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 | be29b99 | 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 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 552 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 553 | struct netlink_callback *cb, |
| 554 | struct cfg80211_registered_device **rdev, |
| 555 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 556 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 557 | int err; |
| 558 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 559 | if (!cb->args[0]) { |
| 560 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 561 | genl_family_attrbuf(&nl80211_fam), |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 562 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 563 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 564 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 565 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 566 | *wdev = __cfg80211_wdev_from_attrs( |
| 567 | sock_net(skb->sk), |
| 568 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 569 | if (IS_ERR(*wdev)) |
| 570 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 571 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 572 | /* 0 is the first index - add 1 to parse only once */ |
| 573 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 574 | cb->args[1] = (*wdev)->identifier; |
| 575 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 576 | /* subtract the 1 again here */ |
| 577 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 578 | struct wireless_dev *tmp; |
| 579 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 580 | if (!wiphy) |
| 581 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 582 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 583 | *wdev = NULL; |
| 584 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 585 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 586 | if (tmp->identifier == cb->args[1]) { |
| 587 | *wdev = tmp; |
| 588 | break; |
| 589 | } |
| 590 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 591 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 592 | if (!*wdev) |
| 593 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 594 | } |
| 595 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 596 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 597 | } |
| 598 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 599 | /* IE validation */ |
| 600 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 601 | { |
| 602 | const u8 *pos; |
| 603 | int len; |
| 604 | |
| 605 | if (!attr) |
| 606 | return true; |
| 607 | |
| 608 | pos = nla_data(attr); |
| 609 | len = nla_len(attr); |
| 610 | |
| 611 | while (len) { |
| 612 | u8 elemlen; |
| 613 | |
| 614 | if (len < 2) |
| 615 | return false; |
| 616 | len -= 2; |
| 617 | |
| 618 | elemlen = pos[1]; |
| 619 | if (elemlen > len) |
| 620 | return false; |
| 621 | |
| 622 | len -= elemlen; |
| 623 | pos += 2 + elemlen; |
| 624 | } |
| 625 | |
| 626 | return true; |
| 627 | } |
| 628 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 629 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 630 | 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] | 631 | int flags, u8 cmd) |
| 632 | { |
| 633 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 634 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 637 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 638 | struct ieee80211_channel *chan, |
| 639 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 640 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 641 | /* Some channels must be completely excluded from the |
| 642 | * list to protect old user-space tools from breaking |
| 643 | */ |
| 644 | if (!large && chan->flags & |
| 645 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 646 | return 0; |
| 647 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 648 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 649 | chan->center_freq)) |
| 650 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 651 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 652 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 653 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 654 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 655 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 656 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 657 | goto nla_put_failure; |
| 658 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 659 | goto nla_put_failure; |
| 660 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 661 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 662 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 663 | goto nla_put_failure; |
| 664 | if (large) { |
| 665 | u32 time; |
| 666 | |
| 667 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 668 | |
| 669 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 670 | chan->dfs_state)) |
| 671 | goto nla_put_failure; |
| 672 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 673 | time)) |
| 674 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 675 | if (nla_put_u32(msg, |
| 676 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 677 | chan->dfs_cac_ms)) |
| 678 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 679 | } |
| 680 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 681 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 682 | if (large) { |
| 683 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 684 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 685 | goto nla_put_failure; |
| 686 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 687 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 688 | goto nla_put_failure; |
| 689 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 690 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 691 | goto nla_put_failure; |
| 692 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 693 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 694 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 695 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 696 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 697 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 698 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 699 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 700 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 701 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 702 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 703 | goto nla_put_failure; |
| 704 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 705 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 706 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 707 | } |
| 708 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 709 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 710 | DBM_TO_MBM(chan->max_power))) |
| 711 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 712 | |
| 713 | return 0; |
| 714 | |
| 715 | nla_put_failure: |
| 716 | return -ENOBUFS; |
| 717 | } |
| 718 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 719 | /* netlink command implementations */ |
| 720 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 721 | struct key_parse { |
| 722 | struct key_params p; |
| 723 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 724 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 725 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 726 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | }; |
| 728 | |
| 729 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 730 | { |
| 731 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 732 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 733 | nl80211_key_policy, NULL); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 734 | if (err) |
| 735 | return err; |
| 736 | |
| 737 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 738 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 739 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 740 | if (k->def) { |
| 741 | k->def_uni = true; |
| 742 | k->def_multi = true; |
| 743 | } |
| 744 | if (k->defmgmt) |
| 745 | k->def_multi = true; |
| 746 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 747 | if (tb[NL80211_KEY_IDX]) |
| 748 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 749 | |
| 750 | if (tb[NL80211_KEY_DATA]) { |
| 751 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 752 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 753 | } |
| 754 | |
| 755 | if (tb[NL80211_KEY_SEQ]) { |
| 756 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 757 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 758 | } |
| 759 | |
| 760 | if (tb[NL80211_KEY_CIPHER]) |
| 761 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 762 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 763 | if (tb[NL80211_KEY_TYPE]) { |
| 764 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 765 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 769 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 770 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 771 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 772 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 773 | tb[NL80211_KEY_DEFAULT_TYPES], |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 774 | nl80211_key_default_policy, NULL); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 775 | if (err) |
| 776 | return err; |
| 777 | |
| 778 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 779 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 780 | } |
| 781 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 786 | { |
| 787 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 788 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 789 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 790 | } |
| 791 | |
| 792 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 793 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 794 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 795 | } |
| 796 | |
| 797 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 798 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 799 | |
| 800 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 801 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 802 | |
| 803 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 804 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 805 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 806 | if (k->def) { |
| 807 | k->def_uni = true; |
| 808 | k->def_multi = true; |
| 809 | } |
| 810 | if (k->defmgmt) |
| 811 | k->def_multi = true; |
| 812 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 813 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 814 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 815 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 819 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 820 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 821 | int err = nla_parse_nested(kdt, |
| 822 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 823 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 824 | nl80211_key_default_policy, |
| 825 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 826 | if (err) |
| 827 | return err; |
| 828 | |
| 829 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 830 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 831 | } |
| 832 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 837 | { |
| 838 | int err; |
| 839 | |
| 840 | memset(k, 0, sizeof(*k)); |
| 841 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 842 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 843 | |
| 844 | if (info->attrs[NL80211_ATTR_KEY]) |
| 845 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 846 | else |
| 847 | err = nl80211_parse_key_old(info, k); |
| 848 | |
| 849 | if (err) |
| 850 | return err; |
| 851 | |
| 852 | if (k->def && k->defmgmt) |
| 853 | return -EINVAL; |
| 854 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 855 | if (k->defmgmt) { |
| 856 | if (k->def_uni || !k->def_multi) |
| 857 | return -EINVAL; |
| 858 | } |
| 859 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 860 | if (k->idx != -1) { |
| 861 | if (k->defmgmt) { |
| 862 | if (k->idx < 4 || k->idx > 5) |
| 863 | return -EINVAL; |
| 864 | } else if (k->def) { |
| 865 | if (k->idx < 0 || k->idx > 3) |
| 866 | return -EINVAL; |
| 867 | } else { |
| 868 | if (k->idx < 0 || k->idx > 5) |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 876 | static struct cfg80211_cached_keys * |
| 877 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 878 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 879 | { |
| 880 | struct key_parse parse; |
| 881 | struct nlattr *key; |
| 882 | struct cfg80211_cached_keys *result; |
| 883 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 884 | bool have_key = false; |
| 885 | |
| 886 | nla_for_each_nested(key, keys, rem) { |
| 887 | have_key = true; |
| 888 | break; |
| 889 | } |
| 890 | |
| 891 | if (!have_key) |
| 892 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 893 | |
| 894 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 895 | if (!result) |
| 896 | return ERR_PTR(-ENOMEM); |
| 897 | |
| 898 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 899 | |
| 900 | nla_for_each_nested(key, keys, rem) { |
| 901 | memset(&parse, 0, sizeof(parse)); |
| 902 | parse.idx = -1; |
| 903 | |
| 904 | err = nl80211_parse_key_new(key, &parse); |
| 905 | if (err) |
| 906 | goto error; |
| 907 | err = -EINVAL; |
| 908 | if (!parse.p.key) |
| 909 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 910 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 911 | goto error; |
| 912 | if (parse.def) { |
| 913 | if (def) |
| 914 | goto error; |
| 915 | def = 1; |
| 916 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 917 | if (!parse.def_uni || !parse.def_multi) |
| 918 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 919 | } else if (parse.defmgmt) |
| 920 | goto error; |
| 921 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 922 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 923 | if (err) |
| 924 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 925 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 926 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 927 | err = -EINVAL; |
| 928 | goto error; |
| 929 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 930 | result->params[parse.idx].cipher = parse.p.cipher; |
| 931 | result->params[parse.idx].key_len = parse.p.key_len; |
| 932 | result->params[parse.idx].key = result->data[parse.idx]; |
| 933 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 934 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 935 | /* must be WEP key if we got here */ |
| 936 | if (no_ht) |
| 937 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 938 | } |
| 939 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 940 | if (result->def < 0) { |
| 941 | err = -EINVAL; |
| 942 | goto error; |
| 943 | } |
| 944 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 945 | return result; |
| 946 | error: |
| 947 | kfree(result); |
| 948 | return ERR_PTR(err); |
| 949 | } |
| 950 | |
| 951 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 952 | { |
| 953 | ASSERT_WDEV_LOCK(wdev); |
| 954 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 955 | switch (wdev->iftype) { |
| 956 | case NL80211_IFTYPE_AP: |
| 957 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 958 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 959 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 960 | break; |
| 961 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 962 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 963 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 964 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 965 | return -ENOLINK; |
| 966 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 967 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 968 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 969 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 970 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 971 | case NL80211_IFTYPE_P2P_DEVICE: |
| 972 | case NL80211_IFTYPE_WDS: |
| 973 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 974 | return -EINVAL; |
| 975 | } |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 980 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 981 | struct nlattr *tb) |
| 982 | { |
| 983 | struct ieee80211_channel *chan; |
| 984 | |
| 985 | if (tb == NULL) |
| 986 | return NULL; |
| 987 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 988 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 989 | return NULL; |
| 990 | return chan; |
| 991 | } |
| 992 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 993 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 994 | { |
| 995 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 996 | int i; |
| 997 | |
| 998 | if (!nl_modes) |
| 999 | goto nla_put_failure; |
| 1000 | |
| 1001 | i = 0; |
| 1002 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1003 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1004 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1005 | ifmodes >>= 1; |
| 1006 | i++; |
| 1007 | } |
| 1008 | |
| 1009 | nla_nest_end(msg, nl_modes); |
| 1010 | return 0; |
| 1011 | |
| 1012 | nla_put_failure: |
| 1013 | return -ENOBUFS; |
| 1014 | } |
| 1015 | |
| 1016 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1017 | struct sk_buff *msg, |
| 1018 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1019 | { |
| 1020 | struct nlattr *nl_combis; |
| 1021 | int i, j; |
| 1022 | |
| 1023 | nl_combis = nla_nest_start(msg, |
| 1024 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1025 | if (!nl_combis) |
| 1026 | goto nla_put_failure; |
| 1027 | |
| 1028 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1029 | const struct ieee80211_iface_combination *c; |
| 1030 | struct nlattr *nl_combi, *nl_limits; |
| 1031 | |
| 1032 | c = &wiphy->iface_combinations[i]; |
| 1033 | |
| 1034 | nl_combi = nla_nest_start(msg, i + 1); |
| 1035 | if (!nl_combi) |
| 1036 | goto nla_put_failure; |
| 1037 | |
| 1038 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1039 | if (!nl_limits) |
| 1040 | goto nla_put_failure; |
| 1041 | |
| 1042 | for (j = 0; j < c->n_limits; j++) { |
| 1043 | struct nlattr *nl_limit; |
| 1044 | |
| 1045 | nl_limit = nla_nest_start(msg, j + 1); |
| 1046 | if (!nl_limit) |
| 1047 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1048 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1049 | c->limits[j].max)) |
| 1050 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1051 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1052 | c->limits[j].types)) |
| 1053 | goto nla_put_failure; |
| 1054 | nla_nest_end(msg, nl_limit); |
| 1055 | } |
| 1056 | |
| 1057 | nla_nest_end(msg, nl_limits); |
| 1058 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1059 | if (c->beacon_int_infra_match && |
| 1060 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1061 | goto nla_put_failure; |
| 1062 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1063 | c->num_different_channels) || |
| 1064 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1065 | c->max_interfaces)) |
| 1066 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1067 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1068 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1069 | c->radar_detect_widths) || |
| 1070 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1071 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1072 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1073 | if (c->beacon_int_min_gcd && |
| 1074 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1075 | c->beacon_int_min_gcd)) |
| 1076 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1077 | |
| 1078 | nla_nest_end(msg, nl_combi); |
| 1079 | } |
| 1080 | |
| 1081 | nla_nest_end(msg, nl_combis); |
| 1082 | |
| 1083 | return 0; |
| 1084 | nla_put_failure: |
| 1085 | return -ENOBUFS; |
| 1086 | } |
| 1087 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1088 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1089 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1090 | struct sk_buff *msg) |
| 1091 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1092 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1093 | struct nlattr *nl_tcp; |
| 1094 | |
| 1095 | if (!tcp) |
| 1096 | return 0; |
| 1097 | |
| 1098 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1099 | if (!nl_tcp) |
| 1100 | return -ENOBUFS; |
| 1101 | |
| 1102 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1103 | tcp->data_payload_max)) |
| 1104 | return -ENOBUFS; |
| 1105 | |
| 1106 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1107 | tcp->data_payload_max)) |
| 1108 | return -ENOBUFS; |
| 1109 | |
| 1110 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1111 | return -ENOBUFS; |
| 1112 | |
| 1113 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1114 | sizeof(*tcp->tok), tcp->tok)) |
| 1115 | return -ENOBUFS; |
| 1116 | |
| 1117 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1118 | tcp->data_interval_max)) |
| 1119 | return -ENOBUFS; |
| 1120 | |
| 1121 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1122 | tcp->wake_payload_max)) |
| 1123 | return -ENOBUFS; |
| 1124 | |
| 1125 | nla_nest_end(msg, nl_tcp); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1129 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1130 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1131 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1132 | { |
| 1133 | struct nlattr *nl_wowlan; |
| 1134 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1135 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1136 | return 0; |
| 1137 | |
| 1138 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1139 | if (!nl_wowlan) |
| 1140 | return -ENOBUFS; |
| 1141 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1142 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1143 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1144 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1145 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1146 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1147 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1148 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1149 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1150 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1151 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1152 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1153 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1154 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1155 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1156 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1157 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1158 | return -ENOBUFS; |
| 1159 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1160 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1161 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1162 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1163 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1164 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1165 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1166 | }; |
| 1167 | |
| 1168 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1169 | sizeof(pat), &pat)) |
| 1170 | return -ENOBUFS; |
| 1171 | } |
| 1172 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1173 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1174 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1175 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1176 | return -ENOBUFS; |
| 1177 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1178 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1179 | return -ENOBUFS; |
| 1180 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1181 | nla_nest_end(msg, nl_wowlan); |
| 1182 | |
| 1183 | return 0; |
| 1184 | } |
| 1185 | #endif |
| 1186 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1187 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1188 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1189 | { |
| 1190 | struct nl80211_coalesce_rule_support rule; |
| 1191 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1192 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1193 | return 0; |
| 1194 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1195 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1196 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1197 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1198 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1199 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1200 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1201 | |
| 1202 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1203 | return -ENOBUFS; |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1208 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1209 | struct ieee80211_supported_band *sband) |
| 1210 | { |
| 1211 | struct nlattr *nl_rates, *nl_rate; |
| 1212 | struct ieee80211_rate *rate; |
| 1213 | int i; |
| 1214 | |
| 1215 | /* add HT info */ |
| 1216 | if (sband->ht_cap.ht_supported && |
| 1217 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1218 | sizeof(sband->ht_cap.mcs), |
| 1219 | &sband->ht_cap.mcs) || |
| 1220 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1221 | sband->ht_cap.cap) || |
| 1222 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1223 | sband->ht_cap.ampdu_factor) || |
| 1224 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1225 | sband->ht_cap.ampdu_density))) |
| 1226 | return -ENOBUFS; |
| 1227 | |
| 1228 | /* add VHT info */ |
| 1229 | if (sband->vht_cap.vht_supported && |
| 1230 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1231 | sizeof(sband->vht_cap.vht_mcs), |
| 1232 | &sband->vht_cap.vht_mcs) || |
| 1233 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1234 | sband->vht_cap.cap))) |
| 1235 | return -ENOBUFS; |
| 1236 | |
| 1237 | /* add bitrates */ |
| 1238 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1239 | if (!nl_rates) |
| 1240 | return -ENOBUFS; |
| 1241 | |
| 1242 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1243 | nl_rate = nla_nest_start(msg, i); |
| 1244 | if (!nl_rate) |
| 1245 | return -ENOBUFS; |
| 1246 | |
| 1247 | rate = &sband->bitrates[i]; |
| 1248 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1249 | rate->bitrate)) |
| 1250 | return -ENOBUFS; |
| 1251 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1252 | nla_put_flag(msg, |
| 1253 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1254 | return -ENOBUFS; |
| 1255 | |
| 1256 | nla_nest_end(msg, nl_rate); |
| 1257 | } |
| 1258 | |
| 1259 | nla_nest_end(msg, nl_rates); |
| 1260 | |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | static int |
| 1265 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1266 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1267 | { |
| 1268 | u16 stypes; |
| 1269 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1270 | enum nl80211_iftype ift; |
| 1271 | int i; |
| 1272 | |
| 1273 | if (!mgmt_stypes) |
| 1274 | return 0; |
| 1275 | |
| 1276 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1277 | if (!nl_ifs) |
| 1278 | return -ENOBUFS; |
| 1279 | |
| 1280 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1281 | nl_ftypes = nla_nest_start(msg, ift); |
| 1282 | if (!nl_ftypes) |
| 1283 | return -ENOBUFS; |
| 1284 | i = 0; |
| 1285 | stypes = mgmt_stypes[ift].tx; |
| 1286 | while (stypes) { |
| 1287 | if ((stypes & 1) && |
| 1288 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1289 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1290 | return -ENOBUFS; |
| 1291 | stypes >>= 1; |
| 1292 | i++; |
| 1293 | } |
| 1294 | nla_nest_end(msg, nl_ftypes); |
| 1295 | } |
| 1296 | |
| 1297 | nla_nest_end(msg, nl_ifs); |
| 1298 | |
| 1299 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1300 | if (!nl_ifs) |
| 1301 | return -ENOBUFS; |
| 1302 | |
| 1303 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1304 | nl_ftypes = nla_nest_start(msg, ift); |
| 1305 | if (!nl_ftypes) |
| 1306 | return -ENOBUFS; |
| 1307 | i = 0; |
| 1308 | stypes = mgmt_stypes[ift].rx; |
| 1309 | while (stypes) { |
| 1310 | if ((stypes & 1) && |
| 1311 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1312 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1313 | return -ENOBUFS; |
| 1314 | stypes >>= 1; |
| 1315 | i++; |
| 1316 | } |
| 1317 | nla_nest_end(msg, nl_ftypes); |
| 1318 | } |
| 1319 | nla_nest_end(msg, nl_ifs); |
| 1320 | |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1324 | #define CMD(op, n) \ |
| 1325 | do { \ |
| 1326 | if (rdev->ops->op) { \ |
| 1327 | i++; \ |
| 1328 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1329 | goto nla_put_failure; \ |
| 1330 | } \ |
| 1331 | } while (0) |
| 1332 | |
| 1333 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1334 | struct sk_buff *msg) |
| 1335 | { |
| 1336 | int i = 0; |
| 1337 | |
| 1338 | /* |
| 1339 | * do *NOT* add anything into this function, new things need to be |
| 1340 | * advertised only to new versions of userspace that can deal with |
| 1341 | * the split (and they can't possibly care about new features... |
| 1342 | */ |
| 1343 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1344 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1345 | CMD(add_key, NEW_KEY); |
| 1346 | CMD(start_ap, START_AP); |
| 1347 | CMD(add_station, NEW_STATION); |
| 1348 | CMD(add_mpath, NEW_MPATH); |
| 1349 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1350 | CMD(change_bss, SET_BSS); |
| 1351 | CMD(auth, AUTHENTICATE); |
| 1352 | CMD(assoc, ASSOCIATE); |
| 1353 | CMD(deauth, DEAUTHENTICATE); |
| 1354 | CMD(disassoc, DISASSOCIATE); |
| 1355 | CMD(join_ibss, JOIN_IBSS); |
| 1356 | CMD(join_mesh, JOIN_MESH); |
| 1357 | CMD(set_pmksa, SET_PMKSA); |
| 1358 | CMD(del_pmksa, DEL_PMKSA); |
| 1359 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1360 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1361 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1362 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1363 | CMD(mgmt_tx, FRAME); |
| 1364 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1365 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1366 | i++; |
| 1367 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1368 | goto nla_put_failure; |
| 1369 | } |
| 1370 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1371 | rdev->ops->join_mesh) { |
| 1372 | i++; |
| 1373 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1374 | goto nla_put_failure; |
| 1375 | } |
| 1376 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1377 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1378 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1379 | CMD(tdls_oper, TDLS_OPER); |
| 1380 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1381 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1382 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1383 | CMD(probe_client, PROBE_CLIENT); |
| 1384 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1385 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1386 | i++; |
| 1387 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1388 | goto nla_put_failure; |
| 1389 | } |
| 1390 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1391 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1392 | #ifdef CONFIG_NL80211_TESTMODE |
| 1393 | CMD(testmode_cmd, TESTMODE); |
| 1394 | #endif |
| 1395 | |
| 1396 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1397 | i++; |
| 1398 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1399 | goto nla_put_failure; |
| 1400 | } |
| 1401 | |
| 1402 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1403 | i++; |
| 1404 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1405 | goto nla_put_failure; |
| 1406 | } |
| 1407 | |
| 1408 | return i; |
| 1409 | nla_put_failure: |
| 1410 | return -ENOBUFS; |
| 1411 | } |
| 1412 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1413 | struct nl80211_dump_wiphy_state { |
| 1414 | s64 filter_wiphy; |
| 1415 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1416 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | bool split; |
| 1418 | }; |
| 1419 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1420 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1421 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1422 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1423 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1424 | { |
| 1425 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1426 | struct nlattr *nl_bands, *nl_band; |
| 1427 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1428 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1429 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1431 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1432 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1433 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1434 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1435 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1436 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1437 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | return -ENOBUFS; |
| 1439 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1440 | if (WARN_ON(!state)) |
| 1441 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1442 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1443 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1445 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1446 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1448 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1449 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1450 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1451 | goto finish; |
| 1452 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1453 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | case 0: |
| 1455 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1456 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1458 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1459 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1460 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1461 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1462 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1464 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1465 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1466 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1467 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1468 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1470 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1471 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1472 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1474 | rdev->wiphy.max_match_sets) || |
| 1475 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1476 | rdev->wiphy.max_sched_scan_plans) || |
| 1477 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1478 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1479 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1480 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1481 | goto nla_put_failure; |
| 1482 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1483 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1485 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1488 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1489 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1490 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1491 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1492 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1494 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1495 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1497 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1498 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1500 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1501 | state->split_start++; |
| 1502 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | break; |
| 1504 | case 1: |
| 1505 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1506 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1507 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1508 | goto nla_put_failure; |
| 1509 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1511 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1512 | goto nla_put_failure; |
| 1513 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1514 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1515 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1516 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1517 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1519 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1520 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1521 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1522 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1523 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1526 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1527 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1528 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | if ((rdev->wiphy.available_antennas_tx || |
| 1530 | rdev->wiphy.available_antennas_rx) && |
| 1531 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1532 | u32 tx_ant = 0, rx_ant = 0; |
| 1533 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1534 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1535 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | if (!res) { |
| 1537 | if (nla_put_u32(msg, |
| 1538 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1539 | tx_ant) || |
| 1540 | nla_put_u32(msg, |
| 1541 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1542 | rx_ant)) |
| 1543 | goto nla_put_failure; |
| 1544 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1545 | } |
| 1546 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1547 | state->split_start++; |
| 1548 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | break; |
| 1550 | case 2: |
| 1551 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1552 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1553 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1554 | state->split_start++; |
| 1555 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1556 | break; |
| 1557 | case 3: |
| 1558 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1559 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1560 | goto nla_put_failure; |
| 1561 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1562 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1563 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | struct ieee80211_supported_band *sband; |
| 1565 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1566 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1567 | |
| 1568 | if (!sband) |
| 1569 | continue; |
| 1570 | |
| 1571 | nl_band = nla_nest_start(msg, band); |
| 1572 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1573 | goto nla_put_failure; |
| 1574 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1576 | case 0: |
| 1577 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1578 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1579 | state->chan_start++; |
| 1580 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | break; |
| 1582 | default: |
| 1583 | /* add frequencies */ |
| 1584 | nl_freqs = nla_nest_start( |
| 1585 | msg, NL80211_BAND_ATTR_FREQS); |
| 1586 | if (!nl_freqs) |
| 1587 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1588 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1589 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | i < sband->n_channels; |
| 1591 | i++) { |
| 1592 | nl_freq = nla_nest_start(msg, i); |
| 1593 | if (!nl_freq) |
| 1594 | goto nla_put_failure; |
| 1595 | |
| 1596 | chan = &sband->channels[i]; |
| 1597 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1598 | if (nl80211_msg_put_channel( |
| 1599 | msg, chan, |
| 1600 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1601 | goto nla_put_failure; |
| 1602 | |
| 1603 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1604 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1605 | break; |
| 1606 | } |
| 1607 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1608 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1609 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1610 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1611 | nla_nest_end(msg, nl_freqs); |
| 1612 | } |
| 1613 | |
| 1614 | nla_nest_end(msg, nl_band); |
| 1615 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1616 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1617 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1618 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | band--; |
| 1620 | break; |
| 1621 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1622 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1624 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1625 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1626 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1629 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1631 | if (state->band_start == 0 && state->chan_start == 0) |
| 1632 | state->split_start++; |
| 1633 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1634 | break; |
| 1635 | case 4: |
| 1636 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1637 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1638 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1639 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1640 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1641 | if (i < 0) |
| 1642 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1643 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1644 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1645 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1647 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1648 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1649 | if (rdev->wiphy.features & |
| 1650 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1651 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1652 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1653 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1654 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1655 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1656 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1657 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1658 | state->split_start++; |
| 1659 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1660 | break; |
| 1661 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1662 | if (rdev->ops->remain_on_channel && |
| 1663 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1664 | nla_put_u32(msg, |
| 1665 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1666 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1667 | goto nla_put_failure; |
| 1668 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1669 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1670 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1671 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1672 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1673 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1674 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1675 | state->split_start++; |
| 1676 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1677 | break; |
| 1678 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1679 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1680 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1681 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1682 | state->split_start++; |
| 1683 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1684 | break; |
| 1685 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1686 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1687 | #endif |
| 1688 | case 7: |
| 1689 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1691 | goto nla_put_failure; |
| 1692 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1693 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1694 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1695 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1696 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1697 | state->split_start++; |
| 1698 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1699 | break; |
| 1700 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1701 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1702 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1704 | goto nla_put_failure; |
| 1705 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1706 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1707 | /* |
| 1708 | * We can only add the per-channel limit information if the |
| 1709 | * dump is split, otherwise it makes it too big. Therefore |
| 1710 | * only advertise it in that case. |
| 1711 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1712 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1713 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1714 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1715 | goto nla_put_failure; |
| 1716 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1717 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1718 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1720 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1721 | goto nla_put_failure; |
| 1722 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1723 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1724 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1725 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1726 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1727 | goto nla_put_failure; |
| 1728 | |
| 1729 | /* |
| 1730 | * Any information below this point is only available to |
| 1731 | * applications that can deal with it being split. This |
| 1732 | * helps ensure that newly added capabilities don't break |
| 1733 | * older tools by overrunning their buffers. |
| 1734 | * |
| 1735 | * We still increment split_start so that in the split |
| 1736 | * case we'll continue with more data in the next round, |
| 1737 | * but break unconditionally so unsplit data stops here. |
| 1738 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1739 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1740 | break; |
| 1741 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1742 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1743 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1744 | rdev->wiphy.extended_capabilities_len, |
| 1745 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1746 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1747 | rdev->wiphy.extended_capabilities_len, |
| 1748 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1749 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1750 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1751 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1752 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1753 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1754 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1755 | goto nla_put_failure; |
| 1756 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1757 | state->split_start++; |
| 1758 | break; |
| 1759 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1760 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1761 | goto nla_put_failure; |
| 1762 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1763 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1764 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1765 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1766 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1767 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1768 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1769 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1770 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1771 | goto nla_put_failure; |
| 1772 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1773 | state->split_start++; |
| 1774 | break; |
| 1775 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1776 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1777 | const struct nl80211_vendor_cmd_info *info; |
| 1778 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1779 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1780 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1781 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1782 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1783 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1784 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1785 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1786 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1787 | goto nla_put_failure; |
| 1788 | } |
| 1789 | nla_nest_end(msg, nested); |
| 1790 | } |
| 1791 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1792 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1793 | const struct nl80211_vendor_cmd_info *info; |
| 1794 | struct nlattr *nested; |
| 1795 | |
| 1796 | nested = nla_nest_start(msg, |
| 1797 | NL80211_ATTR_VENDOR_EVENTS); |
| 1798 | if (!nested) |
| 1799 | goto nla_put_failure; |
| 1800 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1801 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1802 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1803 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1804 | goto nla_put_failure; |
| 1805 | } |
| 1806 | nla_nest_end(msg, nested); |
| 1807 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1808 | state->split_start++; |
| 1809 | break; |
| 1810 | case 12: |
| 1811 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1812 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1813 | rdev->wiphy.max_num_csa_counters)) |
| 1814 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1815 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1816 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1817 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1818 | goto nla_put_failure; |
| 1819 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1820 | if (rdev->wiphy.max_sched_scan_reqs && |
| 1821 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 1822 | rdev->wiphy.max_sched_scan_reqs)) |
| 1823 | goto nla_put_failure; |
| 1824 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1825 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1826 | sizeof(rdev->wiphy.ext_features), |
| 1827 | rdev->wiphy.ext_features)) |
| 1828 | goto nla_put_failure; |
| 1829 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1830 | if (rdev->wiphy.bss_select_support) { |
| 1831 | struct nlattr *nested; |
| 1832 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1833 | |
| 1834 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1835 | if (!nested) |
| 1836 | goto nla_put_failure; |
| 1837 | |
| 1838 | i = 0; |
| 1839 | while (bss_select_support) { |
| 1840 | if ((bss_select_support & 1) && |
| 1841 | nla_put_flag(msg, i)) |
| 1842 | goto nla_put_failure; |
| 1843 | i++; |
| 1844 | bss_select_support >>= 1; |
| 1845 | } |
| 1846 | nla_nest_end(msg, nested); |
| 1847 | } |
| 1848 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1849 | state->split_start++; |
| 1850 | break; |
| 1851 | case 13: |
| 1852 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1853 | rdev->wiphy.iftype_ext_capab) { |
| 1854 | struct nlattr *nested_ext_capab, *nested; |
| 1855 | |
| 1856 | nested = nla_nest_start(msg, |
| 1857 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1858 | if (!nested) |
| 1859 | goto nla_put_failure; |
| 1860 | |
| 1861 | for (i = state->capa_start; |
| 1862 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1863 | const struct wiphy_iftype_ext_capab *capab; |
| 1864 | |
| 1865 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1866 | |
| 1867 | nested_ext_capab = nla_nest_start(msg, i); |
| 1868 | if (!nested_ext_capab || |
| 1869 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1870 | capab->iftype) || |
| 1871 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1872 | capab->extended_capabilities_len, |
| 1873 | capab->extended_capabilities) || |
| 1874 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1875 | capab->extended_capabilities_len, |
| 1876 | capab->extended_capabilities_mask)) |
| 1877 | goto nla_put_failure; |
| 1878 | |
| 1879 | nla_nest_end(msg, nested_ext_capab); |
| 1880 | if (state->split) |
| 1881 | break; |
| 1882 | } |
| 1883 | nla_nest_end(msg, nested); |
| 1884 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1885 | state->capa_start = i + 1; |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
| 1889 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 1890 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 1891 | rdev->wiphy.nan_supported_bands)) |
| 1892 | goto nla_put_failure; |
| 1893 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1894 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1895 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1896 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1897 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1898 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1899 | genlmsg_end(msg, hdr); |
| 1900 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1901 | |
| 1902 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1903 | genlmsg_cancel(msg, hdr); |
| 1904 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1905 | } |
| 1906 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1907 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1908 | struct netlink_callback *cb, |
| 1909 | struct nl80211_dump_wiphy_state *state) |
| 1910 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 1911 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 1912 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, |
| 1913 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1914 | /* ignore parse errors for backward compatibility */ |
| 1915 | if (ret) |
| 1916 | return 0; |
| 1917 | |
| 1918 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1919 | if (tb[NL80211_ATTR_WIPHY]) |
| 1920 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1921 | if (tb[NL80211_ATTR_WDEV]) |
| 1922 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1923 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1924 | struct net_device *netdev; |
| 1925 | struct cfg80211_registered_device *rdev; |
| 1926 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1927 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1928 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1929 | if (!netdev) |
| 1930 | return -ENODEV; |
| 1931 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1932 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1933 | netdev->ieee80211_ptr->wiphy); |
| 1934 | state->filter_wiphy = rdev->wiphy_idx; |
| 1935 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1941 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1942 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1943 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1944 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1945 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1946 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1947 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1948 | if (!state) { |
| 1949 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1950 | if (!state) { |
| 1951 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1952 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1953 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1954 | state->filter_wiphy = -1; |
| 1955 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1956 | if (ret) { |
| 1957 | kfree(state); |
| 1958 | rtnl_unlock(); |
| 1959 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1960 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1961 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1962 | } |
| 1963 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1964 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1965 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1966 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1967 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1968 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1969 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1970 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1971 | continue; |
| 1972 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1973 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1974 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1975 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1976 | NETLINK_CB(cb->skb).portid, |
| 1977 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1978 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1979 | if (ret < 0) { |
| 1980 | /* |
| 1981 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1982 | * or EMSGSIZE returned), this SKB is still |
| 1983 | * empty (so it's not too big because another |
| 1984 | * wiphy dataset is already in the skb) and |
| 1985 | * we've not tried to adjust the dump allocation |
| 1986 | * yet ... then adjust the alloc size to be |
| 1987 | * bigger, and return 1 but with the empty skb. |
| 1988 | * This results in an empty message being RX'ed |
| 1989 | * in userspace, but that is ignored. |
| 1990 | * |
| 1991 | * We can then retry with the larger buffer. |
| 1992 | */ |
| 1993 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1994 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1995 | cb->min_dump_alloc < 4096) { |
| 1996 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1997 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1998 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1999 | return 1; |
| 2000 | } |
| 2001 | idx--; |
| 2002 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2003 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2004 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2005 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2006 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2007 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2008 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2009 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2010 | |
| 2011 | return skb->len; |
| 2012 | } |
| 2013 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2014 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2015 | { |
| 2016 | kfree((void *)cb->args[0]); |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2020 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2021 | { |
| 2022 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2024 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2025 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2026 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2027 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2028 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2029 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2030 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2031 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2032 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2033 | nlmsg_free(msg); |
| 2034 | return -ENOBUFS; |
| 2035 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2036 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2037 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2040 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2041 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2042 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2043 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2044 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2045 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2046 | }; |
| 2047 | |
| 2048 | static int parse_txq_params(struct nlattr *tb[], |
| 2049 | struct ieee80211_txq_params *txq_params) |
| 2050 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2051 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2052 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2053 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2054 | return -EINVAL; |
| 2055 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2056 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2057 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2058 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2059 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2060 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2061 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2062 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 2063 | return -EINVAL; |
| 2064 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2065 | return 0; |
| 2066 | } |
| 2067 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2068 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2069 | { |
| 2070 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2071 | * You can only set the channel explicitly for WDS interfaces, |
| 2072 | * all others have their channel managed via their respective |
| 2073 | * "establish a connection" command (connect, join, ...) |
| 2074 | * |
| 2075 | * For AP/GO and mesh mode, the channel can be set with the |
| 2076 | * channel userspace API, but is only stored and passed to the |
| 2077 | * low-level driver when the AP starts or the mesh is joined. |
| 2078 | * This is for backward compatibility, userspace can also give |
| 2079 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2080 | * |
| 2081 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2082 | * whatever else is going on, so they have their own special |
| 2083 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2084 | */ |
| 2085 | return !wdev || |
| 2086 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2087 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2088 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2089 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2090 | } |
| 2091 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2092 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2093 | struct genl_info *info, |
| 2094 | struct cfg80211_chan_def *chandef) |
| 2095 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2096 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2097 | |
| 2098 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2099 | return -EINVAL; |
| 2100 | |
| 2101 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2102 | |
| 2103 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2104 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2105 | chandef->center_freq1 = control_freq; |
| 2106 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2107 | |
| 2108 | /* Primary channel not allowed */ |
| 2109 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2110 | return -EINVAL; |
| 2111 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2112 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2113 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2114 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2115 | chantype = nla_get_u32( |
| 2116 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2117 | |
| 2118 | switch (chantype) { |
| 2119 | case NL80211_CHAN_NO_HT: |
| 2120 | case NL80211_CHAN_HT20: |
| 2121 | case NL80211_CHAN_HT40PLUS: |
| 2122 | case NL80211_CHAN_HT40MINUS: |
| 2123 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2124 | chantype); |
| 2125 | break; |
| 2126 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2127 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2128 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2129 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2130 | chandef->width = |
| 2131 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2132 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2133 | chandef->center_freq1 = |
| 2134 | nla_get_u32( |
| 2135 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2136 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2137 | chandef->center_freq2 = |
| 2138 | nla_get_u32( |
| 2139 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2140 | } |
| 2141 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2142 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2143 | return -EINVAL; |
| 2144 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2145 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2146 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2147 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2148 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2149 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2150 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2151 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2152 | return -EINVAL; |
| 2153 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2154 | return 0; |
| 2155 | } |
| 2156 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2157 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2158 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2159 | struct genl_info *info) |
| 2160 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2161 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2162 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2163 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2164 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2165 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2166 | if (dev) |
| 2167 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2168 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2169 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2170 | if (wdev) |
| 2171 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2172 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2173 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2174 | if (result) |
| 2175 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2176 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2177 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2178 | case NL80211_IFTYPE_AP: |
| 2179 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2180 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2181 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2182 | result = -EINVAL; |
| 2183 | break; |
| 2184 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2185 | if (wdev->beacon_interval) { |
| 2186 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2187 | !(rdev->wiphy.features & |
| 2188 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2189 | result = -EBUSY; |
| 2190 | break; |
| 2191 | } |
| 2192 | |
| 2193 | /* Only allow dynamic channel width changes */ |
| 2194 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2195 | result = -EBUSY; |
| 2196 | break; |
| 2197 | } |
| 2198 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2199 | if (result) |
| 2200 | break; |
| 2201 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2202 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2203 | result = 0; |
| 2204 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2205 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2206 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2207 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2208 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2209 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2210 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2211 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2212 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2213 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2214 | |
| 2215 | return result; |
| 2216 | } |
| 2217 | |
| 2218 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2219 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2221 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2222 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2223 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2224 | } |
| 2225 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2226 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2227 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2229 | struct net_device *dev = info->user_ptr[1]; |
| 2230 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2231 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2232 | |
| 2233 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2234 | return -EINVAL; |
| 2235 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2236 | if (netif_running(dev)) |
| 2237 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2238 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2239 | if (!rdev->ops->set_wds_peer) |
| 2240 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2241 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2242 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2243 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2244 | |
| 2245 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2246 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2247 | } |
| 2248 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2249 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2250 | { |
| 2251 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2252 | struct net_device *netdev = NULL; |
| 2253 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2254 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2255 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2256 | u32 changed; |
| 2257 | u8 retry_short = 0, retry_long = 0; |
| 2258 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2259 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2260 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2261 | ASSERT_RTNL(); |
| 2262 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2263 | /* |
| 2264 | * Try to find the wiphy and netdev. Normally this |
| 2265 | * function shouldn't need the netdev, but this is |
| 2266 | * done for backward compatibility -- previously |
| 2267 | * setting the channel was done per wiphy, but now |
| 2268 | * it is per netdev. Previous userland like hostapd |
| 2269 | * also passed a netdev to set_wiphy, so that it is |
| 2270 | * possible to let that go to the right netdev! |
| 2271 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2272 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2273 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2274 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2275 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2276 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2277 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2278 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2279 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2280 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2281 | } |
| 2282 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2283 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2284 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2285 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2286 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2287 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2288 | wdev = NULL; |
| 2289 | netdev = NULL; |
| 2290 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2291 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2292 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2293 | |
| 2294 | /* |
| 2295 | * end workaround code, by now the rdev is available |
| 2296 | * and locked, and wdev may or may not be NULL. |
| 2297 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2298 | |
| 2299 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2300 | result = cfg80211_dev_rename( |
| 2301 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2302 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2303 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2304 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2305 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2306 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2307 | struct ieee80211_txq_params txq_params; |
| 2308 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2309 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2310 | if (!rdev->ops->set_txq_params) |
| 2311 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2312 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2313 | if (!netdev) |
| 2314 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2315 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2316 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2317 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2318 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2319 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2320 | if (!netif_running(netdev)) |
| 2321 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2322 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2323 | nla_for_each_nested(nl_txq_params, |
| 2324 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2325 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2326 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2327 | nl_txq_params, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 2328 | txq_params_policy, |
| 2329 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2330 | if (result) |
| 2331 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2332 | result = parse_txq_params(tb, &txq_params); |
| 2333 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2334 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2335 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2336 | result = rdev_set_txq_params(rdev, netdev, |
| 2337 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2338 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2339 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2343 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2344 | result = __nl80211_set_channel( |
| 2345 | rdev, |
| 2346 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2347 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2348 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2349 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2350 | } |
| 2351 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2352 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2353 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2354 | enum nl80211_tx_power_setting type; |
| 2355 | int idx, mbm = 0; |
| 2356 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2357 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2358 | txp_wdev = NULL; |
| 2359 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2360 | if (!rdev->ops->set_tx_power) |
| 2361 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2362 | |
| 2363 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2364 | type = nla_get_u32(info->attrs[idx]); |
| 2365 | |
| 2366 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2367 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2368 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2369 | |
| 2370 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2371 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2372 | mbm = nla_get_u32(info->attrs[idx]); |
| 2373 | } |
| 2374 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2375 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2376 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2377 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2378 | } |
| 2379 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2380 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2381 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2382 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2383 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2384 | if ((!rdev->wiphy.available_antennas_tx && |
| 2385 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2386 | !rdev->ops->set_antenna) |
| 2387 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2388 | |
| 2389 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2390 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2391 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2392 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2393 | * available antenna masks, except for the "all" mask */ |
| 2394 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2395 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2396 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2397 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2398 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2399 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2400 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2401 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2402 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2403 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2404 | } |
| 2405 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2406 | changed = 0; |
| 2407 | |
| 2408 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2409 | retry_short = nla_get_u8( |
| 2410 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2411 | if (retry_short == 0) |
| 2412 | return -EINVAL; |
| 2413 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2414 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2415 | } |
| 2416 | |
| 2417 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2418 | retry_long = nla_get_u8( |
| 2419 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2420 | if (retry_long == 0) |
| 2421 | return -EINVAL; |
| 2422 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2423 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2424 | } |
| 2425 | |
| 2426 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2427 | frag_threshold = nla_get_u32( |
| 2428 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2429 | if (frag_threshold < 256) |
| 2430 | return -EINVAL; |
| 2431 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2432 | if (frag_threshold != (u32) -1) { |
| 2433 | /* |
| 2434 | * Fragments (apart from the last one) are required to |
| 2435 | * have even length. Make the fragmentation code |
| 2436 | * simpler by stripping LSB should someone try to use |
| 2437 | * odd threshold value. |
| 2438 | */ |
| 2439 | frag_threshold &= ~0x1; |
| 2440 | } |
| 2441 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2442 | } |
| 2443 | |
| 2444 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2445 | rts_threshold = nla_get_u32( |
| 2446 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2447 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2448 | } |
| 2449 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2450 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2451 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2452 | return -EINVAL; |
| 2453 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2454 | coverage_class = nla_get_u8( |
| 2455 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2456 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2457 | } |
| 2458 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2459 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2460 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2461 | return -EOPNOTSUPP; |
| 2462 | |
| 2463 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2464 | } |
| 2465 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2466 | if (changed) { |
| 2467 | u8 old_retry_short, old_retry_long; |
| 2468 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2469 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2470 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2471 | if (!rdev->ops->set_wiphy_params) |
| 2472 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2473 | |
| 2474 | old_retry_short = rdev->wiphy.retry_short; |
| 2475 | old_retry_long = rdev->wiphy.retry_long; |
| 2476 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2477 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2478 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2479 | |
| 2480 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2481 | rdev->wiphy.retry_short = retry_short; |
| 2482 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2483 | rdev->wiphy.retry_long = retry_long; |
| 2484 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2485 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2486 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2487 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2488 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2489 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2490 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2491 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2492 | if (result) { |
| 2493 | rdev->wiphy.retry_short = old_retry_short; |
| 2494 | rdev->wiphy.retry_long = old_retry_long; |
| 2495 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2496 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2497 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2498 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2499 | } |
| 2500 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2501 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2502 | } |
| 2503 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2504 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2505 | { |
| 2506 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2507 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2508 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2509 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2510 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2511 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2512 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2513 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2514 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2515 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2516 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2517 | chandef->chan->center_freq)) |
| 2518 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2519 | switch (chandef->width) { |
| 2520 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2521 | case NL80211_CHAN_WIDTH_20: |
| 2522 | case NL80211_CHAN_WIDTH_40: |
| 2523 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2524 | cfg80211_get_chandef_type(chandef))) |
| 2525 | return -ENOBUFS; |
| 2526 | break; |
| 2527 | default: |
| 2528 | break; |
| 2529 | } |
| 2530 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2531 | return -ENOBUFS; |
| 2532 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2533 | return -ENOBUFS; |
| 2534 | if (chandef->center_freq2 && |
| 2535 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2536 | return -ENOBUFS; |
| 2537 | return 0; |
| 2538 | } |
| 2539 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2540 | 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] | 2541 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2542 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2543 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2544 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2545 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2546 | void *hdr; |
| 2547 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2548 | if (removal) |
| 2549 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2550 | |
| 2551 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2552 | if (!hdr) |
| 2553 | return -1; |
| 2554 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2555 | if (dev && |
| 2556 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2557 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2558 | goto nla_put_failure; |
| 2559 | |
| 2560 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2561 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2562 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2563 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2565 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2566 | rdev->devlist_generation ^ |
| 2567 | (cfg80211_rdev_list_generation << 2))) |
| 2568 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2569 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2570 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2571 | int ret; |
| 2572 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2573 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2574 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2575 | if (ret == 0) { |
| 2576 | if (nl80211_send_chandef(msg, &chandef)) |
| 2577 | goto nla_put_failure; |
| 2578 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2579 | } |
| 2580 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2581 | if (rdev->ops->get_tx_power) { |
| 2582 | int dbm, ret; |
| 2583 | |
| 2584 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2585 | if (ret == 0 && |
| 2586 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2587 | DBM_TO_MBM(dbm))) |
| 2588 | goto nla_put_failure; |
| 2589 | } |
| 2590 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2591 | if (wdev->ssid_len) { |
| 2592 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2593 | goto nla_put_failure; |
| 2594 | } |
| 2595 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2596 | genlmsg_end(msg, hdr); |
| 2597 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2598 | |
| 2599 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2600 | genlmsg_cancel(msg, hdr); |
| 2601 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2605 | { |
| 2606 | int wp_idx = 0; |
| 2607 | int if_idx = 0; |
| 2608 | int wp_start = cb->args[0]; |
| 2609 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2610 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2611 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2612 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2613 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2614 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2615 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2616 | if (!cb->args[2]) { |
| 2617 | struct nl80211_dump_wiphy_state state = { |
| 2618 | .filter_wiphy = -1, |
| 2619 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2620 | |
| 2621 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2622 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2623 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2624 | |
| 2625 | filter_wiphy = state.filter_wiphy; |
| 2626 | |
| 2627 | /* |
| 2628 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2629 | * value needed to determine that parsing is necessary. |
| 2630 | */ |
| 2631 | if (filter_wiphy >= 0) |
| 2632 | cb->args[2] = filter_wiphy + 1; |
| 2633 | else |
| 2634 | cb->args[2] = -1; |
| 2635 | } else if (cb->args[2] > 0) { |
| 2636 | filter_wiphy = cb->args[2] - 1; |
| 2637 | } |
| 2638 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2639 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2640 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2641 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2642 | if (wp_idx < wp_start) { |
| 2643 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2644 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2645 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2646 | |
| 2647 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2648 | continue; |
| 2649 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2650 | if_idx = 0; |
| 2651 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2652 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2653 | if (if_idx < if_start) { |
| 2654 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2655 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2656 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2657 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2658 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2659 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2660 | goto out; |
| 2661 | } |
| 2662 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2663 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2664 | |
| 2665 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2666 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2667 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2668 | cb->args[0] = wp_idx; |
| 2669 | cb->args[1] = if_idx; |
| 2670 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2671 | ret = skb->len; |
| 2672 | out_unlock: |
| 2673 | rtnl_unlock(); |
| 2674 | |
| 2675 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2679 | { |
| 2680 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2681 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2682 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2683 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2685 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2686 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2687 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2688 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2689 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2690 | nlmsg_free(msg); |
| 2691 | return -ENOBUFS; |
| 2692 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2693 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2694 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2697 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2698 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2699 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2700 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2701 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2702 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2703 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2704 | }; |
| 2705 | |
| 2706 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2707 | { |
| 2708 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2709 | int flag; |
| 2710 | |
| 2711 | *mntrflags = 0; |
| 2712 | |
| 2713 | if (!nla) |
| 2714 | return -EINVAL; |
| 2715 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2716 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
| 2717 | mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2718 | return -EINVAL; |
| 2719 | |
| 2720 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2721 | if (flags[flag]) |
| 2722 | *mntrflags |= (1<<flag); |
| 2723 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2724 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 2725 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2726 | return 0; |
| 2727 | } |
| 2728 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2729 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 2730 | enum nl80211_iftype type, |
| 2731 | struct genl_info *info, |
| 2732 | struct vif_params *params) |
| 2733 | { |
| 2734 | bool change = false; |
| 2735 | int err; |
| 2736 | |
| 2737 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 2738 | if (type != NL80211_IFTYPE_MONITOR) |
| 2739 | return -EINVAL; |
| 2740 | |
| 2741 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2742 | ¶ms->flags); |
| 2743 | if (err) |
| 2744 | return err; |
| 2745 | |
| 2746 | change = true; |
| 2747 | } |
| 2748 | |
| 2749 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 2750 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2751 | return -EOPNOTSUPP; |
| 2752 | |
| 2753 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2754 | const u8 *mumimo_groups; |
| 2755 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2756 | |
| 2757 | if (type != NL80211_IFTYPE_MONITOR) |
| 2758 | return -EINVAL; |
| 2759 | |
| 2760 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2761 | return -EOPNOTSUPP; |
| 2762 | |
| 2763 | mumimo_groups = |
| 2764 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2765 | |
| 2766 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 2767 | if ((mumimo_groups[0] & BIT(0)) || |
| 2768 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2769 | return -EINVAL; |
| 2770 | |
| 2771 | params->vht_mumimo_groups = mumimo_groups; |
| 2772 | change = true; |
| 2773 | } |
| 2774 | |
| 2775 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2776 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2777 | |
| 2778 | if (type != NL80211_IFTYPE_MONITOR) |
| 2779 | return -EINVAL; |
| 2780 | |
| 2781 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2782 | return -EOPNOTSUPP; |
| 2783 | |
| 2784 | params->vht_mumimo_follow_addr = |
| 2785 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 2786 | change = true; |
| 2787 | } |
| 2788 | |
| 2789 | return change ? 1 : 0; |
| 2790 | } |
| 2791 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2792 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2793 | struct net_device *netdev, u8 use_4addr, |
| 2794 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2795 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2796 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2797 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2798 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2799 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2800 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2801 | |
| 2802 | switch (iftype) { |
| 2803 | case NL80211_IFTYPE_AP_VLAN: |
| 2804 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2805 | return 0; |
| 2806 | break; |
| 2807 | case NL80211_IFTYPE_STATION: |
| 2808 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2809 | return 0; |
| 2810 | break; |
| 2811 | default: |
| 2812 | break; |
| 2813 | } |
| 2814 | |
| 2815 | return -EOPNOTSUPP; |
| 2816 | } |
| 2817 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2818 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2819 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2821 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2822 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2823 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2824 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2825 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2826 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2827 | memset(¶ms, 0, sizeof(params)); |
| 2828 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2829 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2830 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2831 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2832 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2833 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2834 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2835 | if (ntype > NL80211_IFTYPE_MAX) |
| 2836 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2837 | } |
| 2838 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2839 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2840 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2842 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2843 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2844 | if (netif_running(dev)) |
| 2845 | return -EBUSY; |
| 2846 | |
| 2847 | wdev_lock(wdev); |
| 2848 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2849 | IEEE80211_MAX_MESH_ID_LEN); |
| 2850 | wdev->mesh_id_up_len = |
| 2851 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2852 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2853 | wdev->mesh_id_up_len); |
| 2854 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2857 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2858 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2859 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2860 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2861 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2863 | } else { |
| 2864 | params.use_4addr = -1; |
| 2865 | } |
| 2866 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2867 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 2868 | if (err < 0) |
| 2869 | return err; |
| 2870 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2871 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2872 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2873 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2874 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2875 | else |
| 2876 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2877 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2878 | if (!err && params.use_4addr != -1) |
| 2879 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2880 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2881 | return err; |
| 2882 | } |
| 2883 | |
| 2884 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2885 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2887 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2888 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2889 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2890 | int err; |
| 2891 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 2892 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2893 | /* to avoid failing a new interface creation due to pending removal */ |
| 2894 | cfg80211_destroy_ifaces(rdev); |
| 2895 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2896 | memset(¶ms, 0, sizeof(params)); |
| 2897 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2898 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2899 | return -EINVAL; |
| 2900 | |
| 2901 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2902 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2903 | if (type > NL80211_IFTYPE_MAX) |
| 2904 | return -EINVAL; |
| 2905 | } |
| 2906 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2907 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2908 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2909 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2910 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2911 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2912 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2913 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2914 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2915 | ETH_ALEN); |
| 2916 | if (!is_valid_ether_addr(params.macaddr)) |
| 2917 | return -EADDRNOTAVAIL; |
| 2918 | } |
| 2919 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2920 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2921 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2922 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2923 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2924 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2925 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2926 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2927 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 2928 | if (err < 0) |
| 2929 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2930 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2932 | if (!msg) |
| 2933 | return -ENOMEM; |
| 2934 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2935 | wdev = rdev_add_virtual_intf(rdev, |
| 2936 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2937 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2938 | if (WARN_ON(!wdev)) { |
| 2939 | nlmsg_free(msg); |
| 2940 | return -EPROTO; |
| 2941 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2942 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2943 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2944 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2945 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2946 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2947 | wdev->owner_nlportid = info->snd_portid; |
| 2948 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2949 | switch (type) { |
| 2950 | case NL80211_IFTYPE_MESH_POINT: |
| 2951 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2952 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2953 | wdev_lock(wdev); |
| 2954 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2955 | IEEE80211_MAX_MESH_ID_LEN); |
| 2956 | wdev->mesh_id_up_len = |
| 2957 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2958 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2959 | wdev->mesh_id_up_len); |
| 2960 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2961 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2962 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2963 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2964 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2965 | * 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] | 2966 | * through the netdev notifier and must be added here |
| 2967 | */ |
| 2968 | mutex_init(&wdev->mtx); |
| 2969 | INIT_LIST_HEAD(&wdev->event_list); |
| 2970 | spin_lock_init(&wdev->event_lock); |
| 2971 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2972 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2973 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2974 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2975 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2976 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2977 | break; |
| 2978 | default: |
| 2979 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2980 | } |
| 2981 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2982 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2983 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2984 | nlmsg_free(msg); |
| 2985 | return -ENOBUFS; |
| 2986 | } |
| 2987 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2988 | /* |
| 2989 | * For wdevs which have no associated netdev object (e.g. of type |
| 2990 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2991 | * For all other types, the event will be generated from the |
| 2992 | * netdev notifier |
| 2993 | */ |
| 2994 | if (!wdev->netdev) |
| 2995 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2996 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2997 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3003 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3005 | if (!rdev->ops->del_virtual_intf) |
| 3006 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3007 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3008 | /* |
| 3009 | * If we remove a wireless device without a netdev then clear |
| 3010 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3011 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3012 | * since the wdev has been freed, unlike with a netdev where |
| 3013 | * we need the dev_put() for the netdev to really be freed. |
| 3014 | */ |
| 3015 | if (!wdev->netdev) |
| 3016 | info->user_ptr[1] = NULL; |
| 3017 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3018 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3019 | } |
| 3020 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3021 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3022 | { |
| 3023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3024 | struct net_device *dev = info->user_ptr[1]; |
| 3025 | u16 noack_map; |
| 3026 | |
| 3027 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3028 | return -EINVAL; |
| 3029 | |
| 3030 | if (!rdev->ops->set_noack_map) |
| 3031 | return -EOPNOTSUPP; |
| 3032 | |
| 3033 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3034 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3035 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 | struct get_key_cookie { |
| 3039 | struct sk_buff *msg; |
| 3040 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3041 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3042 | }; |
| 3043 | |
| 3044 | static void get_key_callback(void *c, struct key_params *params) |
| 3045 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3046 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3047 | struct get_key_cookie *cookie = c; |
| 3048 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3049 | if ((params->key && |
| 3050 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3051 | params->key_len, params->key)) || |
| 3052 | (params->seq && |
| 3053 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3054 | params->seq_len, params->seq)) || |
| 3055 | (params->cipher && |
| 3056 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3057 | params->cipher))) |
| 3058 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3059 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3060 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3061 | if (!key) |
| 3062 | goto nla_put_failure; |
| 3063 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3064 | if ((params->key && |
| 3065 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3066 | params->key_len, params->key)) || |
| 3067 | (params->seq && |
| 3068 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3069 | params->seq_len, params->seq)) || |
| 3070 | (params->cipher && |
| 3071 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3072 | params->cipher))) |
| 3073 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3075 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3076 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3077 | |
| 3078 | nla_nest_end(cookie->msg, key); |
| 3079 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3080 | return; |
| 3081 | nla_put_failure: |
| 3082 | cookie->error = 1; |
| 3083 | } |
| 3084 | |
| 3085 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3086 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3088 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3089 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3090 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3091 | const u8 *mac_addr = NULL; |
| 3092 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3093 | struct get_key_cookie cookie = { |
| 3094 | .error = 0, |
| 3095 | }; |
| 3096 | void *hdr; |
| 3097 | struct sk_buff *msg; |
| 3098 | |
| 3099 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3100 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3101 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3102 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3103 | return -EINVAL; |
| 3104 | |
| 3105 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3106 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3107 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3108 | pairwise = !!mac_addr; |
| 3109 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3110 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3111 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3112 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3113 | return -EINVAL; |
| 3114 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3115 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3116 | return -EINVAL; |
| 3117 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3118 | } |
| 3119 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3120 | if (!rdev->ops->get_key) |
| 3121 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3122 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3123 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3124 | return -ENOENT; |
| 3125 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3126 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3127 | if (!msg) |
| 3128 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3129 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3130 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3131 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3132 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3133 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3134 | |
| 3135 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3136 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3137 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3138 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3139 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3140 | goto nla_put_failure; |
| 3141 | if (mac_addr && |
| 3142 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3143 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3144 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3145 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3146 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3147 | |
| 3148 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3149 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3150 | |
| 3151 | if (cookie.error) |
| 3152 | goto nla_put_failure; |
| 3153 | |
| 3154 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3155 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3156 | |
| 3157 | nla_put_failure: |
| 3158 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3159 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3160 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3161 | return err; |
| 3162 | } |
| 3163 | |
| 3164 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3167 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3168 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3169 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3170 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3171 | err = nl80211_parse_key(info, &key); |
| 3172 | if (err) |
| 3173 | return err; |
| 3174 | |
| 3175 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3176 | return -EINVAL; |
| 3177 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3178 | /* only support setting default key */ |
| 3179 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3180 | return -EINVAL; |
| 3181 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3182 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3183 | |
| 3184 | if (key.def) { |
| 3185 | if (!rdev->ops->set_default_key) { |
| 3186 | err = -EOPNOTSUPP; |
| 3187 | goto out; |
| 3188 | } |
| 3189 | |
| 3190 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3191 | if (err) |
| 3192 | goto out; |
| 3193 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3194 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3195 | key.def_uni, key.def_multi); |
| 3196 | |
| 3197 | if (err) |
| 3198 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3199 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3200 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3201 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3202 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3203 | } else { |
| 3204 | if (key.def_uni || !key.def_multi) { |
| 3205 | err = -EINVAL; |
| 3206 | goto out; |
| 3207 | } |
| 3208 | |
| 3209 | if (!rdev->ops->set_default_mgmt_key) { |
| 3210 | err = -EOPNOTSUPP; |
| 3211 | goto out; |
| 3212 | } |
| 3213 | |
| 3214 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3215 | if (err) |
| 3216 | goto out; |
| 3217 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3218 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3219 | if (err) |
| 3220 | goto out; |
| 3221 | |
| 3222 | #ifdef CONFIG_CFG80211_WEXT |
| 3223 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3224 | #endif |
| 3225 | } |
| 3226 | |
| 3227 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3228 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3229 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3230 | return err; |
| 3231 | } |
| 3232 | |
| 3233 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3234 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3236 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3237 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3238 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3239 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3241 | err = nl80211_parse_key(info, &key); |
| 3242 | if (err) |
| 3243 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3244 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3245 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3246 | return -EINVAL; |
| 3247 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3248 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3249 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3250 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3251 | if (key.type == -1) { |
| 3252 | if (mac_addr) |
| 3253 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3254 | else |
| 3255 | key.type = NL80211_KEYTYPE_GROUP; |
| 3256 | } |
| 3257 | |
| 3258 | /* for now */ |
| 3259 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3260 | key.type != NL80211_KEYTYPE_GROUP) |
| 3261 | return -EINVAL; |
| 3262 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3263 | if (!rdev->ops->add_key) |
| 3264 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3265 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3266 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3267 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3268 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3269 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3270 | |
| 3271 | wdev_lock(dev->ieee80211_ptr); |
| 3272 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3273 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3274 | err = rdev_add_key(rdev, dev, key.idx, |
| 3275 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3276 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3277 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3278 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3279 | return err; |
| 3280 | } |
| 3281 | |
| 3282 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3283 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3285 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3286 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3287 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3288 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3289 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3290 | err = nl80211_parse_key(info, &key); |
| 3291 | if (err) |
| 3292 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3293 | |
| 3294 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3295 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3296 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3297 | if (key.type == -1) { |
| 3298 | if (mac_addr) |
| 3299 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3300 | else |
| 3301 | key.type = NL80211_KEYTYPE_GROUP; |
| 3302 | } |
| 3303 | |
| 3304 | /* for now */ |
| 3305 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3306 | key.type != NL80211_KEYTYPE_GROUP) |
| 3307 | return -EINVAL; |
| 3308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3309 | if (!rdev->ops->del_key) |
| 3310 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3311 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3312 | wdev_lock(dev->ieee80211_ptr); |
| 3313 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3314 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3315 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3316 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3317 | err = -ENOENT; |
| 3318 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3319 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3320 | err = rdev_del_key(rdev, dev, key.idx, |
| 3321 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3322 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3323 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3324 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3325 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3326 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3327 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3328 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3329 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3330 | } |
| 3331 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3332 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3333 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3334 | return err; |
| 3335 | } |
| 3336 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3337 | /* This function returns an error or the number of nested attributes */ |
| 3338 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3339 | { |
| 3340 | struct nlattr *attr; |
| 3341 | int n_entries = 0, tmp; |
| 3342 | |
| 3343 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3344 | if (nla_len(attr) != ETH_ALEN) |
| 3345 | return -EINVAL; |
| 3346 | |
| 3347 | n_entries++; |
| 3348 | } |
| 3349 | |
| 3350 | return n_entries; |
| 3351 | } |
| 3352 | |
| 3353 | /* |
| 3354 | * This function parses ACL information and allocates memory for ACL data. |
| 3355 | * On successful return, the calling function is responsible to free the |
| 3356 | * ACL buffer returned by this function. |
| 3357 | */ |
| 3358 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3359 | struct genl_info *info) |
| 3360 | { |
| 3361 | enum nl80211_acl_policy acl_policy; |
| 3362 | struct nlattr *attr; |
| 3363 | struct cfg80211_acl_data *acl; |
| 3364 | int i = 0, n_entries, tmp; |
| 3365 | |
| 3366 | if (!wiphy->max_acl_mac_addrs) |
| 3367 | return ERR_PTR(-EOPNOTSUPP); |
| 3368 | |
| 3369 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3370 | return ERR_PTR(-EINVAL); |
| 3371 | |
| 3372 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3373 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3374 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3375 | return ERR_PTR(-EINVAL); |
| 3376 | |
| 3377 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3378 | return ERR_PTR(-EINVAL); |
| 3379 | |
| 3380 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3381 | if (n_entries < 0) |
| 3382 | return ERR_PTR(n_entries); |
| 3383 | |
| 3384 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3385 | return ERR_PTR(-ENOTSUPP); |
| 3386 | |
| 3387 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3388 | GFP_KERNEL); |
| 3389 | if (!acl) |
| 3390 | return ERR_PTR(-ENOMEM); |
| 3391 | |
| 3392 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3393 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3394 | i++; |
| 3395 | } |
| 3396 | |
| 3397 | acl->n_acl_entries = n_entries; |
| 3398 | acl->acl_policy = acl_policy; |
| 3399 | |
| 3400 | return acl; |
| 3401 | } |
| 3402 | |
| 3403 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3404 | { |
| 3405 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3406 | struct net_device *dev = info->user_ptr[1]; |
| 3407 | struct cfg80211_acl_data *acl; |
| 3408 | int err; |
| 3409 | |
| 3410 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3411 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3412 | return -EOPNOTSUPP; |
| 3413 | |
| 3414 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3415 | return -EINVAL; |
| 3416 | |
| 3417 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3418 | if (IS_ERR(acl)) |
| 3419 | return PTR_ERR(acl); |
| 3420 | |
| 3421 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3422 | |
| 3423 | kfree(acl); |
| 3424 | |
| 3425 | return err; |
| 3426 | } |
| 3427 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3428 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3429 | u8 *rates, u8 rates_len) |
| 3430 | { |
| 3431 | u8 i; |
| 3432 | u32 mask = 0; |
| 3433 | |
| 3434 | for (i = 0; i < rates_len; i++) { |
| 3435 | int rate = (rates[i] & 0x7f) * 5; |
| 3436 | int ridx; |
| 3437 | |
| 3438 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3439 | struct ieee80211_rate *srate = |
| 3440 | &sband->bitrates[ridx]; |
| 3441 | if (rate == srate->bitrate) { |
| 3442 | mask |= 1 << ridx; |
| 3443 | break; |
| 3444 | } |
| 3445 | } |
| 3446 | if (ridx == sband->n_bitrates) |
| 3447 | return 0; /* rate not found */ |
| 3448 | } |
| 3449 | |
| 3450 | return mask; |
| 3451 | } |
| 3452 | |
| 3453 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3454 | u8 *rates, u8 rates_len, |
| 3455 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3456 | { |
| 3457 | u8 i; |
| 3458 | |
| 3459 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3460 | |
| 3461 | for (i = 0; i < rates_len; i++) { |
| 3462 | int ridx, rbit; |
| 3463 | |
| 3464 | ridx = rates[i] / 8; |
| 3465 | rbit = BIT(rates[i] % 8); |
| 3466 | |
| 3467 | /* check validity */ |
| 3468 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3469 | return false; |
| 3470 | |
| 3471 | /* check availability */ |
| 3472 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3473 | mcs[ridx] |= rbit; |
| 3474 | else |
| 3475 | return false; |
| 3476 | } |
| 3477 | |
| 3478 | return true; |
| 3479 | } |
| 3480 | |
| 3481 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3482 | { |
| 3483 | u16 mcs_mask = 0; |
| 3484 | |
| 3485 | switch (vht_mcs_map) { |
| 3486 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3487 | break; |
| 3488 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3489 | mcs_mask = 0x00FF; |
| 3490 | break; |
| 3491 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3492 | mcs_mask = 0x01FF; |
| 3493 | break; |
| 3494 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3495 | mcs_mask = 0x03FF; |
| 3496 | break; |
| 3497 | default: |
| 3498 | break; |
| 3499 | } |
| 3500 | |
| 3501 | return mcs_mask; |
| 3502 | } |
| 3503 | |
| 3504 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3505 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3506 | { |
| 3507 | u8 nss; |
| 3508 | |
| 3509 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3510 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3511 | vht_mcs_map >>= 2; |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3516 | struct nl80211_txrate_vht *txrate, |
| 3517 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3518 | { |
| 3519 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3520 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3521 | u8 i; |
| 3522 | |
| 3523 | if (!sband->vht_cap.vht_supported) |
| 3524 | return false; |
| 3525 | |
| 3526 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3527 | |
| 3528 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3529 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3530 | |
| 3531 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3532 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3533 | mcs[i] = txrate->mcs[i]; |
| 3534 | else |
| 3535 | return false; |
| 3536 | } |
| 3537 | |
| 3538 | return true; |
| 3539 | } |
| 3540 | |
| 3541 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3542 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3543 | .len = NL80211_MAX_SUPP_RATES }, |
| 3544 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3545 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3546 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3547 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3548 | }; |
| 3549 | |
| 3550 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3551 | struct cfg80211_bitrate_mask *mask) |
| 3552 | { |
| 3553 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3555 | int rem, i; |
| 3556 | struct nlattr *tx_rates; |
| 3557 | struct ieee80211_supported_band *sband; |
| 3558 | u16 vht_tx_mcs_map; |
| 3559 | |
| 3560 | memset(mask, 0, sizeof(*mask)); |
| 3561 | /* Default to all rates enabled */ |
| 3562 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3563 | sband = rdev->wiphy.bands[i]; |
| 3564 | |
| 3565 | if (!sband) |
| 3566 | continue; |
| 3567 | |
| 3568 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3569 | memcpy(mask->control[i].ht_mcs, |
| 3570 | sband->ht_cap.mcs.rx_mask, |
| 3571 | sizeof(mask->control[i].ht_mcs)); |
| 3572 | |
| 3573 | if (!sband->vht_cap.vht_supported) |
| 3574 | continue; |
| 3575 | |
| 3576 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3577 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3578 | } |
| 3579 | |
| 3580 | /* if no rates are given set it back to the defaults */ |
| 3581 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3582 | goto out; |
| 3583 | |
| 3584 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3585 | * directly to the enum nl80211_band values used in cfg80211. |
| 3586 | */ |
| 3587 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3588 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3589 | enum nl80211_band band = nla_type(tx_rates); |
| 3590 | int err; |
| 3591 | |
| 3592 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3593 | return -EINVAL; |
| 3594 | sband = rdev->wiphy.bands[band]; |
| 3595 | if (sband == NULL) |
| 3596 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3597 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 3598 | nl80211_txattr_policy, info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3599 | if (err) |
| 3600 | return err; |
| 3601 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3602 | mask->control[band].legacy = rateset_to_mask( |
| 3603 | sband, |
| 3604 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3605 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3606 | if ((mask->control[band].legacy == 0) && |
| 3607 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3608 | return -EINVAL; |
| 3609 | } |
| 3610 | if (tb[NL80211_TXRATE_HT]) { |
| 3611 | if (!ht_rateset_to_mask( |
| 3612 | sband, |
| 3613 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3614 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3615 | mask->control[band].ht_mcs)) |
| 3616 | return -EINVAL; |
| 3617 | } |
| 3618 | if (tb[NL80211_TXRATE_VHT]) { |
| 3619 | if (!vht_set_mcs_mask( |
| 3620 | sband, |
| 3621 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3622 | mask->control[band].vht_mcs)) |
| 3623 | return -EINVAL; |
| 3624 | } |
| 3625 | if (tb[NL80211_TXRATE_GI]) { |
| 3626 | mask->control[band].gi = |
| 3627 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3628 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3629 | return -EINVAL; |
| 3630 | } |
| 3631 | |
| 3632 | if (mask->control[band].legacy == 0) { |
| 3633 | /* don't allow empty legacy rates if HT or VHT |
| 3634 | * are not even supported. |
| 3635 | */ |
| 3636 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3637 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3638 | return -EINVAL; |
| 3639 | |
| 3640 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3641 | if (mask->control[band].ht_mcs[i]) |
| 3642 | goto out; |
| 3643 | |
| 3644 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3645 | if (mask->control[band].vht_mcs[i]) |
| 3646 | goto out; |
| 3647 | |
| 3648 | /* legacy and mcs rates may not be both empty */ |
| 3649 | return -EINVAL; |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | out: |
| 3654 | return 0; |
| 3655 | } |
| 3656 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3657 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3658 | enum nl80211_band band, |
| 3659 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3660 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3661 | u32 count_ht, count_vht, i; |
| 3662 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3663 | |
| 3664 | /* Allow only one rate */ |
| 3665 | if (hweight32(rate) > 1) |
| 3666 | return -EINVAL; |
| 3667 | |
| 3668 | count_ht = 0; |
| 3669 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3670 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3671 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3672 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3673 | count_ht++; |
| 3674 | if (count_ht > 1) |
| 3675 | return -EINVAL; |
| 3676 | } |
| 3677 | if (count_ht && rate) |
| 3678 | return -EINVAL; |
| 3679 | } |
| 3680 | |
| 3681 | count_vht = 0; |
| 3682 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3683 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3684 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3685 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3686 | count_vht++; |
| 3687 | if (count_vht > 1) |
| 3688 | return -EINVAL; |
| 3689 | } |
| 3690 | if (count_vht && rate) |
| 3691 | return -EINVAL; |
| 3692 | } |
| 3693 | |
| 3694 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3695 | return -EINVAL; |
| 3696 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3697 | if (rate && |
| 3698 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3699 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3700 | return -EINVAL; |
| 3701 | if (count_ht && |
| 3702 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3703 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3704 | return -EINVAL; |
| 3705 | if (count_vht && |
| 3706 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3707 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3708 | return -EINVAL; |
| 3709 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3710 | return 0; |
| 3711 | } |
| 3712 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3713 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3714 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3715 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3716 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3717 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3718 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3719 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3720 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3721 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3722 | return -EINVAL; |
| 3723 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3724 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3725 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3726 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3727 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3728 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3729 | if (!bcn->head_len) |
| 3730 | return -EINVAL; |
| 3731 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3732 | } |
| 3733 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3734 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3735 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3736 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3737 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3738 | } |
| 3739 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3740 | if (!haveinfo) |
| 3741 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3742 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3743 | if (attrs[NL80211_ATTR_IE]) { |
| 3744 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3745 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3746 | } |
| 3747 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3748 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3749 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3750 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3751 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3752 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3753 | } |
| 3754 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3755 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3756 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3757 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3758 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3759 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3760 | } |
| 3761 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3762 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3763 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3764 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3765 | } |
| 3766 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3767 | return 0; |
| 3768 | } |
| 3769 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3770 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 3771 | const u8 *rates) |
| 3772 | { |
| 3773 | int i; |
| 3774 | |
| 3775 | if (!rates) |
| 3776 | return; |
| 3777 | |
| 3778 | for (i = 0; i < rates[1]; i++) { |
| 3779 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 3780 | params->ht_required = true; |
| 3781 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 3782 | params->vht_required = true; |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | /* |
| 3787 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 3788 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 3789 | * benefit of drivers that rebuild IEs in the firmware. |
| 3790 | */ |
| 3791 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 3792 | { |
| 3793 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 3794 | size_t ies_len = bcn->tail_len; |
| 3795 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3796 | const u8 *rates; |
| 3797 | const u8 *cap; |
| 3798 | |
| 3799 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 3800 | nl80211_check_ap_rate_selectors(params, rates); |
| 3801 | |
| 3802 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 3803 | nl80211_check_ap_rate_selectors(params, rates); |
| 3804 | |
| 3805 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 3806 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 3807 | params->ht_cap = (void *)(cap + 2); |
| 3808 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 3809 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 3810 | params->vht_cap = (void *)(cap + 2); |
| 3811 | } |
| 3812 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3813 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3814 | struct cfg80211_ap_settings *params) |
| 3815 | { |
| 3816 | struct wireless_dev *wdev; |
| 3817 | bool ret = false; |
| 3818 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3819 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3820 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3821 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3822 | continue; |
| 3823 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3824 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3825 | continue; |
| 3826 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3827 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3828 | ret = true; |
| 3829 | break; |
| 3830 | } |
| 3831 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3832 | return ret; |
| 3833 | } |
| 3834 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3835 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3836 | enum nl80211_auth_type auth_type, |
| 3837 | enum nl80211_commands cmd) |
| 3838 | { |
| 3839 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3840 | return false; |
| 3841 | |
| 3842 | switch (cmd) { |
| 3843 | case NL80211_CMD_AUTHENTICATE: |
| 3844 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3845 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3846 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3847 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3848 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3849 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3850 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3851 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3852 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3853 | return true; |
| 3854 | case NL80211_CMD_CONNECT: |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3855 | /* SAE not supported yet */ |
| 3856 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3857 | return false; |
| 3858 | /* FILS with SK PFS or PK not supported yet */ |
| 3859 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3860 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3861 | return false; |
| 3862 | if (!wiphy_ext_feature_isset( |
| 3863 | &rdev->wiphy, |
| 3864 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 3865 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 3866 | return false; |
| 3867 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3868 | case NL80211_CMD_START_AP: |
| 3869 | /* SAE not supported yet */ |
| 3870 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3871 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3872 | /* FILS not supported yet */ |
| 3873 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3874 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3875 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3876 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3877 | return true; |
| 3878 | default: |
| 3879 | return false; |
| 3880 | } |
| 3881 | } |
| 3882 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3883 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3884 | { |
| 3885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3886 | struct net_device *dev = info->user_ptr[1]; |
| 3887 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3888 | struct cfg80211_ap_settings params; |
| 3889 | int err; |
| 3890 | |
| 3891 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3892 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3893 | return -EOPNOTSUPP; |
| 3894 | |
| 3895 | if (!rdev->ops->start_ap) |
| 3896 | return -EOPNOTSUPP; |
| 3897 | |
| 3898 | if (wdev->beacon_interval) |
| 3899 | return -EALREADY; |
| 3900 | |
| 3901 | memset(¶ms, 0, sizeof(params)); |
| 3902 | |
| 3903 | /* these are required for START_AP */ |
| 3904 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3905 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3906 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3907 | return -EINVAL; |
| 3908 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3909 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3910 | if (err) |
| 3911 | return err; |
| 3912 | |
| 3913 | params.beacon_interval = |
| 3914 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3915 | params.dtim_period = |
| 3916 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3917 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3918 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3919 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3920 | if (err) |
| 3921 | return err; |
| 3922 | |
| 3923 | /* |
| 3924 | * In theory, some of these attributes should be required here |
| 3925 | * but since they were not used when the command was originally |
| 3926 | * added, keep them optional for old user space programs to let |
| 3927 | * them continue to work with drivers that do not need the |
| 3928 | * additional information -- drivers must check! |
| 3929 | */ |
| 3930 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3931 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3932 | params.ssid_len = |
| 3933 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3934 | if (params.ssid_len == 0 || |
| 3935 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3936 | return -EINVAL; |
| 3937 | } |
| 3938 | |
| 3939 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3940 | params.hidden_ssid = nla_get_u32( |
| 3941 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3942 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3943 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3944 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3945 | return -EINVAL; |
| 3946 | } |
| 3947 | |
| 3948 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3949 | |
| 3950 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3951 | params.auth_type = nla_get_u32( |
| 3952 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3953 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3954 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3955 | return -EINVAL; |
| 3956 | } else |
| 3957 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3958 | |
| 3959 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3960 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3961 | if (err) |
| 3962 | return err; |
| 3963 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3964 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3965 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3966 | return -EOPNOTSUPP; |
| 3967 | params.inactivity_timeout = nla_get_u16( |
| 3968 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3969 | } |
| 3970 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3971 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3972 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3973 | return -EINVAL; |
| 3974 | params.p2p_ctwindow = |
| 3975 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3976 | if (params.p2p_ctwindow > 127) |
| 3977 | return -EINVAL; |
| 3978 | if (params.p2p_ctwindow != 0 && |
| 3979 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3980 | return -EINVAL; |
| 3981 | } |
| 3982 | |
| 3983 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3984 | u8 tmp; |
| 3985 | |
| 3986 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3987 | return -EINVAL; |
| 3988 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3989 | if (tmp > 1) |
| 3990 | return -EINVAL; |
| 3991 | params.p2p_opp_ps = tmp; |
| 3992 | if (params.p2p_opp_ps != 0 && |
| 3993 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3994 | return -EINVAL; |
| 3995 | } |
| 3996 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3997 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3998 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3999 | if (err) |
| 4000 | return err; |
| 4001 | } else if (wdev->preset_chandef.chan) { |
| 4002 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4003 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4004 | return -EINVAL; |
| 4005 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4006 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4007 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4008 | return -EINVAL; |
| 4009 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4010 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4011 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4012 | if (err) |
| 4013 | return err; |
| 4014 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4015 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4016 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4017 | if (err) |
| 4018 | return err; |
| 4019 | } |
| 4020 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4021 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4022 | params.smps_mode = |
| 4023 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4024 | switch (params.smps_mode) { |
| 4025 | case NL80211_SMPS_OFF: |
| 4026 | break; |
| 4027 | case NL80211_SMPS_STATIC: |
| 4028 | if (!(rdev->wiphy.features & |
| 4029 | NL80211_FEATURE_STATIC_SMPS)) |
| 4030 | return -EINVAL; |
| 4031 | break; |
| 4032 | case NL80211_SMPS_DYNAMIC: |
| 4033 | if (!(rdev->wiphy.features & |
| 4034 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4035 | return -EINVAL; |
| 4036 | break; |
| 4037 | default: |
| 4038 | return -EINVAL; |
| 4039 | } |
| 4040 | } else { |
| 4041 | params.smps_mode = NL80211_SMPS_OFF; |
| 4042 | } |
| 4043 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4044 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4045 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4046 | return -EOPNOTSUPP; |
| 4047 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4048 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4049 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4050 | if (IS_ERR(params.acl)) |
| 4051 | return PTR_ERR(params.acl); |
| 4052 | } |
| 4053 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4054 | nl80211_calculate_ap_params(¶ms); |
| 4055 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4056 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4057 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4058 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4059 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4060 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4061 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4062 | wdev->ssid_len = params.ssid_len; |
| 4063 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4064 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4065 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4066 | |
| 4067 | kfree(params.acl); |
| 4068 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4069 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4072 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4073 | { |
| 4074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4075 | struct net_device *dev = info->user_ptr[1]; |
| 4076 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4077 | struct cfg80211_beacon_data params; |
| 4078 | int err; |
| 4079 | |
| 4080 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4081 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4082 | return -EOPNOTSUPP; |
| 4083 | |
| 4084 | if (!rdev->ops->change_beacon) |
| 4085 | return -EOPNOTSUPP; |
| 4086 | |
| 4087 | if (!wdev->beacon_interval) |
| 4088 | return -EINVAL; |
| 4089 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4090 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4091 | if (err) |
| 4092 | return err; |
| 4093 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4094 | wdev_lock(wdev); |
| 4095 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4096 | wdev_unlock(wdev); |
| 4097 | |
| 4098 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | 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] | 4102 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4104 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4105 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4106 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4107 | } |
| 4108 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4109 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4110 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4111 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4112 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4113 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4114 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4115 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4116 | }; |
| 4117 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4118 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4119 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4120 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4121 | { |
| 4122 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4123 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4124 | int flag; |
| 4125 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4126 | /* |
| 4127 | * Try parsing the new attribute first so userspace |
| 4128 | * can specify both for older kernels. |
| 4129 | */ |
| 4130 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4131 | if (nla) { |
| 4132 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4133 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4134 | sta_flags = nla_data(nla); |
| 4135 | params->sta_flags_mask = sta_flags->mask; |
| 4136 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4137 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4138 | if ((params->sta_flags_mask | |
| 4139 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4140 | return -EINVAL; |
| 4141 | return 0; |
| 4142 | } |
| 4143 | |
| 4144 | /* if present, parse the old attribute */ |
| 4145 | |
| 4146 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4147 | if (!nla) |
| 4148 | return 0; |
| 4149 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 4150 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4151 | sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4152 | return -EINVAL; |
| 4153 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4154 | /* |
| 4155 | * Only allow certain flags for interface types so that |
| 4156 | * other attributes are silently ignored. Remember that |
| 4157 | * this is backward compatibility code with old userspace |
| 4158 | * and shouldn't be hit in other cases anyway. |
| 4159 | */ |
| 4160 | switch (iftype) { |
| 4161 | case NL80211_IFTYPE_AP: |
| 4162 | case NL80211_IFTYPE_AP_VLAN: |
| 4163 | case NL80211_IFTYPE_P2P_GO: |
| 4164 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4165 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4166 | BIT(NL80211_STA_FLAG_WME) | |
| 4167 | BIT(NL80211_STA_FLAG_MFP); |
| 4168 | break; |
| 4169 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4170 | case NL80211_IFTYPE_STATION: |
| 4171 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4172 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4173 | break; |
| 4174 | case NL80211_IFTYPE_MESH_POINT: |
| 4175 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4176 | BIT(NL80211_STA_FLAG_MFP) | |
| 4177 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4178 | default: |
| 4179 | return -EINVAL; |
| 4180 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4181 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4182 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4183 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4184 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4185 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4186 | /* no longer support new API additions in old API */ |
| 4187 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4188 | return -EINVAL; |
| 4189 | } |
| 4190 | } |
| 4191 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4192 | return 0; |
| 4193 | } |
| 4194 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4195 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4196 | int attr) |
| 4197 | { |
| 4198 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4199 | u32 bitrate; |
| 4200 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4201 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4202 | |
| 4203 | rate = nla_nest_start(msg, attr); |
| 4204 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4205 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4206 | |
| 4207 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4208 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4209 | /* report 16-bit bitrate only if we can */ |
| 4210 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4211 | if (bitrate > 0 && |
| 4212 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4213 | return false; |
| 4214 | if (bitrate_compat > 0 && |
| 4215 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4216 | return false; |
| 4217 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4218 | switch (info->bw) { |
| 4219 | case RATE_INFO_BW_5: |
| 4220 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4221 | break; |
| 4222 | case RATE_INFO_BW_10: |
| 4223 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4224 | break; |
| 4225 | default: |
| 4226 | WARN_ON(1); |
| 4227 | /* fall through */ |
| 4228 | case RATE_INFO_BW_20: |
| 4229 | rate_flg = 0; |
| 4230 | break; |
| 4231 | case RATE_INFO_BW_40: |
| 4232 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4233 | break; |
| 4234 | case RATE_INFO_BW_80: |
| 4235 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4236 | break; |
| 4237 | case RATE_INFO_BW_160: |
| 4238 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4239 | break; |
| 4240 | } |
| 4241 | |
| 4242 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4243 | return false; |
| 4244 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4245 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4246 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4247 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4248 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4249 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4250 | return false; |
| 4251 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4252 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4253 | return false; |
| 4254 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4255 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4256 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4257 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4258 | return false; |
| 4259 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4260 | |
| 4261 | nla_nest_end(msg, rate); |
| 4262 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4263 | } |
| 4264 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4265 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4266 | int id) |
| 4267 | { |
| 4268 | void *attr; |
| 4269 | int i = 0; |
| 4270 | |
| 4271 | if (!mask) |
| 4272 | return true; |
| 4273 | |
| 4274 | attr = nla_nest_start(msg, id); |
| 4275 | if (!attr) |
| 4276 | return false; |
| 4277 | |
| 4278 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4279 | if (!(mask & BIT(i))) |
| 4280 | continue; |
| 4281 | |
| 4282 | if (nla_put_u8(msg, i, signal[i])) |
| 4283 | return false; |
| 4284 | } |
| 4285 | |
| 4286 | nla_nest_end(msg, attr); |
| 4287 | |
| 4288 | return true; |
| 4289 | } |
| 4290 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4291 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4292 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4293 | struct cfg80211_registered_device *rdev, |
| 4294 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4295 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4296 | { |
| 4297 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4298 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4299 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4300 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4301 | if (!hdr) |
| 4302 | return -1; |
| 4303 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4304 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4305 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4306 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4307 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4308 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4309 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4310 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4311 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4312 | |
| 4313 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4314 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4315 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4316 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4317 | sinfo->memb)) \ |
| 4318 | goto nla_put_failure; \ |
| 4319 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4320 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4321 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4322 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4323 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4324 | goto nla_put_failure; \ |
| 4325 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4326 | |
| 4327 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4328 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4329 | |
| 4330 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4331 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4332 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4333 | (u32)sinfo->rx_bytes)) |
| 4334 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4335 | |
| 4336 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4337 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4338 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4339 | (u32)sinfo->tx_bytes)) |
| 4340 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4341 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4342 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4343 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4344 | PUT_SINFO(LLID, llid, u16); |
| 4345 | PUT_SINFO(PLID, plid, u16); |
| 4346 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4347 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4348 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4349 | switch (rdev->wiphy.signal_type) { |
| 4350 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4351 | PUT_SINFO(SIGNAL, signal, u8); |
| 4352 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4353 | break; |
| 4354 | default: |
| 4355 | break; |
| 4356 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4357 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4358 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4359 | sinfo->chain_signal, |
| 4360 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4361 | goto nla_put_failure; |
| 4362 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4363 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4364 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4365 | sinfo->chain_signal_avg, |
| 4366 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4367 | goto nla_put_failure; |
| 4368 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4369 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4370 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4371 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4372 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4373 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4374 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4375 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4376 | NL80211_STA_INFO_RX_BITRATE)) |
| 4377 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4378 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4379 | |
| 4380 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4381 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4382 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4383 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4384 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4385 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4386 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4387 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4388 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4389 | |
| 4390 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4391 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4392 | if (!bss_param) |
| 4393 | goto nla_put_failure; |
| 4394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4395 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4396 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4397 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4398 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4399 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4400 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4401 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4402 | sinfo->bss_param.dtim_period) || |
| 4403 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4404 | sinfo->bss_param.beacon_interval)) |
| 4405 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4406 | |
| 4407 | nla_nest_end(msg, bss_param); |
| 4408 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4409 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4410 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4411 | sizeof(struct nl80211_sta_flag_update), |
| 4412 | &sinfo->sta_flags)) |
| 4413 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4414 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4415 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4416 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4417 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4418 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4419 | |
| 4420 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4421 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4422 | |
| 4423 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4424 | struct nlattr *tidsattr; |
| 4425 | int tid; |
| 4426 | |
| 4427 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4428 | if (!tidsattr) |
| 4429 | goto nla_put_failure; |
| 4430 | |
| 4431 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4432 | struct cfg80211_tid_stats *tidstats; |
| 4433 | struct nlattr *tidattr; |
| 4434 | |
| 4435 | tidstats = &sinfo->pertid[tid]; |
| 4436 | |
| 4437 | if (!tidstats->filled) |
| 4438 | continue; |
| 4439 | |
| 4440 | tidattr = nla_nest_start(msg, tid + 1); |
| 4441 | if (!tidattr) |
| 4442 | goto nla_put_failure; |
| 4443 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4444 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4445 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4446 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4447 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4448 | goto nla_put_failure; \ |
| 4449 | } while (0) |
| 4450 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4451 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4452 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4453 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4454 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4455 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4456 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4457 | nla_nest_end(msg, tidattr); |
| 4458 | } |
| 4459 | |
| 4460 | nla_nest_end(msg, tidsattr); |
| 4461 | } |
| 4462 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4463 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4464 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4465 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4466 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4467 | sinfo->assoc_req_ies)) |
| 4468 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4469 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4470 | genlmsg_end(msg, hdr); |
| 4471 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4472 | |
| 4473 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4474 | genlmsg_cancel(msg, hdr); |
| 4475 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4476 | } |
| 4477 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4478 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4479 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4480 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4481 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4482 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4483 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4484 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4485 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4486 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4488 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4489 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4490 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4491 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4492 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4493 | if (!wdev->netdev) { |
| 4494 | err = -EINVAL; |
| 4495 | goto out_err; |
| 4496 | } |
| 4497 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4498 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4499 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4500 | goto out_err; |
| 4501 | } |
| 4502 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4503 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4504 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4505 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4506 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4507 | if (err == -ENOENT) |
| 4508 | break; |
| 4509 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4510 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4511 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4512 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4513 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4514 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4515 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4516 | &sinfo) < 0) |
| 4517 | goto out; |
| 4518 | |
| 4519 | sta_idx++; |
| 4520 | } |
| 4521 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4522 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4523 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4524 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4525 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4526 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4527 | |
| 4528 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4529 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4530 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4531 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4534 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4535 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4536 | struct sk_buff *msg; |
| 4537 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4538 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4539 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4540 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4541 | |
| 4542 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4543 | return -EINVAL; |
| 4544 | |
| 4545 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4547 | if (!rdev->ops->get_station) |
| 4548 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4549 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4550 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4551 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4552 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4553 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4555 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4556 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4557 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4558 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4559 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4560 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | nlmsg_free(msg); |
| 4562 | return -ENOBUFS; |
| 4563 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4564 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4568 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4569 | struct station_parameters *params, |
| 4570 | enum cfg80211_station_type statype) |
| 4571 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4572 | if (params->listen_interval != -1 && |
| 4573 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4574 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4575 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4576 | if (params->support_p2p_ps != -1 && |
| 4577 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4578 | return -EINVAL; |
| 4579 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4580 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4581 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4582 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4583 | return -EINVAL; |
| 4584 | |
| 4585 | /* When you run into this, adjust the code below for the new flag */ |
| 4586 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4587 | |
| 4588 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4589 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4590 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4591 | /* |
| 4592 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4593 | * code doesn't have the bug of including TDLS in the |
| 4594 | * mask everywhere. |
| 4595 | */ |
| 4596 | if (params->sta_flags_mask & |
| 4597 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4598 | BIT(NL80211_STA_FLAG_MFP) | |
| 4599 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4600 | return -EINVAL; |
| 4601 | break; |
| 4602 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4603 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4604 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4605 | return -EINVAL; |
| 4606 | /* ignore since it can't change */ |
| 4607 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4608 | break; |
| 4609 | default: |
| 4610 | /* disallow mesh-specific things */ |
| 4611 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4612 | return -EINVAL; |
| 4613 | if (params->local_pm) |
| 4614 | return -EINVAL; |
| 4615 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4616 | return -EINVAL; |
| 4617 | } |
| 4618 | |
| 4619 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4620 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4621 | /* TDLS can't be set, ... */ |
| 4622 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4623 | return -EINVAL; |
| 4624 | /* |
| 4625 | * ... but don't bother the driver with it. This works around |
| 4626 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4627 | * TLDS_PEER flag in the mask even for AP mode. |
| 4628 | */ |
| 4629 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4630 | } |
| 4631 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4632 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4633 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4634 | /* reject other things that can't change */ |
| 4635 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4636 | return -EINVAL; |
| 4637 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4638 | return -EINVAL; |
| 4639 | if (params->supported_rates) |
| 4640 | return -EINVAL; |
| 4641 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4642 | return -EINVAL; |
| 4643 | } |
| 4644 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4645 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4646 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4647 | if (params->vlan) |
| 4648 | return -EINVAL; |
| 4649 | } |
| 4650 | |
| 4651 | switch (statype) { |
| 4652 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4653 | /* Use this only for authorizing/unauthorizing a station */ |
| 4654 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4655 | return -EOPNOTSUPP; |
| 4656 | break; |
| 4657 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4658 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4659 | /* accept only the listed bits */ |
| 4660 | if (params->sta_flags_mask & |
| 4661 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4662 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4663 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4664 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4665 | BIT(NL80211_STA_FLAG_WME) | |
| 4666 | BIT(NL80211_STA_FLAG_MFP))) |
| 4667 | return -EINVAL; |
| 4668 | |
| 4669 | /* but authenticated/associated only if driver handles it */ |
| 4670 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4671 | params->sta_flags_mask & |
| 4672 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4673 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4674 | return -EINVAL; |
| 4675 | break; |
| 4676 | case CFG80211_STA_IBSS: |
| 4677 | case CFG80211_STA_AP_STA: |
| 4678 | /* reject any changes other than AUTHORIZED */ |
| 4679 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4680 | return -EINVAL; |
| 4681 | break; |
| 4682 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4683 | /* reject any changes other than AUTHORIZED or WME */ |
| 4684 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4685 | BIT(NL80211_STA_FLAG_WME))) |
| 4686 | return -EINVAL; |
| 4687 | /* force (at least) rates when authorizing */ |
| 4688 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4689 | !params->supported_rates) |
| 4690 | return -EINVAL; |
| 4691 | break; |
| 4692 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4693 | /* reject any changes */ |
| 4694 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4695 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4696 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4697 | return -EINVAL; |
| 4698 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4699 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4700 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4701 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4702 | return -EINVAL; |
| 4703 | break; |
| 4704 | } |
| 4705 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4706 | /* |
| 4707 | * Older kernel versions ignored this attribute entirely, so don't |
| 4708 | * reject attempts to update it but mark it as unused instead so the |
| 4709 | * driver won't look at the data. |
| 4710 | */ |
| 4711 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 4712 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 4713 | params->opmode_notif_used = false; |
| 4714 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4715 | return 0; |
| 4716 | } |
| 4717 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4718 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4719 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4720 | * 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] | 4721 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4722 | static struct net_device *get_vlan(struct genl_info *info, |
| 4723 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4724 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4725 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4726 | struct net_device *v; |
| 4727 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4728 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4729 | if (!vlanattr) |
| 4730 | return NULL; |
| 4731 | |
| 4732 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4733 | if (!v) |
| 4734 | return ERR_PTR(-ENODEV); |
| 4735 | |
| 4736 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4737 | ret = -EINVAL; |
| 4738 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4739 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4740 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4741 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4742 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4743 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4744 | ret = -EINVAL; |
| 4745 | goto error; |
| 4746 | } |
| 4747 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4748 | if (!netif_running(v)) { |
| 4749 | ret = -ENETDOWN; |
| 4750 | goto error; |
| 4751 | } |
| 4752 | |
| 4753 | return v; |
| 4754 | error: |
| 4755 | dev_put(v); |
| 4756 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4757 | } |
| 4758 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4759 | static const struct nla_policy |
| 4760 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4761 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4762 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4763 | }; |
| 4764 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4765 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4766 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4767 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4768 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4769 | struct nlattr *nla; |
| 4770 | int err; |
| 4771 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4772 | /* parse WME attributes if present */ |
| 4773 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4774 | return 0; |
| 4775 | |
| 4776 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4777 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4778 | nl80211_sta_wme_policy, info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4779 | if (err) |
| 4780 | return err; |
| 4781 | |
| 4782 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4783 | params->uapsd_queues = nla_get_u8( |
| 4784 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4785 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4786 | return -EINVAL; |
| 4787 | |
| 4788 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4789 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4790 | |
| 4791 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4792 | return -EINVAL; |
| 4793 | |
| 4794 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4795 | |
| 4796 | return 0; |
| 4797 | } |
| 4798 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4799 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4800 | struct station_parameters *params) |
| 4801 | { |
| 4802 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4803 | params->supported_channels = |
| 4804 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4805 | params->supported_channels_len = |
| 4806 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4807 | /* |
| 4808 | * Need to include at least one (first channel, number of |
| 4809 | * channels) tuple for each subband, and must have proper |
| 4810 | * tuples for the rest of the data as well. |
| 4811 | */ |
| 4812 | if (params->supported_channels_len < 2) |
| 4813 | return -EINVAL; |
| 4814 | if (params->supported_channels_len % 2) |
| 4815 | return -EINVAL; |
| 4816 | } |
| 4817 | |
| 4818 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4819 | params->supported_oper_classes = |
| 4820 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4821 | params->supported_oper_classes_len = |
| 4822 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4823 | /* |
| 4824 | * The value of the Length field of the Supported Operating |
| 4825 | * Classes element is between 2 and 253. |
| 4826 | */ |
| 4827 | if (params->supported_oper_classes_len < 2 || |
| 4828 | params->supported_oper_classes_len > 253) |
| 4829 | return -EINVAL; |
| 4830 | } |
| 4831 | return 0; |
| 4832 | } |
| 4833 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4834 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4835 | struct station_parameters *params) |
| 4836 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4837 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4838 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4839 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4840 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4841 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4842 | params->ht_capa = |
| 4843 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4844 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4845 | params->vht_capa = |
| 4846 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4847 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4848 | err = nl80211_parse_sta_channel_info(info, params); |
| 4849 | if (err) |
| 4850 | return err; |
| 4851 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4852 | return nl80211_parse_sta_wme(info, params); |
| 4853 | } |
| 4854 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4855 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4856 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4858 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4859 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4860 | u8 *mac_addr; |
| 4861 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4862 | |
| 4863 | memset(¶ms, 0, sizeof(params)); |
| 4864 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4865 | if (!rdev->ops->change_station) |
| 4866 | return -EOPNOTSUPP; |
| 4867 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4868 | /* |
| 4869 | * AID and listen_interval properties can be set only for unassociated |
| 4870 | * station. Include these parameters here and will check them in |
| 4871 | * cfg80211_check_station_change(). |
| 4872 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4873 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4874 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4875 | |
| 4876 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4877 | params.listen_interval = |
| 4878 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4879 | else |
| 4880 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4881 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4882 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4883 | u8 tmp; |
| 4884 | |
| 4885 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4886 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4887 | return -EINVAL; |
| 4888 | |
| 4889 | params.support_p2p_ps = tmp; |
| 4890 | } else { |
| 4891 | params.support_p2p_ps = -1; |
| 4892 | } |
| 4893 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4894 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4895 | return -EINVAL; |
| 4896 | |
| 4897 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4898 | |
| 4899 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4900 | params.supported_rates = |
| 4901 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4902 | params.supported_rates_len = |
| 4903 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4904 | } |
| 4905 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4906 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4907 | params.capability = |
| 4908 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4909 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4910 | } |
| 4911 | |
| 4912 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4913 | params.ext_capab = |
| 4914 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4915 | params.ext_capab_len = |
| 4916 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4917 | } |
| 4918 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4919 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4920 | return -EINVAL; |
| 4921 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4922 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4923 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4924 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4925 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4926 | return -EINVAL; |
| 4927 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4928 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4929 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4930 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4931 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4932 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4933 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4934 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4935 | params.peer_aid = nla_get_u16( |
| 4936 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4937 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4938 | return -EINVAL; |
| 4939 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4940 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4941 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4942 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4944 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4945 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4946 | |
| 4947 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4948 | pm > NL80211_MESH_POWER_MAX) |
| 4949 | return -EINVAL; |
| 4950 | |
| 4951 | params.local_pm = pm; |
| 4952 | } |
| 4953 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4954 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4955 | params.opmode_notif_used = true; |
| 4956 | params.opmode_notif = |
| 4957 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4958 | } |
| 4959 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4960 | /* Include parameters for TDLS peer (will check later) */ |
| 4961 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4962 | if (err) |
| 4963 | return err; |
| 4964 | |
| 4965 | params.vlan = get_vlan(info, rdev); |
| 4966 | if (IS_ERR(params.vlan)) |
| 4967 | return PTR_ERR(params.vlan); |
| 4968 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4969 | switch (dev->ieee80211_ptr->iftype) { |
| 4970 | case NL80211_IFTYPE_AP: |
| 4971 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4972 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4973 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4974 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4975 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4976 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4977 | break; |
| 4978 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4979 | err = -EOPNOTSUPP; |
| 4980 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4981 | } |
| 4982 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4983 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4984 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4985 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4986 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4987 | if (params.vlan) |
| 4988 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4989 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4990 | return err; |
| 4991 | } |
| 4992 | |
| 4993 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4996 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4997 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4998 | struct station_parameters params; |
| 4999 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5000 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5001 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5002 | |
| 5003 | memset(¶ms, 0, sizeof(params)); |
| 5004 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5005 | if (!rdev->ops->add_station) |
| 5006 | return -EOPNOTSUPP; |
| 5007 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5008 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5009 | return -EINVAL; |
| 5010 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5011 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5012 | return -EINVAL; |
| 5013 | |
| 5014 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5015 | return -EINVAL; |
| 5016 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5017 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5018 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5019 | return -EINVAL; |
| 5020 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5021 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5022 | params.supported_rates = |
| 5023 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5024 | params.supported_rates_len = |
| 5025 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5026 | params.listen_interval = |
| 5027 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5028 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5029 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5030 | u8 tmp; |
| 5031 | |
| 5032 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5033 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5034 | return -EINVAL; |
| 5035 | |
| 5036 | params.support_p2p_ps = tmp; |
| 5037 | } else { |
| 5038 | /* |
| 5039 | * if not specified, assume it's supported for P2P GO interface, |
| 5040 | * and is NOT supported for AP interface |
| 5041 | */ |
| 5042 | params.support_p2p_ps = |
| 5043 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5044 | } |
| 5045 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5046 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5047 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5048 | else |
| 5049 | 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] | 5050 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 5051 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5052 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5053 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5054 | params.capability = |
| 5055 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5056 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5057 | } |
| 5058 | |
| 5059 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5060 | params.ext_capab = |
| 5061 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5062 | params.ext_capab_len = |
| 5063 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5064 | } |
| 5065 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5066 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5067 | params.ht_capa = |
| 5068 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5069 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5070 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5071 | params.vht_capa = |
| 5072 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5073 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5074 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5075 | params.opmode_notif_used = true; |
| 5076 | params.opmode_notif = |
| 5077 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5078 | } |
| 5079 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5080 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5081 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5082 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5083 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5084 | return -EINVAL; |
| 5085 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5086 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5087 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5088 | if (err) |
| 5089 | return err; |
| 5090 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5091 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5092 | if (err) |
| 5093 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5094 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5095 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5096 | return -EINVAL; |
| 5097 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5098 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5099 | * as userspace might just pass through the capabilities from the IEs |
| 5100 | * directly, rather than enforcing this restriction and returning an |
| 5101 | * error in this case. |
| 5102 | */ |
| 5103 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5104 | params.ht_capa = NULL; |
| 5105 | params.vht_capa = NULL; |
| 5106 | } |
| 5107 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5108 | /* When you run into this, adjust the code below for the new flag */ |
| 5109 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5110 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5111 | switch (dev->ieee80211_ptr->iftype) { |
| 5112 | case NL80211_IFTYPE_AP: |
| 5113 | case NL80211_IFTYPE_AP_VLAN: |
| 5114 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5115 | /* ignore WME attributes if iface/sta is not capable */ |
| 5116 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5117 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5118 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5119 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5120 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5121 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5122 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5123 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5124 | /* but don't bother the driver with it */ |
| 5125 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5126 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5127 | /* allow authenticated/associated only if driver handles it */ |
| 5128 | if (!(rdev->wiphy.features & |
| 5129 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5130 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5131 | return -EINVAL; |
| 5132 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5133 | /* Older userspace, or userspace wanting to be compatible with |
| 5134 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5135 | * and assoc flags in the mask, but assumes the station will be |
| 5136 | * added as associated anyway since this was the required driver |
| 5137 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5138 | * introduced. |
| 5139 | * In order to not bother drivers with this quirk in the API |
| 5140 | * set the flags in both the mask and set for new stations in |
| 5141 | * this case. |
| 5142 | */ |
| 5143 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5144 | params.sta_flags_mask |= auth_assoc; |
| 5145 | params.sta_flags_set |= auth_assoc; |
| 5146 | } |
| 5147 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5148 | /* must be last in here for error handling */ |
| 5149 | params.vlan = get_vlan(info, rdev); |
| 5150 | if (IS_ERR(params.vlan)) |
| 5151 | return PTR_ERR(params.vlan); |
| 5152 | break; |
| 5153 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5154 | /* ignore uAPSD data */ |
| 5155 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5156 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5157 | /* associated is disallowed */ |
| 5158 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5159 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5160 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5161 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5162 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5163 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5164 | break; |
| 5165 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5166 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5167 | /* ignore uAPSD data */ |
| 5168 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5169 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5170 | /* these are disallowed */ |
| 5171 | if (params.sta_flags_mask & |
| 5172 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5173 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5174 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5175 | /* Only TDLS peers can be added */ |
| 5176 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5177 | return -EINVAL; |
| 5178 | /* Can only add if TDLS ... */ |
| 5179 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5180 | return -EOPNOTSUPP; |
| 5181 | /* ... with external setup is supported */ |
| 5182 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5183 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5184 | /* |
| 5185 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5186 | * as authorized, but it shouldn't yet be. |
| 5187 | */ |
| 5188 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5189 | break; |
| 5190 | default: |
| 5191 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5192 | } |
| 5193 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5194 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5195 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5196 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5197 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5198 | if (params.vlan) |
| 5199 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5200 | return err; |
| 5201 | } |
| 5202 | |
| 5203 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5204 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5206 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5207 | struct station_del_parameters params; |
| 5208 | |
| 5209 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5210 | |
| 5211 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5212 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5213 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5214 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5215 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5216 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5217 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5218 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5219 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5220 | if (!rdev->ops->del_station) |
| 5221 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5222 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5223 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5224 | params.subtype = |
| 5225 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5226 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5227 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5228 | return -EINVAL; |
| 5229 | } else { |
| 5230 | /* Default to Deauthentication frame */ |
| 5231 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5232 | } |
| 5233 | |
| 5234 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5235 | params.reason_code = |
| 5236 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5237 | if (params.reason_code == 0) |
| 5238 | return -EINVAL; /* 0 is reserved */ |
| 5239 | } else { |
| 5240 | /* Default to reason code 2 */ |
| 5241 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5242 | } |
| 5243 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5244 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5245 | } |
| 5246 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5247 | 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] | 5248 | int flags, struct net_device *dev, |
| 5249 | u8 *dst, u8 *next_hop, |
| 5250 | struct mpath_info *pinfo) |
| 5251 | { |
| 5252 | void *hdr; |
| 5253 | struct nlattr *pinfoattr; |
| 5254 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5255 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5256 | if (!hdr) |
| 5257 | return -1; |
| 5258 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5259 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5260 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5261 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5262 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5263 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5264 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5265 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5266 | if (!pinfoattr) |
| 5267 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5268 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5269 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5270 | pinfo->frame_qlen)) |
| 5271 | goto nla_put_failure; |
| 5272 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5273 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5274 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5275 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5276 | pinfo->metric)) || |
| 5277 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5278 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5279 | pinfo->exptime)) || |
| 5280 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5281 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5282 | pinfo->flags)) || |
| 5283 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5284 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5285 | pinfo->discovery_timeout)) || |
| 5286 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5287 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5288 | pinfo->discovery_retries))) |
| 5289 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5290 | |
| 5291 | nla_nest_end(msg, pinfoattr); |
| 5292 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5293 | genlmsg_end(msg, hdr); |
| 5294 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5295 | |
| 5296 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5297 | genlmsg_cancel(msg, hdr); |
| 5298 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5302 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5303 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5304 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5305 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5306 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5307 | u8 dst[ETH_ALEN]; |
| 5308 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5309 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5310 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5311 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5312 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5313 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5314 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5315 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5316 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5317 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5318 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5319 | goto out_err; |
| 5320 | } |
| 5321 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5322 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5323 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5324 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5325 | } |
| 5326 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5327 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5328 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5329 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5330 | if (err == -ENOENT) |
| 5331 | break; |
| 5332 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5333 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5334 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5335 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5336 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5337 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5338 | &pinfo) < 0) |
| 5339 | goto out; |
| 5340 | |
| 5341 | path_idx++; |
| 5342 | } |
| 5343 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5344 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5345 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5346 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5347 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5348 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5349 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5355 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5356 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5357 | struct mpath_info pinfo; |
| 5358 | struct sk_buff *msg; |
| 5359 | u8 *dst = NULL; |
| 5360 | u8 next_hop[ETH_ALEN]; |
| 5361 | |
| 5362 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5363 | |
| 5364 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5365 | return -EINVAL; |
| 5366 | |
| 5367 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5368 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5369 | if (!rdev->ops->get_mpath) |
| 5370 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5373 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5374 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5375 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5376 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5377 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5378 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5380 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5381 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5382 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5383 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5384 | dev, dst, next_hop, &pinfo) < 0) { |
| 5385 | nlmsg_free(msg); |
| 5386 | return -ENOBUFS; |
| 5387 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5388 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5389 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5393 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5395 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5396 | u8 *dst = NULL; |
| 5397 | u8 *next_hop = NULL; |
| 5398 | |
| 5399 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5400 | return -EINVAL; |
| 5401 | |
| 5402 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5403 | return -EINVAL; |
| 5404 | |
| 5405 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5406 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5408 | if (!rdev->ops->change_mpath) |
| 5409 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5411 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5412 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5413 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5414 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5415 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5416 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5417 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5420 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5421 | u8 *dst = NULL; |
| 5422 | u8 *next_hop = NULL; |
| 5423 | |
| 5424 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5425 | return -EINVAL; |
| 5426 | |
| 5427 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5428 | return -EINVAL; |
| 5429 | |
| 5430 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5431 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5432 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5433 | if (!rdev->ops->add_mpath) |
| 5434 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5436 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5437 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5438 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5439 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5445 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5446 | u8 *dst = NULL; |
| 5447 | |
| 5448 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5449 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5450 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5451 | if (!rdev->ops->del_mpath) |
| 5452 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5453 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5454 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5455 | } |
| 5456 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5457 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5458 | { |
| 5459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5460 | int err; |
| 5461 | struct net_device *dev = info->user_ptr[1]; |
| 5462 | struct mpath_info pinfo; |
| 5463 | struct sk_buff *msg; |
| 5464 | u8 *dst = NULL; |
| 5465 | u8 mpp[ETH_ALEN]; |
| 5466 | |
| 5467 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5468 | |
| 5469 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5470 | return -EINVAL; |
| 5471 | |
| 5472 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5473 | |
| 5474 | if (!rdev->ops->get_mpp) |
| 5475 | return -EOPNOTSUPP; |
| 5476 | |
| 5477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5478 | return -EOPNOTSUPP; |
| 5479 | |
| 5480 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5481 | if (err) |
| 5482 | return err; |
| 5483 | |
| 5484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5485 | if (!msg) |
| 5486 | return -ENOMEM; |
| 5487 | |
| 5488 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5489 | dev, dst, mpp, &pinfo) < 0) { |
| 5490 | nlmsg_free(msg); |
| 5491 | return -ENOBUFS; |
| 5492 | } |
| 5493 | |
| 5494 | return genlmsg_reply(msg, info); |
| 5495 | } |
| 5496 | |
| 5497 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5498 | struct netlink_callback *cb) |
| 5499 | { |
| 5500 | struct mpath_info pinfo; |
| 5501 | struct cfg80211_registered_device *rdev; |
| 5502 | struct wireless_dev *wdev; |
| 5503 | u8 dst[ETH_ALEN]; |
| 5504 | u8 mpp[ETH_ALEN]; |
| 5505 | int path_idx = cb->args[2]; |
| 5506 | int err; |
| 5507 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5508 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5509 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5510 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5511 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5512 | |
| 5513 | if (!rdev->ops->dump_mpp) { |
| 5514 | err = -EOPNOTSUPP; |
| 5515 | goto out_err; |
| 5516 | } |
| 5517 | |
| 5518 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5519 | err = -EOPNOTSUPP; |
| 5520 | goto out_err; |
| 5521 | } |
| 5522 | |
| 5523 | while (1) { |
| 5524 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5525 | mpp, &pinfo); |
| 5526 | if (err == -ENOENT) |
| 5527 | break; |
| 5528 | if (err) |
| 5529 | goto out_err; |
| 5530 | |
| 5531 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5532 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5533 | wdev->netdev, dst, mpp, |
| 5534 | &pinfo) < 0) |
| 5535 | goto out; |
| 5536 | |
| 5537 | path_idx++; |
| 5538 | } |
| 5539 | |
| 5540 | out: |
| 5541 | cb->args[2] = path_idx; |
| 5542 | err = skb->len; |
| 5543 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5544 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5545 | return err; |
| 5546 | } |
| 5547 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5548 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5549 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5551 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5552 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5553 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5554 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5555 | |
| 5556 | memset(¶ms, 0, sizeof(params)); |
| 5557 | /* default to not changing parameters */ |
| 5558 | params.use_cts_prot = -1; |
| 5559 | params.use_short_preamble = -1; |
| 5560 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5561 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5562 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5563 | params.p2p_ctwindow = -1; |
| 5564 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5565 | |
| 5566 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5567 | params.use_cts_prot = |
| 5568 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5569 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5570 | params.use_short_preamble = |
| 5571 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5572 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5573 | params.use_short_slot_time = |
| 5574 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5575 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5576 | params.basic_rates = |
| 5577 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5578 | params.basic_rates_len = |
| 5579 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5580 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5581 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5582 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5583 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5584 | params.ht_opmode = |
| 5585 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5586 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5587 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5588 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5589 | return -EINVAL; |
| 5590 | params.p2p_ctwindow = |
| 5591 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5592 | if (params.p2p_ctwindow < 0) |
| 5593 | return -EINVAL; |
| 5594 | if (params.p2p_ctwindow != 0 && |
| 5595 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5596 | return -EINVAL; |
| 5597 | } |
| 5598 | |
| 5599 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5600 | u8 tmp; |
| 5601 | |
| 5602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5603 | return -EINVAL; |
| 5604 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5605 | if (tmp > 1) |
| 5606 | return -EINVAL; |
| 5607 | params.p2p_opp_ps = tmp; |
| 5608 | if (params.p2p_opp_ps && |
| 5609 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5610 | return -EINVAL; |
| 5611 | } |
| 5612 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5613 | if (!rdev->ops->change_bss) |
| 5614 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5615 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5618 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5619 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5620 | wdev_lock(wdev); |
| 5621 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5622 | wdev_unlock(wdev); |
| 5623 | |
| 5624 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5625 | } |
| 5626 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5627 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5628 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5629 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5630 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5631 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5632 | u32 owner_nlportid; |
| 5633 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5634 | /* |
| 5635 | * You should only get this when cfg80211 hasn't yet initialized |
| 5636 | * completely when built-in to the kernel right between the time |
| 5637 | * window between nl80211_init() and regulatory_init(), if that is |
| 5638 | * even possible. |
| 5639 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5640 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5641 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5642 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5643 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5644 | user_reg_hint_type = |
| 5645 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5646 | else |
| 5647 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5648 | |
| 5649 | switch (user_reg_hint_type) { |
| 5650 | case NL80211_USER_REG_HINT_USER: |
| 5651 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5652 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5653 | return -EINVAL; |
| 5654 | |
| 5655 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5656 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5657 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5658 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5659 | owner_nlportid = info->snd_portid; |
| 5660 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5661 | } else { |
| 5662 | owner_nlportid = 0; |
| 5663 | is_indoor = true; |
| 5664 | } |
| 5665 | |
| 5666 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5667 | default: |
| 5668 | return -EINVAL; |
| 5669 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5670 | } |
| 5671 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5672 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5673 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5674 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5676 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5677 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5678 | struct mesh_config cur_params; |
| 5679 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5680 | void *hdr; |
| 5681 | struct nlattr *pinfoattr; |
| 5682 | struct sk_buff *msg; |
| 5683 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5684 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5685 | return -EOPNOTSUPP; |
| 5686 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5687 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5688 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5689 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5690 | wdev_lock(wdev); |
| 5691 | /* If not connected, get default parameters */ |
| 5692 | if (!wdev->mesh_id_len) |
| 5693 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5694 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5695 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5696 | wdev_unlock(wdev); |
| 5697 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5698 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5699 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5700 | |
| 5701 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5703 | if (!msg) |
| 5704 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5705 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5706 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5707 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5708 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5709 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5710 | if (!pinfoattr) |
| 5711 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5712 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5713 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5714 | cur_params.dot11MeshRetryTimeout) || |
| 5715 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5716 | cur_params.dot11MeshConfirmTimeout) || |
| 5717 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5718 | cur_params.dot11MeshHoldingTimeout) || |
| 5719 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5720 | cur_params.dot11MeshMaxPeerLinks) || |
| 5721 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5722 | cur_params.dot11MeshMaxRetries) || |
| 5723 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5724 | cur_params.dot11MeshTTL) || |
| 5725 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5726 | cur_params.element_ttl) || |
| 5727 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5728 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5729 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5730 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5731 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5732 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5733 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5734 | cur_params.path_refresh_time) || |
| 5735 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5736 | cur_params.min_discovery_timeout) || |
| 5737 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5738 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5739 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5740 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5741 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5742 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5743 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5744 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5745 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5746 | cur_params.dot11MeshHWMPRootMode) || |
| 5747 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5748 | cur_params.dot11MeshHWMPRannInterval) || |
| 5749 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5750 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5751 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5752 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 5753 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5754 | cur_params.rssi_threshold) || |
| 5755 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5756 | cur_params.ht_opmode) || |
| 5757 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5758 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5759 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5760 | cur_params.dot11MeshHWMProotInterval) || |
| 5761 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5762 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5763 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5764 | cur_params.power_mode) || |
| 5765 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5766 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5767 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5768 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5769 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5770 | nla_nest_end(msg, pinfoattr); |
| 5771 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5772 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5773 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5774 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5775 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5776 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5777 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5778 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5781 | 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] | 5782 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5783 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5784 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5785 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5786 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5787 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5788 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5789 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5790 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5791 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5792 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5793 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5794 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5795 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5796 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5797 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5798 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5799 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5800 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5801 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5802 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5803 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5804 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5805 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5806 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5807 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5808 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5809 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5810 | }; |
| 5811 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5812 | static const struct nla_policy |
| 5813 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5814 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5815 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5816 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5817 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5818 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5819 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5820 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5821 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5822 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5823 | }; |
| 5824 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5825 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5826 | { |
| 5827 | u8 val = nla_get_u8(nla); |
| 5828 | if (val < min || val > max) |
| 5829 | return -EINVAL; |
| 5830 | *out = val; |
| 5831 | return 0; |
| 5832 | } |
| 5833 | |
| 5834 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5835 | { |
| 5836 | u8 val = nla_get_u8(nla); |
| 5837 | if (val < min || val > max) |
| 5838 | return -EINVAL; |
| 5839 | *out = val; |
| 5840 | return 0; |
| 5841 | } |
| 5842 | |
| 5843 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5844 | { |
| 5845 | u16 val = nla_get_u16(nla); |
| 5846 | if (val < min || val > max) |
| 5847 | return -EINVAL; |
| 5848 | *out = val; |
| 5849 | return 0; |
| 5850 | } |
| 5851 | |
| 5852 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5853 | { |
| 5854 | u32 val = nla_get_u32(nla); |
| 5855 | if (val < min || val > max) |
| 5856 | return -EINVAL; |
| 5857 | *out = val; |
| 5858 | return 0; |
| 5859 | } |
| 5860 | |
| 5861 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5862 | { |
| 5863 | s32 val = nla_get_s32(nla); |
| 5864 | if (val < min || val > max) |
| 5865 | return -EINVAL; |
| 5866 | *out = val; |
| 5867 | return 0; |
| 5868 | } |
| 5869 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5870 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5871 | enum nl80211_mesh_power_mode min, |
| 5872 | enum nl80211_mesh_power_mode max, |
| 5873 | enum nl80211_mesh_power_mode *out) |
| 5874 | { |
| 5875 | u32 val = nla_get_u32(nla); |
| 5876 | if (val < min || val > max) |
| 5877 | return -EINVAL; |
| 5878 | *out = val; |
| 5879 | return 0; |
| 5880 | } |
| 5881 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5882 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5883 | struct mesh_config *cfg, |
| 5884 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5885 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5886 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5887 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5888 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5889 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5890 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5891 | do { \ |
| 5892 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5893 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5894 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5895 | mask |= (1 << (attr - 1)); \ |
| 5896 | } \ |
| 5897 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5898 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5899 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5900 | return -EINVAL; |
| 5901 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5902 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 5903 | nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5904 | return -EINVAL; |
| 5905 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5906 | /* This makes sure that there aren't more than 32 mesh config |
| 5907 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5908 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5909 | |
| 5910 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5912 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5913 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5914 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5915 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5916 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5917 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5918 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5919 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5921 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5922 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5923 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5924 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5925 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5927 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5928 | 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] | 5929 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5930 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5931 | 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] | 5932 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5933 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5935 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5936 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5937 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5939 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5940 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5941 | 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] | 5942 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5943 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5944 | 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] | 5945 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5946 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5948 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5949 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5950 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5951 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5952 | 1, 65535, mask, |
| 5953 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5954 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5955 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5956 | 1, 65535, mask, |
| 5957 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5958 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5960 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5961 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5962 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5963 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5965 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5966 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5968 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5969 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5970 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5971 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5972 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5973 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5974 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5975 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5976 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5977 | 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] | 5978 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5979 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5980 | /* |
| 5981 | * Check HT operation mode based on |
| 5982 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5983 | */ |
| 5984 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5985 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5986 | |
| 5987 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5988 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5989 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5990 | return -EINVAL; |
| 5991 | |
| 5992 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5993 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5994 | return -EINVAL; |
| 5995 | |
| 5996 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5997 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5998 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5999 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 6000 | return -EINVAL; |
| 6001 | break; |
| 6002 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 6003 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 6004 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6005 | return -EINVAL; |
| 6006 | break; |
| 6007 | } |
| 6008 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6009 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6010 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6012 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6013 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6014 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6015 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6016 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6017 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6018 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6019 | dot11MeshHWMPconfirmationInterval, |
| 6020 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6021 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6022 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 6024 | NL80211_MESH_POWER_ACTIVE, |
| 6025 | NL80211_MESH_POWER_MAX, |
| 6026 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6027 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6028 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 6029 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6030 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 6031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6032 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6033 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6034 | if (mask_out) |
| 6035 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6036 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6037 | return 0; |
| 6038 | |
| 6039 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6040 | } |
| 6041 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6042 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6043 | struct mesh_setup *setup) |
| 6044 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6046 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6047 | |
| 6048 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6049 | return -EINVAL; |
| 6050 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6051 | info->attrs[NL80211_ATTR_MESH_SETUP], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6052 | nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6053 | return -EINVAL; |
| 6054 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6055 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6056 | setup->sync_method = |
| 6057 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6058 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6059 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6060 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6061 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6062 | setup->path_sel_proto = |
| 6063 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6064 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6065 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6066 | |
| 6067 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6068 | setup->path_metric = |
| 6069 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6070 | IEEE80211_PATH_METRIC_VENDOR : |
| 6071 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6072 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6073 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6074 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6075 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6076 | if (!is_valid_ie_attr(ieattr)) |
| 6077 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6078 | setup->ie = nla_data(ieattr); |
| 6079 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6080 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6081 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6082 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6083 | return -EINVAL; |
| 6084 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6085 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6086 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6087 | if (setup->is_secure) |
| 6088 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6089 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6090 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6091 | if (!setup->user_mpm) |
| 6092 | return -EINVAL; |
| 6093 | setup->auth_id = |
| 6094 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6095 | } |
| 6096 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6097 | return 0; |
| 6098 | } |
| 6099 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6100 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6101 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6102 | { |
| 6103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6104 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6106 | struct mesh_config cfg; |
| 6107 | u32 mask; |
| 6108 | int err; |
| 6109 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6110 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6111 | return -EOPNOTSUPP; |
| 6112 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6113 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6114 | return -EOPNOTSUPP; |
| 6115 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6116 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6117 | if (err) |
| 6118 | return err; |
| 6119 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6120 | wdev_lock(wdev); |
| 6121 | if (!wdev->mesh_id_len) |
| 6122 | err = -ENOLINK; |
| 6123 | |
| 6124 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6125 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6126 | |
| 6127 | wdev_unlock(wdev); |
| 6128 | |
| 6129 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6130 | } |
| 6131 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6132 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6133 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6134 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6135 | struct nlattr *nl_reg_rules; |
| 6136 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6137 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6138 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6139 | (regdom->dfs_region && |
| 6140 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6141 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6142 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6143 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6144 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6145 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6146 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6147 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6148 | struct nlattr *nl_reg_rule; |
| 6149 | const struct ieee80211_reg_rule *reg_rule; |
| 6150 | const struct ieee80211_freq_range *freq_range; |
| 6151 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6152 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6153 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6154 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6155 | freq_range = ®_rule->freq_range; |
| 6156 | power_rule = ®_rule->power_rule; |
| 6157 | |
| 6158 | nl_reg_rule = nla_nest_start(msg, i); |
| 6159 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6160 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6161 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6162 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6163 | if (!max_bandwidth_khz) |
| 6164 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6165 | reg_rule); |
| 6166 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6167 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6168 | reg_rule->flags) || |
| 6169 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6170 | freq_range->start_freq_khz) || |
| 6171 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6172 | freq_range->end_freq_khz) || |
| 6173 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6174 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6175 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6176 | power_rule->max_antenna_gain) || |
| 6177 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6178 | power_rule->max_eirp) || |
| 6179 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6180 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6181 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6182 | |
| 6183 | nla_nest_end(msg, nl_reg_rule); |
| 6184 | } |
| 6185 | |
| 6186 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6187 | return 0; |
| 6188 | |
| 6189 | nla_put_failure: |
| 6190 | return -EMSGSIZE; |
| 6191 | } |
| 6192 | |
| 6193 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6194 | { |
| 6195 | const struct ieee80211_regdomain *regdom = NULL; |
| 6196 | struct cfg80211_registered_device *rdev; |
| 6197 | struct wiphy *wiphy = NULL; |
| 6198 | struct sk_buff *msg; |
| 6199 | void *hdr; |
| 6200 | |
| 6201 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6202 | if (!msg) |
| 6203 | return -ENOBUFS; |
| 6204 | |
| 6205 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6206 | NL80211_CMD_GET_REG); |
| 6207 | if (!hdr) |
| 6208 | goto put_failure; |
| 6209 | |
| 6210 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6211 | bool self_managed; |
| 6212 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6213 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6214 | if (IS_ERR(rdev)) { |
| 6215 | nlmsg_free(msg); |
| 6216 | return PTR_ERR(rdev); |
| 6217 | } |
| 6218 | |
| 6219 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6220 | self_managed = wiphy->regulatory_flags & |
| 6221 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6222 | regdom = get_wiphy_regdom(wiphy); |
| 6223 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6224 | /* a self-managed-reg device must have a private regdom */ |
| 6225 | if (WARN_ON(!regdom && self_managed)) { |
| 6226 | nlmsg_free(msg); |
| 6227 | return -EINVAL; |
| 6228 | } |
| 6229 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6230 | if (regdom && |
| 6231 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6232 | goto nla_put_failure; |
| 6233 | } |
| 6234 | |
| 6235 | if (!wiphy && reg_last_request_cell_base() && |
| 6236 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6237 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6238 | goto nla_put_failure; |
| 6239 | |
| 6240 | rcu_read_lock(); |
| 6241 | |
| 6242 | if (!regdom) |
| 6243 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6244 | |
| 6245 | if (nl80211_put_regdom(regdom, msg)) |
| 6246 | goto nla_put_failure_rcu; |
| 6247 | |
| 6248 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6249 | |
| 6250 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6251 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6252 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6253 | nla_put_failure_rcu: |
| 6254 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6255 | nla_put_failure: |
| 6256 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6257 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6258 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6259 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6260 | } |
| 6261 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6262 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6263 | u32 seq, int flags, struct wiphy *wiphy, |
| 6264 | const struct ieee80211_regdomain *regdom) |
| 6265 | { |
| 6266 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6267 | NL80211_CMD_GET_REG); |
| 6268 | |
| 6269 | if (!hdr) |
| 6270 | return -1; |
| 6271 | |
| 6272 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6273 | |
| 6274 | if (nl80211_put_regdom(regdom, msg)) |
| 6275 | goto nla_put_failure; |
| 6276 | |
| 6277 | if (!wiphy && reg_last_request_cell_base() && |
| 6278 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6279 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6280 | goto nla_put_failure; |
| 6281 | |
| 6282 | if (wiphy && |
| 6283 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6284 | goto nla_put_failure; |
| 6285 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6286 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6287 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6288 | goto nla_put_failure; |
| 6289 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6290 | genlmsg_end(msg, hdr); |
| 6291 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6292 | |
| 6293 | nla_put_failure: |
| 6294 | genlmsg_cancel(msg, hdr); |
| 6295 | return -EMSGSIZE; |
| 6296 | } |
| 6297 | |
| 6298 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6299 | struct netlink_callback *cb) |
| 6300 | { |
| 6301 | const struct ieee80211_regdomain *regdom = NULL; |
| 6302 | struct cfg80211_registered_device *rdev; |
| 6303 | int err, reg_idx, start = cb->args[2]; |
| 6304 | |
| 6305 | rtnl_lock(); |
| 6306 | |
| 6307 | if (cfg80211_regdomain && start == 0) { |
| 6308 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6309 | NLM_F_MULTI, NULL, |
| 6310 | rtnl_dereference(cfg80211_regdomain)); |
| 6311 | if (err < 0) |
| 6312 | goto out_err; |
| 6313 | } |
| 6314 | |
| 6315 | /* the global regdom is idx 0 */ |
| 6316 | reg_idx = 1; |
| 6317 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6318 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6319 | if (!regdom) |
| 6320 | continue; |
| 6321 | |
| 6322 | if (++reg_idx <= start) |
| 6323 | continue; |
| 6324 | |
| 6325 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6326 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6327 | if (err < 0) { |
| 6328 | reg_idx--; |
| 6329 | break; |
| 6330 | } |
| 6331 | } |
| 6332 | |
| 6333 | cb->args[2] = reg_idx; |
| 6334 | err = skb->len; |
| 6335 | out_err: |
| 6336 | rtnl_unlock(); |
| 6337 | return err; |
| 6338 | } |
| 6339 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6340 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6341 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6342 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6343 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6344 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6345 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6346 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6347 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6348 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6349 | }; |
| 6350 | |
| 6351 | static int parse_reg_rule(struct nlattr *tb[], |
| 6352 | struct ieee80211_reg_rule *reg_rule) |
| 6353 | { |
| 6354 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6355 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6356 | |
| 6357 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6358 | return -EINVAL; |
| 6359 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6360 | return -EINVAL; |
| 6361 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6362 | return -EINVAL; |
| 6363 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6364 | return -EINVAL; |
| 6365 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6366 | return -EINVAL; |
| 6367 | |
| 6368 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6369 | |
| 6370 | freq_range->start_freq_khz = |
| 6371 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6372 | freq_range->end_freq_khz = |
| 6373 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6374 | freq_range->max_bandwidth_khz = |
| 6375 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6376 | |
| 6377 | power_rule->max_eirp = |
| 6378 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6379 | |
| 6380 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6381 | power_rule->max_antenna_gain = |
| 6382 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6383 | |
| 6384 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6385 | reg_rule->dfs_cac_ms = |
| 6386 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6387 | |
| 6388 | return 0; |
| 6389 | } |
| 6390 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6391 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6392 | { |
| 6393 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6394 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6395 | char *alpha2; |
| 6396 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6397 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6398 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6399 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6400 | |
| 6401 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6402 | return -EINVAL; |
| 6403 | |
| 6404 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6405 | return -EINVAL; |
| 6406 | |
| 6407 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6408 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6409 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6410 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6411 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6412 | 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] | 6413 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6414 | num_rules++; |
| 6415 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6416 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6417 | } |
| 6418 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6419 | if (!reg_is_valid_request(alpha2)) |
| 6420 | return -EINVAL; |
| 6421 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6422 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6423 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6424 | |
| 6425 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6426 | if (!rd) |
| 6427 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6428 | |
| 6429 | rd->n_reg_rules = num_rules; |
| 6430 | rd->alpha2[0] = alpha2[0]; |
| 6431 | rd->alpha2[1] = alpha2[1]; |
| 6432 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6433 | /* |
| 6434 | * Disable DFS master mode if the DFS region was |
| 6435 | * not supported or known on this kernel. |
| 6436 | */ |
| 6437 | if (reg_supported_dfs_region(dfs_region)) |
| 6438 | rd->dfs_region = dfs_region; |
| 6439 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6440 | 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] | 6441 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6442 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6443 | nl_reg_rule, reg_rule_policy, |
| 6444 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6445 | if (r) |
| 6446 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6447 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6448 | if (r) |
| 6449 | goto bad_reg; |
| 6450 | |
| 6451 | rule_idx++; |
| 6452 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6453 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6454 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6455 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6456 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6457 | } |
| 6458 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6459 | /* set_regdom takes ownership of rd */ |
| 6460 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6461 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6462 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6463 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6464 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6465 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6466 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6467 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6468 | { |
| 6469 | struct nlattr *attr1, *attr2; |
| 6470 | int n_channels = 0, tmp1, tmp2; |
| 6471 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6472 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6473 | if (nla_len(attr1) != sizeof(u32)) |
| 6474 | return 0; |
| 6475 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6476 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6477 | n_channels++; |
| 6478 | /* |
| 6479 | * Some hardware has a limited channel list for |
| 6480 | * scanning, and it is pretty much nonsensical |
| 6481 | * to scan for a channel twice, so disallow that |
| 6482 | * and don't require drivers to check that the |
| 6483 | * channel list they get isn't longer than what |
| 6484 | * they can scan, as long as they can scan all |
| 6485 | * the channels they registered at once. |
| 6486 | */ |
| 6487 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6488 | if (attr1 != attr2 && |
| 6489 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6490 | return 0; |
| 6491 | } |
| 6492 | |
| 6493 | return n_channels; |
| 6494 | } |
| 6495 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6496 | 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] | 6497 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6498 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6502 | struct cfg80211_bss_selection *bss_select) |
| 6503 | { |
| 6504 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6505 | struct nlattr *nest; |
| 6506 | int err; |
| 6507 | bool found = false; |
| 6508 | int i; |
| 6509 | |
| 6510 | /* only process one nested attribute */ |
| 6511 | nest = nla_data(nla); |
| 6512 | if (!nla_ok(nest, nla_len(nest))) |
| 6513 | return -EINVAL; |
| 6514 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6515 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 6516 | nl80211_bss_select_policy, NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6517 | if (err) |
| 6518 | return err; |
| 6519 | |
| 6520 | /* only one attribute may be given */ |
| 6521 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6522 | if (attr[i]) { |
| 6523 | if (found) |
| 6524 | return -EINVAL; |
| 6525 | found = true; |
| 6526 | } |
| 6527 | } |
| 6528 | |
| 6529 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6530 | |
| 6531 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6532 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6533 | |
| 6534 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6535 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6536 | bss_select->param.band_pref = |
| 6537 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6538 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6539 | return -EINVAL; |
| 6540 | } |
| 6541 | |
| 6542 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6543 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6544 | |
| 6545 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6546 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6547 | bss_select->param.adjust.band = adj_param->band; |
| 6548 | bss_select->param.adjust.delta = adj_param->delta; |
| 6549 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6550 | return -EINVAL; |
| 6551 | } |
| 6552 | |
| 6553 | /* user-space did not provide behaviour attribute */ |
| 6554 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6555 | return -EINVAL; |
| 6556 | |
| 6557 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6558 | return -EINVAL; |
| 6559 | |
| 6560 | return 0; |
| 6561 | } |
| 6562 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6563 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6564 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6565 | { |
| 6566 | int i; |
| 6567 | |
| 6568 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6569 | eth_zero_addr(mac_addr); |
| 6570 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6571 | mac_addr[0] = 0x2; |
| 6572 | mac_addr_mask[0] = 0x3; |
| 6573 | |
| 6574 | return 0; |
| 6575 | } |
| 6576 | |
| 6577 | /* need both or none */ |
| 6578 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6579 | return -EINVAL; |
| 6580 | |
| 6581 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6582 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6583 | |
| 6584 | /* don't allow or configure an mcast address */ |
| 6585 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6586 | is_multicast_ether_addr(mac_addr)) |
| 6587 | return -EINVAL; |
| 6588 | |
| 6589 | /* |
| 6590 | * allow users to pass a MAC address that has bits set outside |
| 6591 | * of the mask, but don't bother drivers with having to deal |
| 6592 | * with such bits |
| 6593 | */ |
| 6594 | for (i = 0; i < ETH_ALEN; i++) |
| 6595 | mac_addr[i] &= mac_addr_mask[i]; |
| 6596 | |
| 6597 | return 0; |
| 6598 | } |
| 6599 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6600 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 6601 | { |
| 6602 | ASSERT_WDEV_LOCK(wdev); |
| 6603 | |
| 6604 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 6605 | return true; |
| 6606 | |
| 6607 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 6608 | return true; |
| 6609 | |
| 6610 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 6611 | } |
| 6612 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6613 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6614 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6616 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6617 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6618 | struct nlattr *attr; |
| 6619 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6620 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6621 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6622 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6623 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6624 | return -EINVAL; |
| 6625 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6626 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6627 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6628 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6629 | return -EOPNOTSUPP; |
| 6630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6631 | if (!rdev->ops->scan) |
| 6632 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6633 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6634 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6635 | err = -EBUSY; |
| 6636 | goto unlock; |
| 6637 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6638 | |
| 6639 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6640 | n_channels = validate_scan_freqs( |
| 6641 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6642 | if (!n_channels) { |
| 6643 | err = -EINVAL; |
| 6644 | goto unlock; |
| 6645 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6646 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6647 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6651 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6652 | n_ssids++; |
| 6653 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6654 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6655 | err = -EINVAL; |
| 6656 | goto unlock; |
| 6657 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6658 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6659 | if (info->attrs[NL80211_ATTR_IE]) |
| 6660 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6661 | else |
| 6662 | ie_len = 0; |
| 6663 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6664 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6665 | err = -EINVAL; |
| 6666 | goto unlock; |
| 6667 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6668 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6669 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6670 | + sizeof(*request->ssids) * n_ssids |
| 6671 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6672 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6673 | if (!request) { |
| 6674 | err = -ENOMEM; |
| 6675 | goto unlock; |
| 6676 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6677 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6678 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6679 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6680 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6681 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6682 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6683 | request->ie = (void *)(request->ssids + n_ssids); |
| 6684 | else |
| 6685 | request->ie = (void *)(request->channels + n_channels); |
| 6686 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6687 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6688 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6689 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6690 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6691 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6692 | struct ieee80211_channel *chan; |
| 6693 | |
| 6694 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6695 | |
| 6696 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6697 | err = -EINVAL; |
| 6698 | goto out_free; |
| 6699 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6700 | |
| 6701 | /* ignore disabled channels */ |
| 6702 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6703 | continue; |
| 6704 | |
| 6705 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6706 | i++; |
| 6707 | } |
| 6708 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6709 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6710 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6711 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6712 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6713 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6714 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6715 | if (!wiphy->bands[band]) |
| 6716 | continue; |
| 6717 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6718 | struct ieee80211_channel *chan; |
| 6719 | |
| 6720 | chan = &wiphy->bands[band]->channels[j]; |
| 6721 | |
| 6722 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6723 | continue; |
| 6724 | |
| 6725 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6726 | i++; |
| 6727 | } |
| 6728 | } |
| 6729 | } |
| 6730 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6731 | if (!i) { |
| 6732 | err = -EINVAL; |
| 6733 | goto out_free; |
| 6734 | } |
| 6735 | |
| 6736 | request->n_channels = i; |
| 6737 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6738 | wdev_lock(wdev); |
| 6739 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 6740 | struct ieee80211_channel *chan; |
| 6741 | |
| 6742 | if (request->n_channels != 1) { |
| 6743 | wdev_unlock(wdev); |
| 6744 | err = -EBUSY; |
| 6745 | goto out_free; |
| 6746 | } |
| 6747 | |
| 6748 | chan = request->channels[0]; |
| 6749 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 6750 | wdev_unlock(wdev); |
| 6751 | err = -EBUSY; |
| 6752 | goto out_free; |
| 6753 | } |
| 6754 | } |
| 6755 | wdev_unlock(wdev); |
| 6756 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6757 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6758 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6759 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6760 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6761 | err = -EINVAL; |
| 6762 | goto out_free; |
| 6763 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6764 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6765 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6766 | i++; |
| 6767 | } |
| 6768 | } |
| 6769 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6770 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6771 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6772 | memcpy((void *)request->ie, |
| 6773 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6774 | request->ie_len); |
| 6775 | } |
| 6776 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6777 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6778 | if (wiphy->bands[i]) |
| 6779 | request->rates[i] = |
| 6780 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6781 | |
| 6782 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6783 | nla_for_each_nested(attr, |
| 6784 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6785 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6786 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6787 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6788 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6789 | err = -EINVAL; |
| 6790 | goto out_free; |
| 6791 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6792 | |
| 6793 | if (!wiphy->bands[band]) |
| 6794 | continue; |
| 6795 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6796 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6797 | nla_data(attr), |
| 6798 | nla_len(attr), |
| 6799 | &request->rates[band]); |
| 6800 | if (err) |
| 6801 | goto out_free; |
| 6802 | } |
| 6803 | } |
| 6804 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6805 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6806 | if (!wiphy_ext_feature_isset(wiphy, |
| 6807 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6808 | err = -EOPNOTSUPP; |
| 6809 | goto out_free; |
| 6810 | } |
| 6811 | |
| 6812 | request->duration = |
| 6813 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6814 | request->duration_mandatory = |
| 6815 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6816 | } |
| 6817 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6818 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6819 | request->flags = nla_get_u32( |
| 6820 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6821 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6822 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6823 | err = -EOPNOTSUPP; |
| 6824 | goto out_free; |
| 6825 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6826 | |
| 6827 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6828 | if (!(wiphy->features & |
| 6829 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6830 | err = -EOPNOTSUPP; |
| 6831 | goto out_free; |
| 6832 | } |
| 6833 | |
| 6834 | if (wdev->current_bss) { |
| 6835 | err = -EOPNOTSUPP; |
| 6836 | goto out_free; |
| 6837 | } |
| 6838 | |
| 6839 | err = nl80211_parse_random_mac(info->attrs, |
| 6840 | request->mac_addr, |
| 6841 | request->mac_addr_mask); |
| 6842 | if (err) |
| 6843 | goto out_free; |
| 6844 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6845 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6846 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6847 | request->no_cck = |
| 6848 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6849 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6850 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6851 | * BSSID to scan for. This was problematic because that same attribute |
| 6852 | * was already used for another purpose (local random MAC address). The |
| 6853 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6854 | * compatibility with older userspace components, also use the |
| 6855 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6856 | * the specific BSSID use case instead of the random MAC address |
| 6857 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6858 | */ |
| 6859 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6860 | memcpy(request->bssid, |
| 6861 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6862 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6863 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6864 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6865 | ETH_ALEN); |
| 6866 | else |
| 6867 | eth_broadcast_addr(request->bssid); |
| 6868 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6869 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6870 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6871 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6872 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6873 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6874 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6875 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6876 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6877 | nl80211_send_scan_start(rdev, wdev); |
| 6878 | if (wdev->netdev) |
| 6879 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6880 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6881 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6882 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6883 | kfree(request); |
| 6884 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6885 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6886 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6887 | return err; |
| 6888 | } |
| 6889 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6890 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6891 | { |
| 6892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6893 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6894 | |
| 6895 | if (!rdev->ops->abort_scan) |
| 6896 | return -EOPNOTSUPP; |
| 6897 | |
| 6898 | if (rdev->scan_msg) |
| 6899 | return 0; |
| 6900 | |
| 6901 | if (!rdev->scan_req) |
| 6902 | return -ENOENT; |
| 6903 | |
| 6904 | rdev_abort_scan(rdev, wdev); |
| 6905 | return 0; |
| 6906 | } |
| 6907 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6908 | static int |
| 6909 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6910 | struct cfg80211_sched_scan_request *request, |
| 6911 | struct nlattr **attrs) |
| 6912 | { |
| 6913 | int tmp, err, i = 0; |
| 6914 | struct nlattr *attr; |
| 6915 | |
| 6916 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6917 | u32 interval; |
| 6918 | |
| 6919 | /* |
| 6920 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 6921 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6922 | * case one scan plan will be set with the specified scan |
| 6923 | * interval and infinite number of iterations. |
| 6924 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6925 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6926 | if (!interval) |
| 6927 | return -EINVAL; |
| 6928 | |
| 6929 | request->scan_plans[0].interval = |
| 6930 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6931 | if (!request->scan_plans[0].interval) |
| 6932 | return -EINVAL; |
| 6933 | |
| 6934 | if (request->scan_plans[0].interval > |
| 6935 | wiphy->max_sched_scan_plan_interval) |
| 6936 | request->scan_plans[0].interval = |
| 6937 | wiphy->max_sched_scan_plan_interval; |
| 6938 | |
| 6939 | return 0; |
| 6940 | } |
| 6941 | |
| 6942 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6943 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6944 | |
| 6945 | if (WARN_ON(i >= n_plans)) |
| 6946 | return -EINVAL; |
| 6947 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6948 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 6949 | attr, nl80211_plan_policy, NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6950 | if (err) |
| 6951 | return err; |
| 6952 | |
| 6953 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6954 | return -EINVAL; |
| 6955 | |
| 6956 | request->scan_plans[i].interval = |
| 6957 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6958 | if (!request->scan_plans[i].interval || |
| 6959 | request->scan_plans[i].interval > |
| 6960 | wiphy->max_sched_scan_plan_interval) |
| 6961 | return -EINVAL; |
| 6962 | |
| 6963 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6964 | request->scan_plans[i].iterations = |
| 6965 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6966 | if (!request->scan_plans[i].iterations || |
| 6967 | (request->scan_plans[i].iterations > |
| 6968 | wiphy->max_sched_scan_plan_iterations)) |
| 6969 | return -EINVAL; |
| 6970 | } else if (i < n_plans - 1) { |
| 6971 | /* |
| 6972 | * All scan plans but the last one must specify |
| 6973 | * a finite number of iterations |
| 6974 | */ |
| 6975 | return -EINVAL; |
| 6976 | } |
| 6977 | |
| 6978 | i++; |
| 6979 | } |
| 6980 | |
| 6981 | /* |
| 6982 | * The last scan plan must not specify the number of |
| 6983 | * iterations, it is supposed to run infinitely |
| 6984 | */ |
| 6985 | if (request->scan_plans[n_plans - 1].iterations) |
| 6986 | return -EINVAL; |
| 6987 | |
| 6988 | return 0; |
| 6989 | } |
| 6990 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6991 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6992 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 6993 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6994 | { |
| 6995 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6996 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6997 | 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] | 6998 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6999 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7000 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7001 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7002 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7003 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 7004 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7005 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7006 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7007 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7008 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7009 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7010 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7011 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7012 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7013 | } |
| 7014 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7015 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7016 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7017 | tmp) |
| 7018 | n_ssids++; |
| 7019 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7020 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7021 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7022 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7023 | /* |
| 7024 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7025 | * the old implementation, matchsets containing only the RSSI attribute |
| 7026 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7027 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7028 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7029 | * older userspace that treated a matchset with only the RSSI as the |
| 7030 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7031 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7032 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7033 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7034 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7035 | tmp) { |
| 7036 | struct nlattr *rssi; |
| 7037 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7038 | err = nla_parse_nested(tb, |
| 7039 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7040 | attr, nl80211_match_policy, |
| 7041 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7042 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7043 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7044 | |
| 7045 | /* SSID and BSSID are mutually exclusive */ |
| 7046 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 7047 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 7048 | return ERR_PTR(-EINVAL); |
| 7049 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7050 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7051 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 7052 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7053 | n_match_sets++; |
| 7054 | continue; |
| 7055 | } |
| 7056 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7057 | if (rssi) |
| 7058 | default_match_rssi = nla_get_s32(rssi); |
| 7059 | } |
| 7060 | } |
| 7061 | |
| 7062 | /* However, if there's no other matchset, add the RSSI one */ |
| 7063 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7064 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7065 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7066 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7067 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7068 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7069 | if (attrs[NL80211_ATTR_IE]) |
| 7070 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7071 | else |
| 7072 | ie_len = 0; |
| 7073 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7074 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7075 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7076 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7077 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7078 | /* |
| 7079 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7080 | * each scan plan already specifies its own interval |
| 7081 | */ |
| 7082 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7083 | return ERR_PTR(-EINVAL); |
| 7084 | |
| 7085 | nla_for_each_nested(attr, |
| 7086 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7087 | n_plans++; |
| 7088 | } else { |
| 7089 | /* |
| 7090 | * The scan interval attribute is kept for backward |
| 7091 | * compatibility. If no scan plans are specified and sched scan |
| 7092 | * interval is specified, one scan plan will be set with this |
| 7093 | * scan interval and infinite number of iterations. |
| 7094 | */ |
| 7095 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7096 | return ERR_PTR(-EINVAL); |
| 7097 | |
| 7098 | n_plans = 1; |
| 7099 | } |
| 7100 | |
| 7101 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7102 | return ERR_PTR(-EINVAL); |
| 7103 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7104 | if (!wiphy_ext_feature_isset( |
| 7105 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7106 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7107 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7108 | return ERR_PTR(-EINVAL); |
| 7109 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7110 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7111 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7112 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7113 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7114 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7115 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7116 | if (!request) |
| 7117 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7118 | |
| 7119 | if (n_ssids) |
| 7120 | request->ssids = (void *)&request->channels[n_channels]; |
| 7121 | request->n_ssids = n_ssids; |
| 7122 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7123 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7124 | request->ie = (void *)(request->ssids + n_ssids); |
| 7125 | else |
| 7126 | request->ie = (void *)(request->channels + n_channels); |
| 7127 | } |
| 7128 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7129 | if (n_match_sets) { |
| 7130 | if (request->ie) |
| 7131 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7132 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7133 | request->match_sets = |
| 7134 | (void *)(request->ssids + n_ssids); |
| 7135 | else |
| 7136 | request->match_sets = |
| 7137 | (void *)(request->channels + n_channels); |
| 7138 | } |
| 7139 | request->n_match_sets = n_match_sets; |
| 7140 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7141 | if (n_match_sets) |
| 7142 | request->scan_plans = (void *)(request->match_sets + |
| 7143 | n_match_sets); |
| 7144 | else if (request->ie) |
| 7145 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7146 | else if (n_ssids) |
| 7147 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7148 | else |
| 7149 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7150 | |
| 7151 | request->n_scan_plans = n_plans; |
| 7152 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7153 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7154 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7155 | /* user specified, bail out if channel not found */ |
| 7156 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7157 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7158 | tmp) { |
| 7159 | struct ieee80211_channel *chan; |
| 7160 | |
| 7161 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7162 | |
| 7163 | if (!chan) { |
| 7164 | err = -EINVAL; |
| 7165 | goto out_free; |
| 7166 | } |
| 7167 | |
| 7168 | /* ignore disabled channels */ |
| 7169 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7170 | continue; |
| 7171 | |
| 7172 | request->channels[i] = chan; |
| 7173 | i++; |
| 7174 | } |
| 7175 | } else { |
| 7176 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7177 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7178 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7179 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7180 | if (!wiphy->bands[band]) |
| 7181 | continue; |
| 7182 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7183 | struct ieee80211_channel *chan; |
| 7184 | |
| 7185 | chan = &wiphy->bands[band]->channels[j]; |
| 7186 | |
| 7187 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7188 | continue; |
| 7189 | |
| 7190 | request->channels[i] = chan; |
| 7191 | i++; |
| 7192 | } |
| 7193 | } |
| 7194 | } |
| 7195 | |
| 7196 | if (!i) { |
| 7197 | err = -EINVAL; |
| 7198 | goto out_free; |
| 7199 | } |
| 7200 | |
| 7201 | request->n_channels = i; |
| 7202 | |
| 7203 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7204 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7205 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7206 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7207 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7208 | err = -EINVAL; |
| 7209 | goto out_free; |
| 7210 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7211 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7212 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7213 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7214 | i++; |
| 7215 | } |
| 7216 | } |
| 7217 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7218 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7219 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7220 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7221 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7222 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7223 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7224 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7225 | err = nla_parse_nested(tb, |
| 7226 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7227 | attr, nl80211_match_policy, |
| 7228 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7229 | if (err) |
| 7230 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7231 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7232 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| 7233 | if (ssid || bssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7234 | if (WARN_ON(i >= n_match_sets)) { |
| 7235 | /* this indicates a programming error, |
| 7236 | * the loop above should have verified |
| 7237 | * things properly |
| 7238 | */ |
| 7239 | err = -EINVAL; |
| 7240 | goto out_free; |
| 7241 | } |
| 7242 | |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7243 | if (ssid) { |
| 7244 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7245 | err = -EINVAL; |
| 7246 | goto out_free; |
| 7247 | } |
| 7248 | memcpy(request->match_sets[i].ssid.ssid, |
| 7249 | nla_data(ssid), nla_len(ssid)); |
| 7250 | request->match_sets[i].ssid.ssid_len = |
| 7251 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7252 | } |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7253 | if (bssid) { |
| 7254 | if (nla_len(bssid) != ETH_ALEN) { |
| 7255 | err = -EINVAL; |
| 7256 | goto out_free; |
| 7257 | } |
| 7258 | memcpy(request->match_sets[i].bssid, |
| 7259 | nla_data(bssid), ETH_ALEN); |
| 7260 | } |
| 7261 | |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7262 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7263 | request->match_sets[i].rssi_thold = |
| 7264 | default_match_rssi; |
| 7265 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7266 | if (rssi) |
| 7267 | request->match_sets[i].rssi_thold = |
| 7268 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7269 | } |
| 7270 | i++; |
| 7271 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7272 | |
| 7273 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7274 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7275 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7276 | |
| 7277 | request->min_rssi_thold = INT_MAX; |
| 7278 | for (i = 0; i < n_match_sets; i++) |
| 7279 | request->min_rssi_thold = |
| 7280 | min(request->match_sets[i].rssi_thold, |
| 7281 | request->min_rssi_thold); |
| 7282 | } else { |
| 7283 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7284 | } |
| 7285 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7286 | if (ie_len) { |
| 7287 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7288 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7289 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7290 | request->ie_len); |
| 7291 | } |
| 7292 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7293 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7294 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7295 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 7296 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7297 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7298 | err = -EOPNOTSUPP; |
| 7299 | goto out_free; |
| 7300 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7301 | |
| 7302 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7303 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 7304 | |
| 7305 | if (!wdev) /* must be net-detect */ |
| 7306 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7307 | |
| 7308 | if (!(wiphy->features & flg)) { |
| 7309 | err = -EOPNOTSUPP; |
| 7310 | goto out_free; |
| 7311 | } |
| 7312 | |
| 7313 | if (wdev && wdev->current_bss) { |
| 7314 | err = -EOPNOTSUPP; |
| 7315 | goto out_free; |
| 7316 | } |
| 7317 | |
| 7318 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 7319 | request->mac_addr_mask); |
| 7320 | if (err) |
| 7321 | goto out_free; |
| 7322 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7323 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7324 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7325 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7326 | request->delay = |
| 7327 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7328 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7329 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7330 | request->relative_rssi = nla_get_s8( |
| 7331 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7332 | request->relative_rssi_set = true; |
| 7333 | } |
| 7334 | |
| 7335 | if (request->relative_rssi_set && |
| 7336 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7337 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7338 | |
| 7339 | rssi_adjust = nla_data( |
| 7340 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7341 | request->rssi_adjust.band = rssi_adjust->band; |
| 7342 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7343 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7344 | err = -EINVAL; |
| 7345 | goto out_free; |
| 7346 | } |
| 7347 | } |
| 7348 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7349 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7350 | if (err) |
| 7351 | goto out_free; |
| 7352 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7353 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7354 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7355 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7356 | |
| 7357 | out_free: |
| 7358 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7359 | return ERR_PTR(err); |
| 7360 | } |
| 7361 | |
| 7362 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7363 | struct genl_info *info) |
| 7364 | { |
| 7365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7366 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7367 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7368 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7369 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7370 | int err; |
| 7371 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7372 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7373 | return -EOPNOTSUPP; |
| 7374 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7375 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 7376 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 7377 | if (err) |
| 7378 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7379 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7380 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7381 | info->attrs, |
| 7382 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7383 | |
| 7384 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7385 | if (err) |
| 7386 | goto out_err; |
| 7387 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7388 | /* leave request id zero for legacy request |
| 7389 | * or if driver does not support multi-scheduled scan |
| 7390 | */ |
| 7391 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { |
| 7392 | while (!sched_scan_req->reqid) |
| 7393 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; |
| 7394 | } |
| 7395 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7396 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7397 | if (err) |
| 7398 | goto out_free; |
| 7399 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7400 | sched_scan_req->dev = dev; |
| 7401 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7402 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7403 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7404 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7405 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7406 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7407 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7408 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7409 | return 0; |
| 7410 | |
| 7411 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7412 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7413 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7414 | return err; |
| 7415 | } |
| 7416 | |
| 7417 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7418 | struct genl_info *info) |
| 7419 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7420 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7422 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7423 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7424 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7425 | return -EOPNOTSUPP; |
| 7426 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7427 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 7428 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7429 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 7430 | } |
| 7431 | |
| 7432 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 7433 | struct cfg80211_sched_scan_request, |
| 7434 | list); |
| 7435 | if (!req || req->reqid || |
| 7436 | (req->owner_nlportid && |
| 7437 | req->owner_nlportid != info->snd_portid)) |
| 7438 | return -ENOENT; |
| 7439 | |
| 7440 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7441 | } |
| 7442 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7443 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7444 | struct genl_info *info) |
| 7445 | { |
| 7446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7447 | struct net_device *dev = info->user_ptr[1]; |
| 7448 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7449 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7450 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7451 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7452 | int err; |
| 7453 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7454 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7455 | if (dfs_region == NL80211_DFS_UNSET) |
| 7456 | return -EINVAL; |
| 7457 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7458 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7459 | if (err) |
| 7460 | return err; |
| 7461 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7462 | if (netif_carrier_ok(dev)) |
| 7463 | return -EBUSY; |
| 7464 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7465 | if (wdev->cac_started) |
| 7466 | return -EBUSY; |
| 7467 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7468 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7469 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7470 | if (err < 0) |
| 7471 | return err; |
| 7472 | |
| 7473 | if (err == 0) |
| 7474 | return -EINVAL; |
| 7475 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7476 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7477 | return -EINVAL; |
| 7478 | |
| 7479 | if (!rdev->ops->start_radar_detection) |
| 7480 | return -EOPNOTSUPP; |
| 7481 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7482 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7483 | if (WARN_ON(!cac_time_ms)) |
| 7484 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7485 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7486 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7487 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7488 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7489 | wdev->cac_started = true; |
| 7490 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7491 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7492 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7493 | return err; |
| 7494 | } |
| 7495 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7496 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7497 | { |
| 7498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7499 | struct net_device *dev = info->user_ptr[1]; |
| 7500 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7501 | struct cfg80211_csa_settings params; |
| 7502 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7503 | * function is called under RTNL lock, so this should not be a problem. |
| 7504 | */ |
| 7505 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7506 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7507 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7508 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7509 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7510 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7511 | |
| 7512 | if (!rdev->ops->channel_switch || |
| 7513 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7514 | return -EOPNOTSUPP; |
| 7515 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7516 | switch (dev->ieee80211_ptr->iftype) { |
| 7517 | case NL80211_IFTYPE_AP: |
| 7518 | case NL80211_IFTYPE_P2P_GO: |
| 7519 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7520 | /* For all modes except AP the handle_dfs flag needs to be |
| 7521 | * supplied to tell the kernel that userspace will handle radar |
| 7522 | * events when they happen. Otherwise a switch to a channel |
| 7523 | * requiring DFS will be rejected. |
| 7524 | */ |
| 7525 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7526 | |
| 7527 | /* useless if AP is not running */ |
| 7528 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7529 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7530 | break; |
| 7531 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7532 | if (!wdev->ssid_len) |
| 7533 | return -ENOTCONN; |
| 7534 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7535 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7536 | if (!wdev->mesh_id_len) |
| 7537 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7538 | break; |
| 7539 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7540 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7541 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7542 | |
| 7543 | memset(¶ms, 0, sizeof(params)); |
| 7544 | |
| 7545 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7546 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7547 | return -EINVAL; |
| 7548 | |
| 7549 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7550 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7551 | return -EINVAL; |
| 7552 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7553 | /* Even though the attribute is u32, the specification says |
| 7554 | * u8, so let's make sure we don't overflow. |
| 7555 | */ |
| 7556 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7557 | if (cs_count > 255) |
| 7558 | return -EINVAL; |
| 7559 | |
| 7560 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7561 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7562 | if (!need_new_beacon) |
| 7563 | goto skip_beacons; |
| 7564 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7565 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7566 | if (err) |
| 7567 | return err; |
| 7568 | |
| 7569 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7570 | info->attrs[NL80211_ATTR_CSA_IES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 7571 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7572 | if (err) |
| 7573 | return err; |
| 7574 | |
| 7575 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7576 | if (err) |
| 7577 | return err; |
| 7578 | |
| 7579 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7580 | return -EINVAL; |
| 7581 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7582 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7583 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7584 | return -EINVAL; |
| 7585 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7586 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7587 | if (rdev->wiphy.max_num_csa_counters && |
| 7588 | (params.n_counter_offsets_beacon > |
| 7589 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7590 | return -EINVAL; |
| 7591 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7592 | params.counter_offsets_beacon = |
| 7593 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7594 | |
| 7595 | /* sanity checks - counters should fit and be the same */ |
| 7596 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7597 | u16 offset = params.counter_offsets_beacon[i]; |
| 7598 | |
| 7599 | if (offset >= params.beacon_csa.tail_len) |
| 7600 | return -EINVAL; |
| 7601 | |
| 7602 | if (params.beacon_csa.tail[offset] != params.count) |
| 7603 | return -EINVAL; |
| 7604 | } |
| 7605 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7606 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7607 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7608 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7609 | return -EINVAL; |
| 7610 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7611 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7612 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7613 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7614 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7615 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7616 | |
| 7617 | params.counter_offsets_presp = |
| 7618 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7619 | |
| 7620 | /* sanity checks - counters should fit and be the same */ |
| 7621 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7622 | u16 offset = params.counter_offsets_presp[i]; |
| 7623 | |
| 7624 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7625 | return -EINVAL; |
| 7626 | |
| 7627 | if (params.beacon_csa.probe_resp[offset] != |
| 7628 | params.count) |
| 7629 | return -EINVAL; |
| 7630 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7631 | } |
| 7632 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7633 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7634 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7635 | if (err) |
| 7636 | return err; |
| 7637 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7638 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7639 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7640 | return -EINVAL; |
| 7641 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7642 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7643 | ¶ms.chandef, |
| 7644 | wdev->iftype); |
| 7645 | if (err < 0) |
| 7646 | return err; |
| 7647 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7648 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7649 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7650 | if (need_handle_dfs_flag && |
| 7651 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 7652 | return -EINVAL; |
| 7653 | } |
| 7654 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7655 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7656 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7657 | params.block_tx = true; |
| 7658 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7659 | wdev_lock(wdev); |
| 7660 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7661 | wdev_unlock(wdev); |
| 7662 | |
| 7663 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7664 | } |
| 7665 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7666 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7667 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7668 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7669 | struct wireless_dev *wdev, |
| 7670 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7671 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7672 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7673 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7674 | void *hdr; |
| 7675 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7676 | |
| 7677 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7678 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7679 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7680 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7681 | if (!hdr) |
| 7682 | return -1; |
| 7683 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7684 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7685 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7686 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7687 | goto nla_put_failure; |
| 7688 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7689 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7690 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7691 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7692 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7693 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7694 | |
| 7695 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7696 | if (!bss) |
| 7697 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7698 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7699 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7700 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7701 | |
| 7702 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7703 | /* indicate whether we have probe response data or not */ |
| 7704 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7705 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7706 | goto fail_unlock_rcu; |
| 7707 | |
| 7708 | /* this pointer prefers to be pointed to probe response data |
| 7709 | * but is always valid |
| 7710 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7711 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7712 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7713 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7714 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7715 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7716 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7717 | ies->len, ies->data)) |
| 7718 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7719 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7720 | |
| 7721 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7722 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7723 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7724 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7725 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7726 | goto fail_unlock_rcu; |
| 7727 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7728 | ies->len, ies->data)) |
| 7729 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7730 | } |
| 7731 | rcu_read_unlock(); |
| 7732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7733 | if (res->beacon_interval && |
| 7734 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7735 | goto nla_put_failure; |
| 7736 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7737 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7738 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7739 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7740 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7741 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7742 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7743 | if (intbss->parent_tsf && |
| 7744 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7745 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7746 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7747 | intbss->parent_bssid))) |
| 7748 | goto nla_put_failure; |
| 7749 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7750 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7751 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7752 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7753 | goto nla_put_failure; |
| 7754 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7755 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7756 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7757 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7758 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7759 | break; |
| 7760 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7761 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7762 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7763 | break; |
| 7764 | default: |
| 7765 | break; |
| 7766 | } |
| 7767 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7768 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7769 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7770 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7771 | if (intbss == wdev->current_bss && |
| 7772 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7773 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7774 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7775 | break; |
| 7776 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7777 | if (intbss == wdev->current_bss && |
| 7778 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7779 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7780 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7781 | break; |
| 7782 | default: |
| 7783 | break; |
| 7784 | } |
| 7785 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7786 | nla_nest_end(msg, bss); |
| 7787 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7788 | genlmsg_end(msg, hdr); |
| 7789 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7790 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7791 | fail_unlock_rcu: |
| 7792 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7793 | nla_put_failure: |
| 7794 | genlmsg_cancel(msg, hdr); |
| 7795 | return -EMSGSIZE; |
| 7796 | } |
| 7797 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7798 | 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] | 7799 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7800 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7801 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7802 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7803 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7804 | int err; |
| 7805 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7806 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7807 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7808 | if (err) { |
| 7809 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7810 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7811 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7812 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7813 | wdev_lock(wdev); |
| 7814 | spin_lock_bh(&rdev->bss_lock); |
| 7815 | cfg80211_bss_expire(rdev); |
| 7816 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7817 | cb->seq = rdev->bss_generation; |
| 7818 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7819 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7820 | if (++idx <= start) |
| 7821 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7822 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7823 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7824 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7825 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7826 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7827 | } |
| 7828 | } |
| 7829 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7830 | spin_unlock_bh(&rdev->bss_lock); |
| 7831 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7832 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7833 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7834 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7835 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7836 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7837 | } |
| 7838 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7839 | 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] | 7840 | int flags, struct net_device *dev, |
| 7841 | bool allow_radio_stats, |
| 7842 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7843 | { |
| 7844 | void *hdr; |
| 7845 | struct nlattr *infoattr; |
| 7846 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7847 | /* skip radio stats if userspace didn't request them */ |
| 7848 | if (!survey->channel && !allow_radio_stats) |
| 7849 | return 0; |
| 7850 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7851 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7852 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7853 | if (!hdr) |
| 7854 | return -ENOMEM; |
| 7855 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7856 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7857 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7858 | |
| 7859 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7860 | if (!infoattr) |
| 7861 | goto nla_put_failure; |
| 7862 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7863 | if (survey->channel && |
| 7864 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7865 | survey->channel->center_freq)) |
| 7866 | goto nla_put_failure; |
| 7867 | |
| 7868 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7869 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7870 | goto nla_put_failure; |
| 7871 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7872 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7873 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7874 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7875 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7876 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7877 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7878 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7879 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7880 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7881 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7882 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7883 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7884 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7885 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7886 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7887 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7888 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7889 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7890 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7891 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7892 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7893 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7894 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7895 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7896 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7897 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7898 | |
| 7899 | nla_nest_end(msg, infoattr); |
| 7900 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7901 | genlmsg_end(msg, hdr); |
| 7902 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7903 | |
| 7904 | nla_put_failure: |
| 7905 | genlmsg_cancel(msg, hdr); |
| 7906 | return -EMSGSIZE; |
| 7907 | } |
| 7908 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7909 | 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] | 7910 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7911 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7912 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7913 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7914 | struct wireless_dev *wdev; |
| 7915 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7916 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7917 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7918 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7919 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7920 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7921 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7922 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7923 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7924 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7925 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7926 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7927 | if (!wdev->netdev) { |
| 7928 | res = -EINVAL; |
| 7929 | goto out_err; |
| 7930 | } |
| 7931 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7932 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7933 | res = -EOPNOTSUPP; |
| 7934 | goto out_err; |
| 7935 | } |
| 7936 | |
| 7937 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7938 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7939 | if (res == -ENOENT) |
| 7940 | break; |
| 7941 | if (res) |
| 7942 | goto out_err; |
| 7943 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7944 | /* don't send disabled channels, but do send non-channel data */ |
| 7945 | if (survey.channel && |
| 7946 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7947 | survey_idx++; |
| 7948 | continue; |
| 7949 | } |
| 7950 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7951 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7952 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7953 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7954 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7955 | goto out; |
| 7956 | survey_idx++; |
| 7957 | } |
| 7958 | |
| 7959 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7960 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7961 | res = skb->len; |
| 7962 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7963 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7964 | return res; |
| 7965 | } |
| 7966 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7967 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7968 | { |
| 7969 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7970 | NL80211_WPA_VERSION_2)); |
| 7971 | } |
| 7972 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7973 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7974 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7976 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7977 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7978 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 7979 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7980 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7981 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7982 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7983 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7984 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7985 | return -EINVAL; |
| 7986 | |
| 7987 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7988 | return -EINVAL; |
| 7989 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7990 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7991 | return -EINVAL; |
| 7992 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7993 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7994 | return -EINVAL; |
| 7995 | |
| 7996 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7997 | return -EINVAL; |
| 7998 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7999 | err = nl80211_parse_key(info, &key); |
| 8000 | if (err) |
| 8001 | return err; |
| 8002 | |
| 8003 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 8004 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 8005 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8006 | if (!key.p.key || !key.p.key_len) |
| 8007 | return -EINVAL; |
| 8008 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 8009 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 8010 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 8011 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 8012 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 8013 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8014 | return -EINVAL; |
| 8015 | } else { |
| 8016 | key.p.key_len = 0; |
| 8017 | key.p.key = NULL; |
| 8018 | } |
| 8019 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8020 | if (key.idx >= 0) { |
| 8021 | int i; |
| 8022 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8023 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8024 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 8025 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 8026 | ok = true; |
| 8027 | break; |
| 8028 | } |
| 8029 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8030 | if (!ok) |
| 8031 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8032 | } |
| 8033 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8034 | if (!rdev->ops->auth) |
| 8035 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8036 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8037 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8038 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8039 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8040 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8041 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8042 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8043 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8044 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8045 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8046 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8047 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8048 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8049 | |
| 8050 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8051 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8052 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8053 | } |
| 8054 | |
| 8055 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8056 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8057 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8058 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8059 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 8060 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 8061 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 8062 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8063 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8064 | return -EINVAL; |
| 8065 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8066 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8067 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8068 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8069 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8070 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8071 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8072 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8073 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8074 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8075 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8076 | return -EINVAL; |
| 8077 | } |
| 8078 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8079 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8080 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8081 | /* |
| 8082 | * Since we no longer track auth state, ignore |
| 8083 | * requests to only change local state. |
| 8084 | */ |
| 8085 | if (local_state_change) |
| 8086 | return 0; |
| 8087 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8088 | wdev_lock(dev->ieee80211_ptr); |
| 8089 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8090 | ssid, ssid_len, ie, ie_len, |
| 8091 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8092 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8093 | wdev_unlock(dev->ieee80211_ptr); |
| 8094 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8095 | } |
| 8096 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8097 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8098 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8099 | struct cfg80211_crypto_settings *settings, |
| 8100 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8101 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8102 | memset(settings, 0, sizeof(*settings)); |
| 8103 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8104 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8105 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8106 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8107 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8108 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8109 | proto = nla_get_u16( |
| 8110 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8111 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8112 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8113 | proto != ETH_P_PAE) |
| 8114 | return -EINVAL; |
| 8115 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8116 | settings->control_port_no_encrypt = true; |
| 8117 | } else |
| 8118 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8119 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8120 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8121 | void *data; |
| 8122 | int len, i; |
| 8123 | |
| 8124 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8125 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8126 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8127 | |
| 8128 | if (len % sizeof(u32)) |
| 8129 | return -EINVAL; |
| 8130 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8131 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8132 | return -EINVAL; |
| 8133 | |
| 8134 | memcpy(settings->ciphers_pairwise, data, len); |
| 8135 | |
| 8136 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8137 | if (!cfg80211_supported_cipher_suite( |
| 8138 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8139 | settings->ciphers_pairwise[i])) |
| 8140 | return -EINVAL; |
| 8141 | } |
| 8142 | |
| 8143 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8144 | settings->cipher_group = |
| 8145 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8146 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8147 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8148 | return -EINVAL; |
| 8149 | } |
| 8150 | |
| 8151 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8152 | settings->wpa_versions = |
| 8153 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8154 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8155 | return -EINVAL; |
| 8156 | } |
| 8157 | |
| 8158 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8159 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8160 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8161 | |
| 8162 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8163 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8164 | settings->n_akm_suites = len / sizeof(u32); |
| 8165 | |
| 8166 | if (len % sizeof(u32)) |
| 8167 | return -EINVAL; |
| 8168 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8169 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8170 | return -EINVAL; |
| 8171 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8172 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8173 | } |
| 8174 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 8175 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 8176 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 8177 | return -EINVAL; |
| 8178 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8179 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 8180 | return -EINVAL; |
| 8181 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 8182 | } |
| 8183 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8184 | return 0; |
| 8185 | } |
| 8186 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8187 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8188 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8190 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8191 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8192 | struct cfg80211_assoc_request req = {}; |
| 8193 | const u8 *bssid, *ssid; |
| 8194 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8195 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8196 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8197 | return -EINVAL; |
| 8198 | |
| 8199 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8200 | !info->attrs[NL80211_ATTR_SSID] || |
| 8201 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8202 | return -EINVAL; |
| 8203 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8204 | if (!rdev->ops->assoc) |
| 8205 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8206 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8207 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8208 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8209 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8210 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8211 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8212 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8213 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8214 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8215 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8216 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8217 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8218 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8219 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8220 | |
| 8221 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8222 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8223 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8224 | } |
| 8225 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8226 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8227 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8228 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8229 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8230 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8231 | else if (mfp != NL80211_MFP_NO) |
| 8232 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8233 | } |
| 8234 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8235 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8236 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8237 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8238 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8239 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8240 | |
| 8241 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8242 | memcpy(&req.ht_capa_mask, |
| 8243 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8244 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8245 | |
| 8246 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8247 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8248 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8249 | memcpy(&req.ht_capa, |
| 8250 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8251 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8252 | } |
| 8253 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8254 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8255 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8256 | |
| 8257 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8258 | memcpy(&req.vht_capa_mask, |
| 8259 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8260 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8261 | |
| 8262 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8263 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8264 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8265 | memcpy(&req.vht_capa, |
| 8266 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8267 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8268 | } |
| 8269 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8270 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8271 | if (!((rdev->wiphy.features & |
| 8272 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8273 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8274 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8275 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8276 | return -EINVAL; |
| 8277 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8278 | } |
| 8279 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8280 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8281 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8282 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8283 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8284 | return -EINVAL; |
| 8285 | req.fils_nonces = |
| 8286 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8287 | } |
| 8288 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8289 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8290 | if (!err) { |
| 8291 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8292 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8293 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8294 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8295 | |
| 8296 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8297 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8298 | info->snd_portid; |
| 8299 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8300 | bssid, ETH_ALEN); |
| 8301 | } |
| 8302 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8303 | wdev_unlock(dev->ieee80211_ptr); |
| 8304 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8305 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8306 | return err; |
| 8307 | } |
| 8308 | |
| 8309 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8310 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8312 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8313 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8314 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8315 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8316 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8317 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8318 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8319 | return -EINVAL; |
| 8320 | |
| 8321 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8322 | return -EINVAL; |
| 8323 | |
| 8324 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8325 | return -EINVAL; |
| 8326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8327 | if (!rdev->ops->deauth) |
| 8328 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8329 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8330 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8331 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8332 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8333 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8334 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8335 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8336 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8337 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8338 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8339 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8340 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8341 | |
| 8342 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8343 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8344 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8345 | } |
| 8346 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8347 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8348 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8349 | wdev_lock(dev->ieee80211_ptr); |
| 8350 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8351 | local_state_change); |
| 8352 | wdev_unlock(dev->ieee80211_ptr); |
| 8353 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8354 | } |
| 8355 | |
| 8356 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8357 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8359 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8360 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8361 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8362 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8363 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8364 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8365 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8366 | return -EINVAL; |
| 8367 | |
| 8368 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8369 | return -EINVAL; |
| 8370 | |
| 8371 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8372 | return -EINVAL; |
| 8373 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8374 | if (!rdev->ops->disassoc) |
| 8375 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8376 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8377 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8378 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8379 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8380 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8381 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8382 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8383 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8384 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8385 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8386 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8387 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8388 | |
| 8389 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8390 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8391 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8392 | } |
| 8393 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8394 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8395 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8396 | wdev_lock(dev->ieee80211_ptr); |
| 8397 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8398 | local_state_change); |
| 8399 | wdev_unlock(dev->ieee80211_ptr); |
| 8400 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8401 | } |
| 8402 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8403 | static bool |
| 8404 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8405 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8406 | int rateval) |
| 8407 | { |
| 8408 | struct wiphy *wiphy = &rdev->wiphy; |
| 8409 | bool found = false; |
| 8410 | int band, i; |
| 8411 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8412 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8413 | struct ieee80211_supported_band *sband; |
| 8414 | |
| 8415 | sband = wiphy->bands[band]; |
| 8416 | if (!sband) |
| 8417 | continue; |
| 8418 | |
| 8419 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8420 | if (sband->bitrates[i].bitrate == rateval) { |
| 8421 | mcast_rate[band] = i + 1; |
| 8422 | found = true; |
| 8423 | break; |
| 8424 | } |
| 8425 | } |
| 8426 | } |
| 8427 | |
| 8428 | return found; |
| 8429 | } |
| 8430 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8431 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8432 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8434 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8435 | struct cfg80211_ibss_params ibss; |
| 8436 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8437 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8438 | int err; |
| 8439 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8440 | memset(&ibss, 0, sizeof(ibss)); |
| 8441 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8442 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8443 | return -EINVAL; |
| 8444 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8445 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8446 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8447 | return -EINVAL; |
| 8448 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8449 | ibss.beacon_interval = 100; |
| 8450 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8451 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8452 | ibss.beacon_interval = |
| 8453 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8454 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8455 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8456 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8457 | if (err) |
| 8458 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8460 | if (!rdev->ops->join_ibss) |
| 8461 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8464 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8465 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8466 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8467 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8468 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8469 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8470 | |
| 8471 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8472 | return -EINVAL; |
| 8473 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8474 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8475 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8476 | |
| 8477 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8478 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8479 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8480 | } |
| 8481 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8482 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8483 | if (err) |
| 8484 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8485 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8486 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8487 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8488 | return -EINVAL; |
| 8489 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8490 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8491 | case NL80211_CHAN_WIDTH_5: |
| 8492 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8493 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8494 | break; |
| 8495 | case NL80211_CHAN_WIDTH_20: |
| 8496 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8497 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8498 | return -EINVAL; |
| 8499 | break; |
| 8500 | case NL80211_CHAN_WIDTH_80: |
| 8501 | case NL80211_CHAN_WIDTH_80P80: |
| 8502 | case NL80211_CHAN_WIDTH_160: |
| 8503 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8504 | return -EINVAL; |
| 8505 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8506 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8507 | return -EINVAL; |
| 8508 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8509 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8510 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8511 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8512 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8513 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8514 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8515 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8516 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8517 | u8 *rates = |
| 8518 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8519 | int n_rates = |
| 8520 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8521 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8522 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8523 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8524 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8525 | &ibss.basic_rates); |
| 8526 | if (err) |
| 8527 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8528 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8529 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8530 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8531 | memcpy(&ibss.ht_capa_mask, |
| 8532 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8533 | sizeof(ibss.ht_capa_mask)); |
| 8534 | |
| 8535 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8536 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8537 | return -EINVAL; |
| 8538 | memcpy(&ibss.ht_capa, |
| 8539 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8540 | sizeof(ibss.ht_capa)); |
| 8541 | } |
| 8542 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8543 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8544 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8545 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8546 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8547 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8548 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8549 | bool no_ht = false; |
| 8550 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8551 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8552 | info->attrs[NL80211_ATTR_KEYS], |
| 8553 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8554 | if (IS_ERR(connkeys)) |
| 8555 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8556 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8557 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8558 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8559 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8560 | return -EINVAL; |
| 8561 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8562 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8563 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8564 | ibss.control_port = |
| 8565 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8566 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8567 | ibss.userspace_handles_dfs = |
| 8568 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8570 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8571 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8572 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8573 | return err; |
| 8574 | } |
| 8575 | |
| 8576 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8579 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8581 | if (!rdev->ops->leave_ibss) |
| 8582 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8585 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8586 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8587 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8588 | } |
| 8589 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8590 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8591 | { |
| 8592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8593 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8594 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8595 | u32 nla_rate; |
| 8596 | int err; |
| 8597 | |
| 8598 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8599 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8600 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8601 | return -EOPNOTSUPP; |
| 8602 | |
| 8603 | if (!rdev->ops->set_mcast_rate) |
| 8604 | return -EOPNOTSUPP; |
| 8605 | |
| 8606 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8607 | |
| 8608 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8609 | return -EINVAL; |
| 8610 | |
| 8611 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8612 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8613 | return -EINVAL; |
| 8614 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8615 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8616 | |
| 8617 | return err; |
| 8618 | } |
| 8619 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8620 | static struct sk_buff * |
| 8621 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8622 | struct wireless_dev *wdev, int approxlen, |
| 8623 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8624 | enum nl80211_attrs attr, |
| 8625 | const struct nl80211_vendor_cmd_info *info, |
| 8626 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8627 | { |
| 8628 | struct sk_buff *skb; |
| 8629 | void *hdr; |
| 8630 | struct nlattr *data; |
| 8631 | |
| 8632 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8633 | if (!skb) |
| 8634 | return NULL; |
| 8635 | |
| 8636 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8637 | if (!hdr) { |
| 8638 | kfree_skb(skb); |
| 8639 | return NULL; |
| 8640 | } |
| 8641 | |
| 8642 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8643 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8644 | |
| 8645 | if (info) { |
| 8646 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8647 | info->vendor_id)) |
| 8648 | goto nla_put_failure; |
| 8649 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8650 | info->subcmd)) |
| 8651 | goto nla_put_failure; |
| 8652 | } |
| 8653 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8654 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8655 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8656 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8657 | goto nla_put_failure; |
| 8658 | if (wdev->netdev && |
| 8659 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8660 | wdev->netdev->ifindex)) |
| 8661 | goto nla_put_failure; |
| 8662 | } |
| 8663 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8664 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8665 | if (!data) |
| 8666 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8667 | |
| 8668 | ((void **)skb->cb)[0] = rdev; |
| 8669 | ((void **)skb->cb)[1] = hdr; |
| 8670 | ((void **)skb->cb)[2] = data; |
| 8671 | |
| 8672 | return skb; |
| 8673 | |
| 8674 | nla_put_failure: |
| 8675 | kfree_skb(skb); |
| 8676 | return NULL; |
| 8677 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8678 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8679 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8680 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8681 | enum nl80211_commands cmd, |
| 8682 | enum nl80211_attrs attr, |
| 8683 | int vendor_event_idx, |
| 8684 | int approxlen, gfp_t gfp) |
| 8685 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8686 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8687 | const struct nl80211_vendor_cmd_info *info; |
| 8688 | |
| 8689 | switch (cmd) { |
| 8690 | case NL80211_CMD_TESTMODE: |
| 8691 | if (WARN_ON(vendor_event_idx != -1)) |
| 8692 | return NULL; |
| 8693 | info = NULL; |
| 8694 | break; |
| 8695 | case NL80211_CMD_VENDOR: |
| 8696 | if (WARN_ON(vendor_event_idx < 0 || |
| 8697 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8698 | return NULL; |
| 8699 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8700 | break; |
| 8701 | default: |
| 8702 | WARN_ON(1); |
| 8703 | return NULL; |
| 8704 | } |
| 8705 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8706 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8707 | cmd, attr, info, gfp); |
| 8708 | } |
| 8709 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8710 | |
| 8711 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8712 | { |
| 8713 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8714 | void *hdr = ((void **)skb->cb)[1]; |
| 8715 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8716 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8717 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8718 | /* clear CB data for netlink core to own from now on */ |
| 8719 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8720 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8721 | nla_nest_end(skb, data); |
| 8722 | genlmsg_end(skb, hdr); |
| 8723 | |
| 8724 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8725 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8726 | |
| 8727 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8728 | mcgrp, gfp); |
| 8729 | } |
| 8730 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8731 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8732 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8733 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8734 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8736 | struct wireless_dev *wdev = |
| 8737 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8738 | int err; |
| 8739 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8740 | if (!rdev->ops->testmode_cmd) |
| 8741 | return -EOPNOTSUPP; |
| 8742 | |
| 8743 | if (IS_ERR(wdev)) { |
| 8744 | err = PTR_ERR(wdev); |
| 8745 | if (err != -EINVAL) |
| 8746 | return err; |
| 8747 | wdev = NULL; |
| 8748 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8749 | return -EINVAL; |
| 8750 | } |
| 8751 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8752 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8753 | return -EINVAL; |
| 8754 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8755 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8756 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8757 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8758 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8759 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8760 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8761 | return err; |
| 8762 | } |
| 8763 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8764 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8765 | struct netlink_callback *cb) |
| 8766 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8767 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8768 | int err; |
| 8769 | long phy_idx; |
| 8770 | void *data = NULL; |
| 8771 | int data_len = 0; |
| 8772 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8773 | rtnl_lock(); |
| 8774 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8775 | if (cb->args[0]) { |
| 8776 | /* |
| 8777 | * 0 is a valid index, but not valid for args[0], |
| 8778 | * so we need to offset by 1. |
| 8779 | */ |
| 8780 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 8781 | |
| 8782 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8783 | if (!rdev) { |
| 8784 | err = -ENOENT; |
| 8785 | goto out_err; |
| 8786 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8787 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8788 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 8789 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8790 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 8791 | attrbuf, nl80211_fam.maxattr, |
| 8792 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8793 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8794 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8795 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8796 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8797 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8798 | err = PTR_ERR(rdev); |
| 8799 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8800 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8801 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8802 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8803 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 8804 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | if (cb->args[1]) { |
| 8808 | data = nla_data((void *)cb->args[1]); |
| 8809 | data_len = nla_len((void *)cb->args[1]); |
| 8810 | } |
| 8811 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8812 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8813 | err = -EOPNOTSUPP; |
| 8814 | goto out_err; |
| 8815 | } |
| 8816 | |
| 8817 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8818 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8819 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8820 | NL80211_CMD_TESTMODE); |
| 8821 | struct nlattr *tmdata; |
| 8822 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8823 | if (!hdr) |
| 8824 | break; |
| 8825 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8826 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8827 | genlmsg_cancel(skb, hdr); |
| 8828 | break; |
| 8829 | } |
| 8830 | |
| 8831 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8832 | if (!tmdata) { |
| 8833 | genlmsg_cancel(skb, hdr); |
| 8834 | break; |
| 8835 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8836 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8837 | nla_nest_end(skb, tmdata); |
| 8838 | |
| 8839 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8840 | genlmsg_cancel(skb, hdr); |
| 8841 | break; |
| 8842 | } else if (err) { |
| 8843 | genlmsg_cancel(skb, hdr); |
| 8844 | goto out_err; |
| 8845 | } |
| 8846 | |
| 8847 | genlmsg_end(skb, hdr); |
| 8848 | } |
| 8849 | |
| 8850 | err = skb->len; |
| 8851 | /* see above */ |
| 8852 | cb->args[0] = phy_idx + 1; |
| 8853 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8854 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8855 | return err; |
| 8856 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8857 | #endif |
| 8858 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8859 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8860 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8862 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8863 | struct cfg80211_connect_params connect; |
| 8864 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8865 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8866 | int err; |
| 8867 | |
| 8868 | memset(&connect, 0, sizeof(connect)); |
| 8869 | |
| 8870 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8871 | return -EINVAL; |
| 8872 | |
| 8873 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8874 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8875 | return -EINVAL; |
| 8876 | |
| 8877 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8878 | connect.auth_type = |
| 8879 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8880 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8881 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8882 | return -EINVAL; |
| 8883 | } else |
| 8884 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8885 | |
| 8886 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8887 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 8888 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 8889 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8890 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 8891 | return -EINVAL; |
| 8892 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 8893 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8894 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8895 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8896 | if (err) |
| 8897 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8898 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8899 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8900 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8901 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8902 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8903 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8904 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8905 | connect.bg_scan_period = -1; |
| 8906 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8907 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8908 | connect.bg_scan_period = |
| 8909 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8910 | } |
| 8911 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8912 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8913 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8914 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8915 | connect.bssid_hint = |
| 8916 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8917 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8918 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8919 | |
| 8920 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8921 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8922 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8923 | } |
| 8924 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8925 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8926 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8927 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8928 | connect.mfp != NL80211_MFP_NO) |
| 8929 | return -EINVAL; |
| 8930 | } else { |
| 8931 | connect.mfp = NL80211_MFP_NO; |
| 8932 | } |
| 8933 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8934 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8935 | connect.prev_bssid = |
| 8936 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8937 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8938 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8939 | connect.channel = nl80211_get_valid_chan( |
| 8940 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8941 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8942 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8943 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8944 | connect.channel_hint = nl80211_get_valid_chan( |
| 8945 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8946 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8947 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8948 | } |
| 8949 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8950 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8951 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8952 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8953 | if (IS_ERR(connkeys)) |
| 8954 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8955 | } |
| 8956 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8957 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8958 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8959 | |
| 8960 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8961 | memcpy(&connect.ht_capa_mask, |
| 8962 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8963 | sizeof(connect.ht_capa_mask)); |
| 8964 | |
| 8965 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8966 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8967 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8968 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8969 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8970 | memcpy(&connect.ht_capa, |
| 8971 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8972 | sizeof(connect.ht_capa)); |
| 8973 | } |
| 8974 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8975 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8976 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8977 | |
| 8978 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8979 | memcpy(&connect.vht_capa_mask, |
| 8980 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8981 | sizeof(connect.vht_capa_mask)); |
| 8982 | |
| 8983 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8984 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8985 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8986 | return -EINVAL; |
| 8987 | } |
| 8988 | memcpy(&connect.vht_capa, |
| 8989 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8990 | sizeof(connect.vht_capa)); |
| 8991 | } |
| 8992 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8993 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8994 | if (!((rdev->wiphy.features & |
| 8995 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8996 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8997 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8998 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8999 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9000 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9001 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9002 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 9003 | } |
| 9004 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9005 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9006 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9007 | kzfree(connkeys); |
| 9008 | return -EOPNOTSUPP; |
| 9009 | } |
| 9010 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 9011 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 9012 | /* bss selection makes no sense if bssid is set */ |
| 9013 | if (connect.bssid) { |
| 9014 | kzfree(connkeys); |
| 9015 | return -EINVAL; |
| 9016 | } |
| 9017 | |
| 9018 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 9019 | wiphy, &connect.bss_select); |
| 9020 | if (err) { |
| 9021 | kzfree(connkeys); |
| 9022 | return err; |
| 9023 | } |
| 9024 | } |
| 9025 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9026 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 9027 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 9028 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9029 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9030 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9031 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9032 | connect.fils_erp_username = |
| 9033 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9034 | connect.fils_erp_username_len = |
| 9035 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9036 | connect.fils_erp_realm = |
| 9037 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9038 | connect.fils_erp_realm_len = |
| 9039 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9040 | connect.fils_erp_next_seq_num = |
| 9041 | nla_get_u16( |
| 9042 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9043 | connect.fils_erp_rrk = |
| 9044 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9045 | connect.fils_erp_rrk_len = |
| 9046 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9047 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9048 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9049 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9050 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9051 | kzfree(connkeys); |
| 9052 | return -EINVAL; |
| 9053 | } |
| 9054 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9055 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9056 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 9057 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 9058 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9059 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9060 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9061 | |
| 9062 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9063 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9064 | if (connect.bssid) |
| 9065 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9066 | connect.bssid, ETH_ALEN); |
| 9067 | else |
| 9068 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 9069 | 0, ETH_ALEN); |
| 9070 | } |
| 9071 | |
| 9072 | wdev_unlock(dev->ieee80211_ptr); |
| 9073 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9074 | return err; |
| 9075 | } |
| 9076 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9077 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 9078 | struct genl_info *info) |
| 9079 | { |
| 9080 | struct cfg80211_connect_params connect = {}; |
| 9081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9082 | struct net_device *dev = info->user_ptr[1]; |
| 9083 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9084 | u32 changed = 0; |
| 9085 | int ret; |
| 9086 | |
| 9087 | if (!rdev->ops->update_connect_params) |
| 9088 | return -EOPNOTSUPP; |
| 9089 | |
| 9090 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9091 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9092 | return -EINVAL; |
| 9093 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9094 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9095 | changed |= UPDATE_ASSOC_IES; |
| 9096 | } |
| 9097 | |
| 9098 | wdev_lock(dev->ieee80211_ptr); |
| 9099 | if (!wdev->current_bss) |
| 9100 | ret = -ENOLINK; |
| 9101 | else |
| 9102 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9103 | wdev_unlock(dev->ieee80211_ptr); |
| 9104 | |
| 9105 | return ret; |
| 9106 | } |
| 9107 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9108 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9109 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9111 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9112 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9113 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9114 | |
| 9115 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9116 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9117 | else |
| 9118 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9119 | |
| 9120 | if (reason == 0) |
| 9121 | return -EINVAL; |
| 9122 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9123 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9124 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9125 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9126 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9127 | wdev_lock(dev->ieee80211_ptr); |
| 9128 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9129 | wdev_unlock(dev->ieee80211_ptr); |
| 9130 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9131 | } |
| 9132 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9133 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9134 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9136 | struct net *net; |
| 9137 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9138 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9139 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9140 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9141 | |
| 9142 | net = get_net_ns_by_pid(pid); |
| 9143 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9144 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9145 | |
| 9146 | net = get_net_ns_by_fd(fd); |
| 9147 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9148 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9149 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9150 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9151 | if (IS_ERR(net)) |
| 9152 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9153 | |
| 9154 | err = 0; |
| 9155 | |
| 9156 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9157 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9158 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9159 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9160 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9161 | return err; |
| 9162 | } |
| 9163 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9164 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9167 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9168 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9169 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9170 | struct cfg80211_pmksa pmksa; |
| 9171 | |
| 9172 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9173 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9174 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9175 | return -EINVAL; |
| 9176 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9177 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9178 | |
| 9179 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9180 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9181 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9182 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9183 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9184 | info->attrs[NL80211_ATTR_PMK])) { |
| 9185 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9186 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9187 | pmksa.cache_id = |
| 9188 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9189 | } else { |
| 9190 | return -EINVAL; |
| 9191 | } |
| 9192 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9193 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9194 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9195 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9196 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9197 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9198 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9199 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9200 | |
| 9201 | switch (info->genlhdr->cmd) { |
| 9202 | case NL80211_CMD_SET_PMKSA: |
| 9203 | rdev_ops = rdev->ops->set_pmksa; |
| 9204 | break; |
| 9205 | case NL80211_CMD_DEL_PMKSA: |
| 9206 | rdev_ops = rdev->ops->del_pmksa; |
| 9207 | break; |
| 9208 | default: |
| 9209 | WARN_ON(1); |
| 9210 | break; |
| 9211 | } |
| 9212 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9213 | if (!rdev_ops) |
| 9214 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9215 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9216 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9220 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9222 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9223 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9224 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9225 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9226 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9227 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9228 | if (!rdev->ops->flush_pmksa) |
| 9229 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9230 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9231 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9232 | } |
| 9233 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9234 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9235 | { |
| 9236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9237 | struct net_device *dev = info->user_ptr[1]; |
| 9238 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9239 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9240 | u16 status_code; |
| 9241 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9242 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9243 | |
| 9244 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9245 | !rdev->ops->tdls_mgmt) |
| 9246 | return -EOPNOTSUPP; |
| 9247 | |
| 9248 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9249 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9250 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9251 | !info->attrs[NL80211_ATTR_IE] || |
| 9252 | !info->attrs[NL80211_ATTR_MAC]) |
| 9253 | return -EINVAL; |
| 9254 | |
| 9255 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9256 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9257 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9258 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9259 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9260 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9261 | peer_capability = |
| 9262 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9263 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9264 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9265 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9266 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9267 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9268 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9269 | } |
| 9270 | |
| 9271 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9272 | { |
| 9273 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9274 | struct net_device *dev = info->user_ptr[1]; |
| 9275 | enum nl80211_tdls_operation operation; |
| 9276 | u8 *peer; |
| 9277 | |
| 9278 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9279 | !rdev->ops->tdls_oper) |
| 9280 | return -EOPNOTSUPP; |
| 9281 | |
| 9282 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9283 | !info->attrs[NL80211_ATTR_MAC]) |
| 9284 | return -EINVAL; |
| 9285 | |
| 9286 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9287 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9288 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9289 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9290 | } |
| 9291 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9292 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9293 | struct genl_info *info) |
| 9294 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9296 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9297 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9298 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9299 | struct sk_buff *msg; |
| 9300 | void *hdr; |
| 9301 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9302 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9303 | int err; |
| 9304 | |
| 9305 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9306 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9307 | return -EINVAL; |
| 9308 | |
| 9309 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9310 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9311 | if (!rdev->ops->remain_on_channel || |
| 9312 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9313 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9314 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9315 | /* |
| 9316 | * We should be on that channel for at least a minimum amount of |
| 9317 | * time (10ms) but no longer than the driver supports. |
| 9318 | */ |
| 9319 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9320 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9321 | return -EINVAL; |
| 9322 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9323 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9324 | if (err) |
| 9325 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9326 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9327 | wdev_lock(wdev); |
| 9328 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 9329 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 9330 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 9331 | &chandef); |
| 9332 | if (compat_chandef != &chandef) { |
| 9333 | wdev_unlock(wdev); |
| 9334 | return -EBUSY; |
| 9335 | } |
| 9336 | } |
| 9337 | wdev_unlock(wdev); |
| 9338 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9339 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9340 | if (!msg) |
| 9341 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9342 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9343 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9344 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9345 | if (!hdr) { |
| 9346 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9347 | goto free_msg; |
| 9348 | } |
| 9349 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9350 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9351 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9352 | |
| 9353 | if (err) |
| 9354 | goto free_msg; |
| 9355 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9356 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9357 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9358 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9359 | |
| 9360 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9361 | |
| 9362 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9363 | |
| 9364 | nla_put_failure: |
| 9365 | err = -ENOBUFS; |
| 9366 | free_msg: |
| 9367 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9368 | return err; |
| 9369 | } |
| 9370 | |
| 9371 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9372 | struct genl_info *info) |
| 9373 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9375 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9376 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9377 | |
| 9378 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9379 | return -EINVAL; |
| 9380 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9381 | if (!rdev->ops->cancel_remain_on_channel) |
| 9382 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9383 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9384 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9385 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9386 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9387 | } |
| 9388 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9389 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9390 | struct genl_info *info) |
| 9391 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9392 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9394 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9395 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9396 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9397 | if (!rdev->ops->set_bitrate_mask) |
| 9398 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9399 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9400 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9401 | if (err) |
| 9402 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9403 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9404 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9405 | } |
| 9406 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9407 | 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] | 9408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9410 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9411 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9412 | |
| 9413 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9414 | return -EINVAL; |
| 9415 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9416 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9417 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9418 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9419 | switch (wdev->iftype) { |
| 9420 | case NL80211_IFTYPE_STATION: |
| 9421 | case NL80211_IFTYPE_ADHOC: |
| 9422 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9423 | case NL80211_IFTYPE_AP: |
| 9424 | case NL80211_IFTYPE_AP_VLAN: |
| 9425 | case NL80211_IFTYPE_MESH_POINT: |
| 9426 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9427 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9428 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9429 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9430 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9431 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9432 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9433 | |
| 9434 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9435 | if (!rdev->ops->mgmt_tx) |
| 9436 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9437 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9438 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9439 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9440 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9441 | } |
| 9442 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9443 | 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] | 9444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9446 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9447 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9448 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9449 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9450 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9451 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9452 | struct cfg80211_mgmt_tx_params params = { |
| 9453 | .dont_wait_for_ack = |
| 9454 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9455 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9456 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9457 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9458 | return -EINVAL; |
| 9459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9460 | if (!rdev->ops->mgmt_tx) |
| 9461 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9462 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9463 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9464 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9465 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9466 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9467 | case NL80211_IFTYPE_STATION: |
| 9468 | case NL80211_IFTYPE_ADHOC: |
| 9469 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9470 | case NL80211_IFTYPE_AP: |
| 9471 | case NL80211_IFTYPE_AP_VLAN: |
| 9472 | case NL80211_IFTYPE_MESH_POINT: |
| 9473 | case NL80211_IFTYPE_P2P_GO: |
| 9474 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9475 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9476 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9477 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9478 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9479 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9480 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9481 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9482 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9483 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9484 | |
| 9485 | /* |
| 9486 | * We should wait on the channel for at least a minimum amount |
| 9487 | * of time (10ms) but no longer than the driver supports. |
| 9488 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9489 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9490 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9491 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9492 | } |
| 9493 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9494 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9495 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9496 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9497 | return -EINVAL; |
| 9498 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9499 | 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] | 9500 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9501 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9502 | * the driver. The latter will use the current one |
| 9503 | */ |
| 9504 | chandef.chan = NULL; |
| 9505 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9506 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9507 | if (err) |
| 9508 | return err; |
| 9509 | } |
| 9510 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9511 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9512 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9513 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9514 | wdev_lock(wdev); |
| 9515 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 9516 | wdev_unlock(wdev); |
| 9517 | return -EBUSY; |
| 9518 | } |
| 9519 | wdev_unlock(wdev); |
| 9520 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9521 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9522 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9523 | |
| 9524 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9525 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9526 | int i; |
| 9527 | |
| 9528 | if (len % sizeof(u16)) |
| 9529 | return -EINVAL; |
| 9530 | |
| 9531 | params.n_csa_offsets = len / sizeof(u16); |
| 9532 | params.csa_offsets = |
| 9533 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9534 | |
| 9535 | /* check that all the offsets fit the frame */ |
| 9536 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9537 | if (params.csa_offsets[i] >= params.len) |
| 9538 | return -EINVAL; |
| 9539 | } |
| 9540 | } |
| 9541 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9542 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9543 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9544 | if (!msg) |
| 9545 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9546 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9547 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9548 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9549 | if (!hdr) { |
| 9550 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9551 | goto free_msg; |
| 9552 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9553 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9554 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9555 | params.chan = chandef.chan; |
| 9556 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9557 | if (err) |
| 9558 | goto free_msg; |
| 9559 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9560 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9561 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9562 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9563 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9564 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9565 | genlmsg_end(msg, hdr); |
| 9566 | return genlmsg_reply(msg, info); |
| 9567 | } |
| 9568 | |
| 9569 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9570 | |
| 9571 | nla_put_failure: |
| 9572 | err = -ENOBUFS; |
| 9573 | free_msg: |
| 9574 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9575 | return err; |
| 9576 | } |
| 9577 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9578 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9579 | { |
| 9580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9581 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9582 | u64 cookie; |
| 9583 | |
| 9584 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9585 | return -EINVAL; |
| 9586 | |
| 9587 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9588 | return -EOPNOTSUPP; |
| 9589 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9590 | switch (wdev->iftype) { |
| 9591 | case NL80211_IFTYPE_STATION: |
| 9592 | case NL80211_IFTYPE_ADHOC: |
| 9593 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9594 | case NL80211_IFTYPE_AP: |
| 9595 | case NL80211_IFTYPE_AP_VLAN: |
| 9596 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9597 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9598 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9599 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9600 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9601 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9602 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9603 | |
| 9604 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9605 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9606 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9607 | } |
| 9608 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9609 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9610 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9611 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9612 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9613 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9614 | u8 ps_state; |
| 9615 | bool state; |
| 9616 | int err; |
| 9617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9618 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9619 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9620 | |
| 9621 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9622 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9623 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9624 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9625 | |
| 9626 | wdev = dev->ieee80211_ptr; |
| 9627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9628 | if (!rdev->ops->set_power_mgmt) |
| 9629 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9630 | |
| 9631 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9632 | |
| 9633 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9634 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9635 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9636 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9637 | if (!err) |
| 9638 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9639 | return err; |
| 9640 | } |
| 9641 | |
| 9642 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9645 | enum nl80211_ps_state ps_state; |
| 9646 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9647 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9648 | struct sk_buff *msg; |
| 9649 | void *hdr; |
| 9650 | int err; |
| 9651 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9652 | wdev = dev->ieee80211_ptr; |
| 9653 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9654 | if (!rdev->ops->set_power_mgmt) |
| 9655 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9656 | |
| 9657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9658 | if (!msg) |
| 9659 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9660 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9661 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9662 | NL80211_CMD_GET_POWER_SAVE); |
| 9663 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9664 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9665 | goto free_msg; |
| 9666 | } |
| 9667 | |
| 9668 | if (wdev->ps) |
| 9669 | ps_state = NL80211_PS_ENABLED; |
| 9670 | else |
| 9671 | ps_state = NL80211_PS_DISABLED; |
| 9672 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9673 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9674 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9675 | |
| 9676 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9677 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9678 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9679 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9680 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9681 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9682 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9683 | return err; |
| 9684 | } |
| 9685 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9686 | static const struct nla_policy |
| 9687 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9688 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9689 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9690 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9691 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9692 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9693 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 9694 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9695 | }; |
| 9696 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9697 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9698 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9699 | { |
| 9700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9701 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9702 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9703 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9704 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9705 | return -EINVAL; |
| 9706 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9707 | if (!rdev->ops->set_cqm_txe_config) |
| 9708 | return -EOPNOTSUPP; |
| 9709 | |
| 9710 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9711 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9712 | return -EOPNOTSUPP; |
| 9713 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9714 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9715 | } |
| 9716 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9717 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 9718 | struct net_device *dev) |
| 9719 | { |
| 9720 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9721 | s32 last, low, high; |
| 9722 | u32 hyst; |
| 9723 | int i, n; |
| 9724 | int err; |
| 9725 | |
| 9726 | /* RSSI reporting disabled? */ |
| 9727 | if (!wdev->cqm_config) |
| 9728 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 9729 | |
| 9730 | /* |
| 9731 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 9732 | * event has been received yet, we should receive an event after a |
| 9733 | * connection is established and enough beacons received to calculate |
| 9734 | * the average. |
| 9735 | */ |
| 9736 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 9737 | rdev->ops->get_station) { |
| 9738 | struct station_info sinfo; |
| 9739 | u8 *mac_addr; |
| 9740 | |
| 9741 | mac_addr = wdev->current_bss->pub.bssid; |
| 9742 | |
| 9743 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 9744 | if (err) |
| 9745 | return err; |
| 9746 | |
| 9747 | if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
| 9748 | wdev->cqm_config->last_rssi_event_value = |
| 9749 | (s8) sinfo.rx_beacon_signal_avg; |
| 9750 | } |
| 9751 | |
| 9752 | last = wdev->cqm_config->last_rssi_event_value; |
| 9753 | hyst = wdev->cqm_config->rssi_hyst; |
| 9754 | n = wdev->cqm_config->n_rssi_thresholds; |
| 9755 | |
| 9756 | for (i = 0; i < n; i++) |
| 9757 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 9758 | break; |
| 9759 | |
| 9760 | low = i > 0 ? |
| 9761 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; |
| 9762 | high = i < n ? |
| 9763 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; |
| 9764 | |
| 9765 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 9766 | } |
| 9767 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9768 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9769 | const s32 *thresholds, int n_thresholds, |
| 9770 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9773 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9774 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9775 | int i, err; |
| 9776 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9777 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9778 | /* Check all values negative and sorted */ |
| 9779 | for (i = 0; i < n_thresholds; i++) { |
| 9780 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 9781 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9782 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9783 | prev = thresholds[i]; |
| 9784 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9785 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9786 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9787 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9788 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9789 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9790 | wdev_lock(wdev); |
| 9791 | cfg80211_cqm_config_free(wdev); |
| 9792 | wdev_unlock(wdev); |
| 9793 | |
| 9794 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 9795 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 9796 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 9797 | |
| 9798 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 9799 | thresholds[0], hysteresis); |
| 9800 | } |
| 9801 | |
| 9802 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9803 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 9804 | return -EOPNOTSUPP; |
| 9805 | |
| 9806 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 9807 | n_thresholds = 0; |
| 9808 | |
| 9809 | wdev_lock(wdev); |
| 9810 | if (n_thresholds) { |
| 9811 | struct cfg80211_cqm_config *cqm_config; |
| 9812 | |
| 9813 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 9814 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 9815 | if (!cqm_config) { |
| 9816 | err = -ENOMEM; |
| 9817 | goto unlock; |
| 9818 | } |
| 9819 | |
| 9820 | cqm_config->rssi_hyst = hysteresis; |
| 9821 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 9822 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 9823 | n_thresholds * sizeof(s32)); |
| 9824 | |
| 9825 | wdev->cqm_config = cqm_config; |
| 9826 | } |
| 9827 | |
| 9828 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 9829 | |
| 9830 | unlock: |
| 9831 | wdev_unlock(wdev); |
| 9832 | |
| 9833 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9837 | { |
| 9838 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9839 | struct nlattr *cqm; |
| 9840 | int err; |
| 9841 | |
| 9842 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9843 | if (!cqm) |
| 9844 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9845 | |
| 9846 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 9847 | nl80211_attr_cqm_policy, info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9848 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9849 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9850 | |
| 9851 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9852 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9853 | const s32 *thresholds = |
| 9854 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9855 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9856 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9857 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9858 | if (len % 4) |
| 9859 | return -EINVAL; |
| 9860 | |
| 9861 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 9862 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9863 | } |
| 9864 | |
| 9865 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9866 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9867 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9868 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9869 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9870 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9871 | |
| 9872 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9873 | } |
| 9874 | |
| 9875 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9876 | } |
| 9877 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9878 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9879 | { |
| 9880 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9881 | struct net_device *dev = info->user_ptr[1]; |
| 9882 | struct ocb_setup setup = {}; |
| 9883 | int err; |
| 9884 | |
| 9885 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9886 | if (err) |
| 9887 | return err; |
| 9888 | |
| 9889 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9890 | } |
| 9891 | |
| 9892 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9893 | { |
| 9894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9895 | struct net_device *dev = info->user_ptr[1]; |
| 9896 | |
| 9897 | return cfg80211_leave_ocb(rdev, dev); |
| 9898 | } |
| 9899 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9900 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9901 | { |
| 9902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9903 | struct net_device *dev = info->user_ptr[1]; |
| 9904 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9905 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9906 | int err; |
| 9907 | |
| 9908 | /* start with default */ |
| 9909 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9910 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9911 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9912 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9913 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9914 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9915 | if (err) |
| 9916 | return err; |
| 9917 | } |
| 9918 | |
| 9919 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9920 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9921 | return -EINVAL; |
| 9922 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9923 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9924 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9925 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9926 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9927 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9928 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9929 | return -EINVAL; |
| 9930 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9931 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9932 | setup.beacon_interval = |
| 9933 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9934 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9935 | err = cfg80211_validate_beacon_int(rdev, |
| 9936 | NL80211_IFTYPE_MESH_POINT, |
| 9937 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9938 | if (err) |
| 9939 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9940 | } |
| 9941 | |
| 9942 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9943 | setup.dtim_period = |
| 9944 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9945 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9946 | return -EINVAL; |
| 9947 | } |
| 9948 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9949 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9950 | /* parse additional setup parameters if given */ |
| 9951 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9952 | if (err) |
| 9953 | return err; |
| 9954 | } |
| 9955 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9956 | if (setup.user_mpm) |
| 9957 | cfg.auto_open_plinks = false; |
| 9958 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9959 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9960 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9961 | if (err) |
| 9962 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9963 | } else { |
| 9964 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9965 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9966 | } |
| 9967 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9968 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9969 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9970 | int n_rates = |
| 9971 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9972 | struct ieee80211_supported_band *sband; |
| 9973 | |
| 9974 | if (!setup.chandef.chan) |
| 9975 | return -EINVAL; |
| 9976 | |
| 9977 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9978 | |
| 9979 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9980 | &setup.basic_rates); |
| 9981 | if (err) |
| 9982 | return err; |
| 9983 | } |
| 9984 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9985 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 9986 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 9987 | if (err) |
| 9988 | return err; |
| 9989 | |
| 9990 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 9991 | &setup.beacon_rate); |
| 9992 | if (err) |
| 9993 | return err; |
| 9994 | } |
| 9995 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 9996 | setup.userspace_handles_dfs = |
| 9997 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 9998 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9999 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10000 | } |
| 10001 | |
| 10002 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10003 | { |
| 10004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10005 | struct net_device *dev = info->user_ptr[1]; |
| 10006 | |
| 10007 | return cfg80211_leave_mesh(rdev, dev); |
| 10008 | } |
| 10009 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10010 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10011 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 10012 | struct cfg80211_registered_device *rdev) |
| 10013 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10014 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10015 | struct nlattr *nl_pats, *nl_pat; |
| 10016 | int i, pat_len; |
| 10017 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10018 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10019 | return 0; |
| 10020 | |
| 10021 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 10022 | if (!nl_pats) |
| 10023 | return -ENOBUFS; |
| 10024 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10025 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10026 | nl_pat = nla_nest_start(msg, i + 1); |
| 10027 | if (!nl_pat) |
| 10028 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10029 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10030 | 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] | 10031 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10032 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10033 | wowlan->patterns[i].pattern) || |
| 10034 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10035 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10036 | return -ENOBUFS; |
| 10037 | nla_nest_end(msg, nl_pat); |
| 10038 | } |
| 10039 | nla_nest_end(msg, nl_pats); |
| 10040 | |
| 10041 | return 0; |
| 10042 | } |
| 10043 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10044 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 10045 | struct cfg80211_wowlan_tcp *tcp) |
| 10046 | { |
| 10047 | struct nlattr *nl_tcp; |
| 10048 | |
| 10049 | if (!tcp) |
| 10050 | return 0; |
| 10051 | |
| 10052 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 10053 | if (!nl_tcp) |
| 10054 | return -ENOBUFS; |
| 10055 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 10056 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 10057 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10058 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 10059 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 10060 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 10061 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 10062 | tcp->payload_len, tcp->payload) || |
| 10063 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 10064 | tcp->data_interval) || |
| 10065 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 10066 | tcp->wake_len, tcp->wake_data) || |
| 10067 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 10068 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 10069 | return -ENOBUFS; |
| 10070 | |
| 10071 | if (tcp->payload_seq.len && |
| 10072 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 10073 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 10074 | return -ENOBUFS; |
| 10075 | |
| 10076 | if (tcp->payload_tok.len && |
| 10077 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 10078 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 10079 | &tcp->payload_tok)) |
| 10080 | return -ENOBUFS; |
| 10081 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 10082 | nla_nest_end(msg, nl_tcp); |
| 10083 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10084 | return 0; |
| 10085 | } |
| 10086 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10087 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10088 | struct cfg80211_sched_scan_request *req) |
| 10089 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10090 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10091 | int i; |
| 10092 | |
| 10093 | if (!req) |
| 10094 | return 0; |
| 10095 | |
| 10096 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10097 | if (!nd) |
| 10098 | return -ENOBUFS; |
| 10099 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10100 | if (req->n_scan_plans == 1 && |
| 10101 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10102 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10103 | return -ENOBUFS; |
| 10104 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10105 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10106 | return -ENOBUFS; |
| 10107 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10108 | if (req->relative_rssi_set) { |
| 10109 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10110 | |
| 10111 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10112 | req->relative_rssi)) |
| 10113 | return -ENOBUFS; |
| 10114 | |
| 10115 | rssi_adjust.band = req->rssi_adjust.band; |
| 10116 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10117 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10118 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10119 | return -ENOBUFS; |
| 10120 | } |
| 10121 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10122 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10123 | if (!freqs) |
| 10124 | return -ENOBUFS; |
| 10125 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10126 | for (i = 0; i < req->n_channels; i++) { |
| 10127 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10128 | return -ENOBUFS; |
| 10129 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10130 | |
| 10131 | nla_nest_end(msg, freqs); |
| 10132 | |
| 10133 | if (req->n_match_sets) { |
| 10134 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10135 | if (!matches) |
| 10136 | return -ENOBUFS; |
| 10137 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10138 | for (i = 0; i < req->n_match_sets; i++) { |
| 10139 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10140 | if (!match) |
| 10141 | return -ENOBUFS; |
| 10142 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10143 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10144 | req->match_sets[i].ssid.ssid_len, |
| 10145 | req->match_sets[i].ssid.ssid)) |
| 10146 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10147 | nla_nest_end(msg, match); |
| 10148 | } |
| 10149 | nla_nest_end(msg, matches); |
| 10150 | } |
| 10151 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10152 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10153 | if (!scan_plans) |
| 10154 | return -ENOBUFS; |
| 10155 | |
| 10156 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10157 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10158 | if (!scan_plan) |
| 10159 | return -ENOBUFS; |
| 10160 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10161 | if (!scan_plan || |
| 10162 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 10163 | req->scan_plans[i].interval) || |
| 10164 | (req->scan_plans[i].iterations && |
| 10165 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10166 | req->scan_plans[i].iterations))) |
| 10167 | return -ENOBUFS; |
| 10168 | nla_nest_end(msg, scan_plan); |
| 10169 | } |
| 10170 | nla_nest_end(msg, scan_plans); |
| 10171 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10172 | nla_nest_end(msg, nd); |
| 10173 | |
| 10174 | return 0; |
| 10175 | } |
| 10176 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10177 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10178 | { |
| 10179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10180 | struct sk_buff *msg; |
| 10181 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10182 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10183 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10184 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10185 | return -EOPNOTSUPP; |
| 10186 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10187 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10188 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10189 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10190 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10191 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10192 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10193 | } |
| 10194 | |
| 10195 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10196 | if (!msg) |
| 10197 | return -ENOMEM; |
| 10198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10199 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10200 | NL80211_CMD_GET_WOWLAN); |
| 10201 | if (!hdr) |
| 10202 | goto nla_put_failure; |
| 10203 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10204 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10205 | struct nlattr *nl_wowlan; |
| 10206 | |
| 10207 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10208 | if (!nl_wowlan) |
| 10209 | goto nla_put_failure; |
| 10210 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10211 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10212 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10213 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10214 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10215 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10216 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10217 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10218 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10219 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10220 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10221 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10222 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10223 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10224 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10225 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10226 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10227 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10228 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10229 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10230 | if (nl80211_send_wowlan_tcp(msg, |
| 10231 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10232 | goto nla_put_failure; |
| 10233 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10234 | if (nl80211_send_wowlan_nd( |
| 10235 | msg, |
| 10236 | rdev->wiphy.wowlan_config->nd_config)) |
| 10237 | goto nla_put_failure; |
| 10238 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10239 | nla_nest_end(msg, nl_wowlan); |
| 10240 | } |
| 10241 | |
| 10242 | genlmsg_end(msg, hdr); |
| 10243 | return genlmsg_reply(msg, info); |
| 10244 | |
| 10245 | nla_put_failure: |
| 10246 | nlmsg_free(msg); |
| 10247 | return -ENOBUFS; |
| 10248 | } |
| 10249 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10250 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10251 | struct nlattr *attr, |
| 10252 | struct cfg80211_wowlan *trig) |
| 10253 | { |
| 10254 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10255 | struct cfg80211_wowlan_tcp *cfg; |
| 10256 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10257 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10258 | u32 size; |
| 10259 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10260 | int err, port; |
| 10261 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10262 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10263 | return -EINVAL; |
| 10264 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10265 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10266 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10267 | if (err) |
| 10268 | return err; |
| 10269 | |
| 10270 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10271 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10272 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10273 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10274 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10275 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10276 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10277 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10278 | return -EINVAL; |
| 10279 | |
| 10280 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10281 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10282 | return -EINVAL; |
| 10283 | |
| 10284 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10285 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10286 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10287 | return -EINVAL; |
| 10288 | |
| 10289 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10290 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10291 | return -EINVAL; |
| 10292 | |
| 10293 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10294 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10295 | return -EINVAL; |
| 10296 | |
| 10297 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10298 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10299 | |
| 10300 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10301 | tokens_size = tokln - sizeof(*tok); |
| 10302 | |
| 10303 | if (!tok->len || tokens_size % tok->len) |
| 10304 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10305 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10306 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10307 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10308 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10309 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10310 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10311 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10312 | return -EINVAL; |
| 10313 | if (tok->offset + tok->len > data_size) |
| 10314 | return -EINVAL; |
| 10315 | } |
| 10316 | |
| 10317 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10318 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10319 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10320 | return -EINVAL; |
| 10321 | if (seq->len == 0 || seq->len > 4) |
| 10322 | return -EINVAL; |
| 10323 | if (seq->len + seq->offset > data_size) |
| 10324 | return -EINVAL; |
| 10325 | } |
| 10326 | |
| 10327 | size = sizeof(*cfg); |
| 10328 | size += data_size; |
| 10329 | size += wake_size + wake_mask_size; |
| 10330 | size += tokens_size; |
| 10331 | |
| 10332 | cfg = kzalloc(size, GFP_KERNEL); |
| 10333 | if (!cfg) |
| 10334 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10335 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10336 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10337 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10338 | ETH_ALEN); |
| 10339 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10340 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10341 | else |
| 10342 | port = 0; |
| 10343 | #ifdef CONFIG_INET |
| 10344 | /* allocate a socket and port for it and use it */ |
| 10345 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10346 | IPPROTO_TCP, &cfg->sock, 1); |
| 10347 | if (err) { |
| 10348 | kfree(cfg); |
| 10349 | return err; |
| 10350 | } |
| 10351 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10352 | sock_release(cfg->sock); |
| 10353 | kfree(cfg); |
| 10354 | return -EADDRINUSE; |
| 10355 | } |
| 10356 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10357 | #else |
| 10358 | if (!port) { |
| 10359 | kfree(cfg); |
| 10360 | return -EINVAL; |
| 10361 | } |
| 10362 | cfg->src_port = port; |
| 10363 | #endif |
| 10364 | |
| 10365 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10366 | cfg->payload_len = data_size; |
| 10367 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10368 | memcpy((void *)cfg->payload, |
| 10369 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10370 | data_size); |
| 10371 | if (seq) |
| 10372 | cfg->payload_seq = *seq; |
| 10373 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10374 | cfg->wake_len = wake_size; |
| 10375 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10376 | memcpy((void *)cfg->wake_data, |
| 10377 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10378 | wake_size); |
| 10379 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10380 | data_size + wake_size; |
| 10381 | memcpy((void *)cfg->wake_mask, |
| 10382 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10383 | wake_mask_size); |
| 10384 | if (tok) { |
| 10385 | cfg->tokens_size = tokens_size; |
| 10386 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10387 | } |
| 10388 | |
| 10389 | trig->tcp = cfg; |
| 10390 | |
| 10391 | return 0; |
| 10392 | } |
| 10393 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10394 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10395 | const struct wiphy_wowlan_support *wowlan, |
| 10396 | struct nlattr *attr, |
| 10397 | struct cfg80211_wowlan *trig) |
| 10398 | { |
| 10399 | struct nlattr **tb; |
| 10400 | int err; |
| 10401 | |
| 10402 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10403 | if (!tb) |
| 10404 | return -ENOMEM; |
| 10405 | |
| 10406 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10407 | err = -EOPNOTSUPP; |
| 10408 | goto out; |
| 10409 | } |
| 10410 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10411 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
| 10412 | NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10413 | if (err) |
| 10414 | goto out; |
| 10415 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 10416 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 10417 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10418 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10419 | if (err) |
| 10420 | trig->nd_config = NULL; |
| 10421 | |
| 10422 | out: |
| 10423 | kfree(tb); |
| 10424 | return err; |
| 10425 | } |
| 10426 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10427 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10428 | { |
| 10429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10430 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10431 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10432 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10433 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10434 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10435 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10436 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10437 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10438 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10439 | return -EOPNOTSUPP; |
| 10440 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10441 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10442 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10443 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10444 | goto set_wakeup; |
| 10445 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10446 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10447 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10448 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10449 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10450 | if (err) |
| 10451 | return err; |
| 10452 | |
| 10453 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10454 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10455 | return -EINVAL; |
| 10456 | new_triggers.any = true; |
| 10457 | } |
| 10458 | |
| 10459 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10460 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10461 | return -EINVAL; |
| 10462 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10463 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10464 | } |
| 10465 | |
| 10466 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10467 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10468 | return -EINVAL; |
| 10469 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10470 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10471 | } |
| 10472 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10473 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10474 | return -EINVAL; |
| 10475 | |
| 10476 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10477 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10478 | return -EINVAL; |
| 10479 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10480 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10481 | } |
| 10482 | |
| 10483 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10484 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10485 | return -EINVAL; |
| 10486 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10487 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10488 | } |
| 10489 | |
| 10490 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10491 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10492 | return -EINVAL; |
| 10493 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10494 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10495 | } |
| 10496 | |
| 10497 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10498 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10499 | return -EINVAL; |
| 10500 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10501 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10502 | } |
| 10503 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10504 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10505 | struct nlattr *pat; |
| 10506 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10507 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10508 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10509 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10510 | regular = true; |
| 10511 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10512 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10513 | rem) |
| 10514 | n_patterns++; |
| 10515 | if (n_patterns > wowlan->n_patterns) |
| 10516 | return -EINVAL; |
| 10517 | |
| 10518 | new_triggers.patterns = kcalloc(n_patterns, |
| 10519 | sizeof(new_triggers.patterns[0]), |
| 10520 | GFP_KERNEL); |
| 10521 | if (!new_triggers.patterns) |
| 10522 | return -ENOMEM; |
| 10523 | |
| 10524 | new_triggers.n_patterns = n_patterns; |
| 10525 | i = 0; |
| 10526 | |
| 10527 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10528 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10529 | u8 *mask_pat; |
| 10530 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10531 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10532 | NULL, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10533 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10534 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10535 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10536 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10537 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10538 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10539 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10540 | goto error; |
| 10541 | if (pat_len > wowlan->pattern_max_len || |
| 10542 | pat_len < wowlan->pattern_min_len) |
| 10543 | goto error; |
| 10544 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10545 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10546 | pkt_offset = 0; |
| 10547 | else |
| 10548 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10549 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10550 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10551 | goto error; |
| 10552 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10553 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10554 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10555 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10556 | err = -ENOMEM; |
| 10557 | goto error; |
| 10558 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10559 | new_triggers.patterns[i].mask = mask_pat; |
| 10560 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10561 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10562 | mask_pat += mask_len; |
| 10563 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10564 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10565 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10566 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10567 | pat_len); |
| 10568 | i++; |
| 10569 | } |
| 10570 | } |
| 10571 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10572 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10573 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10574 | err = nl80211_parse_wowlan_tcp( |
| 10575 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10576 | &new_triggers); |
| 10577 | if (err) |
| 10578 | goto error; |
| 10579 | } |
| 10580 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10581 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10582 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10583 | err = nl80211_parse_wowlan_nd( |
| 10584 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10585 | &new_triggers); |
| 10586 | if (err) |
| 10587 | goto error; |
| 10588 | } |
| 10589 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10590 | /* The 'any' trigger means the device continues operating more or less |
| 10591 | * as in its normal operation mode and wakes up the host on most of the |
| 10592 | * normal interrupts (like packet RX, ...) |
| 10593 | * It therefore makes little sense to combine with the more constrained |
| 10594 | * wakeup trigger modes. |
| 10595 | */ |
| 10596 | if (new_triggers.any && regular) { |
| 10597 | err = -EINVAL; |
| 10598 | goto error; |
| 10599 | } |
| 10600 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10601 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10602 | if (!ntrig) { |
| 10603 | err = -ENOMEM; |
| 10604 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10605 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10606 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10607 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10608 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10609 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10610 | if (rdev->ops->set_wakeup && |
| 10611 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10612 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10613 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10614 | return 0; |
| 10615 | error: |
| 10616 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10617 | kfree(new_triggers.patterns[i].mask); |
| 10618 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10619 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10620 | sock_release(new_triggers.tcp->sock); |
| 10621 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10622 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10623 | return err; |
| 10624 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10625 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10626 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10627 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10628 | struct cfg80211_registered_device *rdev) |
| 10629 | { |
| 10630 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10631 | int i, j, pat_len; |
| 10632 | struct cfg80211_coalesce_rules *rule; |
| 10633 | |
| 10634 | if (!rdev->coalesce->n_rules) |
| 10635 | return 0; |
| 10636 | |
| 10637 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10638 | if (!nl_rules) |
| 10639 | return -ENOBUFS; |
| 10640 | |
| 10641 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10642 | nl_rule = nla_nest_start(msg, i + 1); |
| 10643 | if (!nl_rule) |
| 10644 | return -ENOBUFS; |
| 10645 | |
| 10646 | rule = &rdev->coalesce->rules[i]; |
| 10647 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10648 | rule->delay)) |
| 10649 | return -ENOBUFS; |
| 10650 | |
| 10651 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10652 | rule->condition)) |
| 10653 | return -ENOBUFS; |
| 10654 | |
| 10655 | nl_pats = nla_nest_start(msg, |
| 10656 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10657 | if (!nl_pats) |
| 10658 | return -ENOBUFS; |
| 10659 | |
| 10660 | for (j = 0; j < rule->n_patterns; j++) { |
| 10661 | nl_pat = nla_nest_start(msg, j + 1); |
| 10662 | if (!nl_pat) |
| 10663 | return -ENOBUFS; |
| 10664 | pat_len = rule->patterns[j].pattern_len; |
| 10665 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10666 | DIV_ROUND_UP(pat_len, 8), |
| 10667 | rule->patterns[j].mask) || |
| 10668 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10669 | rule->patterns[j].pattern) || |
| 10670 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10671 | rule->patterns[j].pkt_offset)) |
| 10672 | return -ENOBUFS; |
| 10673 | nla_nest_end(msg, nl_pat); |
| 10674 | } |
| 10675 | nla_nest_end(msg, nl_pats); |
| 10676 | nla_nest_end(msg, nl_rule); |
| 10677 | } |
| 10678 | nla_nest_end(msg, nl_rules); |
| 10679 | |
| 10680 | return 0; |
| 10681 | } |
| 10682 | |
| 10683 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10684 | { |
| 10685 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10686 | struct sk_buff *msg; |
| 10687 | void *hdr; |
| 10688 | |
| 10689 | if (!rdev->wiphy.coalesce) |
| 10690 | return -EOPNOTSUPP; |
| 10691 | |
| 10692 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10693 | if (!msg) |
| 10694 | return -ENOMEM; |
| 10695 | |
| 10696 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10697 | NL80211_CMD_GET_COALESCE); |
| 10698 | if (!hdr) |
| 10699 | goto nla_put_failure; |
| 10700 | |
| 10701 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10702 | goto nla_put_failure; |
| 10703 | |
| 10704 | genlmsg_end(msg, hdr); |
| 10705 | return genlmsg_reply(msg, info); |
| 10706 | |
| 10707 | nla_put_failure: |
| 10708 | nlmsg_free(msg); |
| 10709 | return -ENOBUFS; |
| 10710 | } |
| 10711 | |
| 10712 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10713 | { |
| 10714 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10715 | int i, j; |
| 10716 | struct cfg80211_coalesce_rules *rule; |
| 10717 | |
| 10718 | if (!coalesce) |
| 10719 | return; |
| 10720 | |
| 10721 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10722 | rule = &coalesce->rules[i]; |
| 10723 | for (j = 0; j < rule->n_patterns; j++) |
| 10724 | kfree(rule->patterns[j].mask); |
| 10725 | kfree(rule->patterns); |
| 10726 | } |
| 10727 | kfree(coalesce->rules); |
| 10728 | kfree(coalesce); |
| 10729 | rdev->coalesce = NULL; |
| 10730 | } |
| 10731 | |
| 10732 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10733 | struct nlattr *rule, |
| 10734 | struct cfg80211_coalesce_rules *new_rule) |
| 10735 | { |
| 10736 | int err, i; |
| 10737 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10738 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10739 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10740 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10741 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10742 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10743 | nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10744 | if (err) |
| 10745 | return err; |
| 10746 | |
| 10747 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10748 | new_rule->delay = |
| 10749 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10750 | if (new_rule->delay > coalesce->max_delay) |
| 10751 | return -EINVAL; |
| 10752 | |
| 10753 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10754 | new_rule->condition = |
| 10755 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10756 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10757 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10758 | return -EINVAL; |
| 10759 | |
| 10760 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10761 | return -EINVAL; |
| 10762 | |
| 10763 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10764 | rem) |
| 10765 | n_patterns++; |
| 10766 | if (n_patterns > coalesce->n_patterns) |
| 10767 | return -EINVAL; |
| 10768 | |
| 10769 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10770 | GFP_KERNEL); |
| 10771 | if (!new_rule->patterns) |
| 10772 | return -ENOMEM; |
| 10773 | |
| 10774 | new_rule->n_patterns = n_patterns; |
| 10775 | i = 0; |
| 10776 | |
| 10777 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10778 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10779 | u8 *mask_pat; |
| 10780 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10781 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10782 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10783 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10784 | return -EINVAL; |
| 10785 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10786 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10787 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10788 | return -EINVAL; |
| 10789 | if (pat_len > coalesce->pattern_max_len || |
| 10790 | pat_len < coalesce->pattern_min_len) |
| 10791 | return -EINVAL; |
| 10792 | |
| 10793 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10794 | pkt_offset = 0; |
| 10795 | else |
| 10796 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10797 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10798 | return -EINVAL; |
| 10799 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10800 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10801 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10802 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10803 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10804 | |
| 10805 | new_rule->patterns[i].mask = mask_pat; |
| 10806 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10807 | mask_len); |
| 10808 | |
| 10809 | mask_pat += mask_len; |
| 10810 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10811 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10812 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10813 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10814 | i++; |
| 10815 | } |
| 10816 | |
| 10817 | return 0; |
| 10818 | } |
| 10819 | |
| 10820 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10821 | { |
| 10822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10823 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10824 | struct cfg80211_coalesce new_coalesce = {}; |
| 10825 | struct cfg80211_coalesce *n_coalesce; |
| 10826 | int err, rem_rule, n_rules = 0, i, j; |
| 10827 | struct nlattr *rule; |
| 10828 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10829 | |
| 10830 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10831 | return -EOPNOTSUPP; |
| 10832 | |
| 10833 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10834 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10835 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10836 | return 0; |
| 10837 | } |
| 10838 | |
| 10839 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10840 | rem_rule) |
| 10841 | n_rules++; |
| 10842 | if (n_rules > coalesce->n_rules) |
| 10843 | return -EINVAL; |
| 10844 | |
| 10845 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10846 | GFP_KERNEL); |
| 10847 | if (!new_coalesce.rules) |
| 10848 | return -ENOMEM; |
| 10849 | |
| 10850 | new_coalesce.n_rules = n_rules; |
| 10851 | i = 0; |
| 10852 | |
| 10853 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10854 | rem_rule) { |
| 10855 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10856 | &new_coalesce.rules[i]); |
| 10857 | if (err) |
| 10858 | goto error; |
| 10859 | |
| 10860 | i++; |
| 10861 | } |
| 10862 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10863 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10864 | if (err) |
| 10865 | goto error; |
| 10866 | |
| 10867 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10868 | if (!n_coalesce) { |
| 10869 | err = -ENOMEM; |
| 10870 | goto error; |
| 10871 | } |
| 10872 | cfg80211_rdev_free_coalesce(rdev); |
| 10873 | rdev->coalesce = n_coalesce; |
| 10874 | |
| 10875 | return 0; |
| 10876 | error: |
| 10877 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10878 | tmp_rule = &new_coalesce.rules[i]; |
| 10879 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10880 | kfree(tmp_rule->patterns[j].mask); |
| 10881 | kfree(tmp_rule->patterns); |
| 10882 | } |
| 10883 | kfree(new_coalesce.rules); |
| 10884 | |
| 10885 | return err; |
| 10886 | } |
| 10887 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10888 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10889 | { |
| 10890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10891 | struct net_device *dev = info->user_ptr[1]; |
| 10892 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10893 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10894 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10895 | int err; |
| 10896 | |
| 10897 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10898 | return -EINVAL; |
| 10899 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10900 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 10901 | info->attrs[NL80211_ATTR_REKEY_DATA], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10902 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10903 | if (err) |
| 10904 | return err; |
| 10905 | |
| 10906 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10907 | return -ERANGE; |
| 10908 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10909 | return -ERANGE; |
| 10910 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10911 | return -ERANGE; |
| 10912 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10913 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10914 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10915 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10916 | |
| 10917 | wdev_lock(wdev); |
| 10918 | if (!wdev->current_bss) { |
| 10919 | err = -ENOTCONN; |
| 10920 | goto out; |
| 10921 | } |
| 10922 | |
| 10923 | if (!rdev->ops->set_rekey_data) { |
| 10924 | err = -EOPNOTSUPP; |
| 10925 | goto out; |
| 10926 | } |
| 10927 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10928 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10929 | out: |
| 10930 | wdev_unlock(wdev); |
| 10931 | return err; |
| 10932 | } |
| 10933 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10934 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10935 | struct genl_info *info) |
| 10936 | { |
| 10937 | struct net_device *dev = info->user_ptr[1]; |
| 10938 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10939 | |
| 10940 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10941 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10942 | return -EINVAL; |
| 10943 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10944 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10945 | return -EBUSY; |
| 10946 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10947 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10948 | return 0; |
| 10949 | } |
| 10950 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10951 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10952 | struct genl_info *info) |
| 10953 | { |
| 10954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10955 | struct net_device *dev = info->user_ptr[1]; |
| 10956 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10957 | struct sk_buff *msg; |
| 10958 | void *hdr; |
| 10959 | const u8 *addr; |
| 10960 | u64 cookie; |
| 10961 | int err; |
| 10962 | |
| 10963 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10964 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10965 | return -EOPNOTSUPP; |
| 10966 | |
| 10967 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10968 | return -EINVAL; |
| 10969 | |
| 10970 | if (!rdev->ops->probe_client) |
| 10971 | return -EOPNOTSUPP; |
| 10972 | |
| 10973 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10974 | if (!msg) |
| 10975 | return -ENOMEM; |
| 10976 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10977 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10978 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10979 | if (!hdr) { |
| 10980 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10981 | goto free_msg; |
| 10982 | } |
| 10983 | |
| 10984 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10986 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10987 | if (err) |
| 10988 | goto free_msg; |
| 10989 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10990 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10991 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10992 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10993 | |
| 10994 | genlmsg_end(msg, hdr); |
| 10995 | |
| 10996 | return genlmsg_reply(msg, info); |
| 10997 | |
| 10998 | nla_put_failure: |
| 10999 | err = -ENOBUFS; |
| 11000 | free_msg: |
| 11001 | nlmsg_free(msg); |
| 11002 | return err; |
| 11003 | } |
| 11004 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11005 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 11006 | { |
| 11007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11008 | struct cfg80211_beacon_registration *reg, *nreg; |
| 11009 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11010 | |
| 11011 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 11012 | return -EOPNOTSUPP; |
| 11013 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11014 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 11015 | if (!nreg) |
| 11016 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11017 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11018 | /* First, check if already registered. */ |
| 11019 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11020 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11021 | if (reg->nlportid == info->snd_portid) { |
| 11022 | rv = -EALREADY; |
| 11023 | goto out_err; |
| 11024 | } |
| 11025 | } |
| 11026 | /* Add it to the list */ |
| 11027 | nreg->nlportid = info->snd_portid; |
| 11028 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 11029 | |
| 11030 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11031 | |
| 11032 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11033 | out_err: |
| 11034 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11035 | kfree(nreg); |
| 11036 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11037 | } |
| 11038 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11039 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11040 | { |
| 11041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11042 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11043 | int err; |
| 11044 | |
| 11045 | if (!rdev->ops->start_p2p_device) |
| 11046 | return -EOPNOTSUPP; |
| 11047 | |
| 11048 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11049 | return -EOPNOTSUPP; |
| 11050 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11051 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11052 | return 0; |
| 11053 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 11054 | if (rfkill_blocked(rdev->rfkill)) |
| 11055 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11056 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 11057 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11058 | if (err) |
| 11059 | return err; |
| 11060 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11061 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11062 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11063 | |
| 11064 | return 0; |
| 11065 | } |
| 11066 | |
| 11067 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11068 | { |
| 11069 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11070 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11071 | |
| 11072 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11073 | return -EOPNOTSUPP; |
| 11074 | |
| 11075 | if (!rdev->ops->stop_p2p_device) |
| 11076 | return -EOPNOTSUPP; |
| 11077 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 11078 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11079 | |
| 11080 | return 0; |
| 11081 | } |
| 11082 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11083 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11084 | { |
| 11085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11086 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11087 | struct cfg80211_nan_conf conf = {}; |
| 11088 | int err; |
| 11089 | |
| 11090 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11091 | return -EOPNOTSUPP; |
| 11092 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11093 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11094 | return -EEXIST; |
| 11095 | |
| 11096 | if (rfkill_blocked(rdev->rfkill)) |
| 11097 | return -ERFKILL; |
| 11098 | |
| 11099 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11100 | return -EINVAL; |
| 11101 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11102 | conf.master_pref = |
| 11103 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11104 | if (!conf.master_pref) |
| 11105 | return -EINVAL; |
| 11106 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11107 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11108 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11109 | |
| 11110 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11111 | return -EOPNOTSUPP; |
| 11112 | |
| 11113 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11114 | return -EINVAL; |
| 11115 | |
| 11116 | conf.bands = bands; |
| 11117 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11118 | |
| 11119 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11120 | if (err) |
| 11121 | return err; |
| 11122 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11123 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11124 | rdev->opencount++; |
| 11125 | |
| 11126 | return 0; |
| 11127 | } |
| 11128 | |
| 11129 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11130 | { |
| 11131 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11132 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11133 | |
| 11134 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11135 | return -EOPNOTSUPP; |
| 11136 | |
| 11137 | cfg80211_stop_nan(rdev, wdev); |
| 11138 | |
| 11139 | return 0; |
| 11140 | } |
| 11141 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11142 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11143 | { |
| 11144 | struct nlattr *attr; |
| 11145 | int len = 0, n_entries = 0, rem; |
| 11146 | |
| 11147 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11148 | len += nla_len(attr); |
| 11149 | n_entries++; |
| 11150 | } |
| 11151 | |
| 11152 | if (len >= U8_MAX) |
| 11153 | return -EINVAL; |
| 11154 | |
| 11155 | return n_entries; |
| 11156 | } |
| 11157 | |
| 11158 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11159 | struct cfg80211_nan_func *func, |
| 11160 | bool tx) |
| 11161 | { |
| 11162 | struct nlattr *attr; |
| 11163 | int n_entries, rem, i; |
| 11164 | struct cfg80211_nan_func_filter *filter; |
| 11165 | |
| 11166 | n_entries = validate_nan_filter(attr_filter); |
| 11167 | if (n_entries < 0) |
| 11168 | return n_entries; |
| 11169 | |
| 11170 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11171 | |
| 11172 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11173 | if (!filter) |
| 11174 | return -ENOMEM; |
| 11175 | |
| 11176 | i = 0; |
| 11177 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11178 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11179 | filter[i].len = nla_len(attr); |
| 11180 | i++; |
| 11181 | } |
| 11182 | if (tx) { |
| 11183 | func->num_tx_filters = n_entries; |
| 11184 | func->tx_filters = filter; |
| 11185 | } else { |
| 11186 | func->num_rx_filters = n_entries; |
| 11187 | func->rx_filters = filter; |
| 11188 | } |
| 11189 | |
| 11190 | return 0; |
| 11191 | } |
| 11192 | |
| 11193 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11194 | struct genl_info *info) |
| 11195 | { |
| 11196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11197 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11198 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11199 | struct cfg80211_nan_func *func; |
| 11200 | struct sk_buff *msg = NULL; |
| 11201 | void *hdr = NULL; |
| 11202 | int err = 0; |
| 11203 | |
| 11204 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11205 | return -EOPNOTSUPP; |
| 11206 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11207 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11208 | return -ENOTCONN; |
| 11209 | |
| 11210 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11211 | return -EINVAL; |
| 11212 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11213 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11214 | info->attrs[NL80211_ATTR_NAN_FUNC], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11215 | nl80211_nan_func_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11216 | if (err) |
| 11217 | return err; |
| 11218 | |
| 11219 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11220 | if (!func) |
| 11221 | return -ENOMEM; |
| 11222 | |
| 11223 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11224 | |
| 11225 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11226 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11227 | err = -EINVAL; |
| 11228 | goto out; |
| 11229 | } |
| 11230 | |
| 11231 | |
| 11232 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11233 | |
| 11234 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11235 | err = -EINVAL; |
| 11236 | goto out; |
| 11237 | } |
| 11238 | |
| 11239 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11240 | sizeof(func->service_id)); |
| 11241 | |
| 11242 | func->close_range = |
| 11243 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11244 | |
| 11245 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11246 | func->serv_spec_info_len = |
| 11247 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11248 | func->serv_spec_info = |
| 11249 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11250 | func->serv_spec_info_len, |
| 11251 | GFP_KERNEL); |
| 11252 | if (!func->serv_spec_info) { |
| 11253 | err = -ENOMEM; |
| 11254 | goto out; |
| 11255 | } |
| 11256 | } |
| 11257 | |
| 11258 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11259 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11260 | |
| 11261 | switch (func->type) { |
| 11262 | case NL80211_NAN_FUNC_PUBLISH: |
| 11263 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11264 | err = -EINVAL; |
| 11265 | goto out; |
| 11266 | } |
| 11267 | |
| 11268 | func->publish_type = |
| 11269 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11270 | func->publish_bcast = |
| 11271 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11272 | |
| 11273 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11274 | func->publish_bcast) { |
| 11275 | err = -EINVAL; |
| 11276 | goto out; |
| 11277 | } |
| 11278 | break; |
| 11279 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11280 | func->subscribe_active = |
| 11281 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11282 | break; |
| 11283 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11284 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 11285 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 11286 | err = -EINVAL; |
| 11287 | goto out; |
| 11288 | } |
| 11289 | |
| 11290 | func->followup_id = |
| 11291 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11292 | func->followup_reqid = |
| 11293 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11294 | memcpy(func->followup_dest.addr, |
| 11295 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11296 | sizeof(func->followup_dest.addr)); |
| 11297 | if (func->ttl) { |
| 11298 | err = -EINVAL; |
| 11299 | goto out; |
| 11300 | } |
| 11301 | break; |
| 11302 | default: |
| 11303 | err = -EINVAL; |
| 11304 | goto out; |
| 11305 | } |
| 11306 | |
| 11307 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11308 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11309 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11310 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11311 | tb[NL80211_NAN_FUNC_SRF], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11312 | nl80211_nan_srf_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11313 | if (err) |
| 11314 | goto out; |
| 11315 | |
| 11316 | func->srf_include = |
| 11317 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11318 | |
| 11319 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11320 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11321 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11322 | err = -EINVAL; |
| 11323 | goto out; |
| 11324 | } |
| 11325 | |
| 11326 | func->srf_bf_len = |
| 11327 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11328 | func->srf_bf = |
| 11329 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11330 | func->srf_bf_len, GFP_KERNEL); |
| 11331 | if (!func->srf_bf) { |
| 11332 | err = -ENOMEM; |
| 11333 | goto out; |
| 11334 | } |
| 11335 | |
| 11336 | func->srf_bf_idx = |
| 11337 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11338 | } else { |
| 11339 | struct nlattr *attr, *mac_attr = |
| 11340 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11341 | int n_entries, rem, i = 0; |
| 11342 | |
| 11343 | if (!mac_attr) { |
| 11344 | err = -EINVAL; |
| 11345 | goto out; |
| 11346 | } |
| 11347 | |
| 11348 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11349 | if (n_entries <= 0) { |
| 11350 | err = -EINVAL; |
| 11351 | goto out; |
| 11352 | } |
| 11353 | |
| 11354 | func->srf_num_macs = n_entries; |
| 11355 | func->srf_macs = |
| 11356 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11357 | GFP_KERNEL); |
| 11358 | if (!func->srf_macs) { |
| 11359 | err = -ENOMEM; |
| 11360 | goto out; |
| 11361 | } |
| 11362 | |
| 11363 | nla_for_each_nested(attr, mac_attr, rem) |
| 11364 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11365 | sizeof(*func->srf_macs)); |
| 11366 | } |
| 11367 | } |
| 11368 | |
| 11369 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11370 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11371 | func, true); |
| 11372 | if (err) |
| 11373 | goto out; |
| 11374 | } |
| 11375 | |
| 11376 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11377 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11378 | func, false); |
| 11379 | if (err) |
| 11380 | goto out; |
| 11381 | } |
| 11382 | |
| 11383 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11384 | if (!msg) { |
| 11385 | err = -ENOMEM; |
| 11386 | goto out; |
| 11387 | } |
| 11388 | |
| 11389 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11390 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11391 | /* This can't really happen - we just allocated 4KB */ |
| 11392 | if (WARN_ON(!hdr)) { |
| 11393 | err = -ENOMEM; |
| 11394 | goto out; |
| 11395 | } |
| 11396 | |
| 11397 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11398 | out: |
| 11399 | if (err < 0) { |
| 11400 | cfg80211_free_nan_func(func); |
| 11401 | nlmsg_free(msg); |
| 11402 | return err; |
| 11403 | } |
| 11404 | |
| 11405 | /* propagate the instance id and cookie to userspace */ |
| 11406 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11407 | NL80211_ATTR_PAD)) |
| 11408 | goto nla_put_failure; |
| 11409 | |
| 11410 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11411 | if (!func_attr) |
| 11412 | goto nla_put_failure; |
| 11413 | |
| 11414 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11415 | func->instance_id)) |
| 11416 | goto nla_put_failure; |
| 11417 | |
| 11418 | nla_nest_end(msg, func_attr); |
| 11419 | |
| 11420 | genlmsg_end(msg, hdr); |
| 11421 | return genlmsg_reply(msg, info); |
| 11422 | |
| 11423 | nla_put_failure: |
| 11424 | nlmsg_free(msg); |
| 11425 | return -ENOBUFS; |
| 11426 | } |
| 11427 | |
| 11428 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11429 | struct genl_info *info) |
| 11430 | { |
| 11431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11432 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11433 | u64 cookie; |
| 11434 | |
| 11435 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11436 | return -EOPNOTSUPP; |
| 11437 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11438 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11439 | return -ENOTCONN; |
| 11440 | |
| 11441 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11442 | return -EINVAL; |
| 11443 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11444 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11445 | |
| 11446 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11447 | |
| 11448 | return 0; |
| 11449 | } |
| 11450 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11451 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11452 | struct genl_info *info) |
| 11453 | { |
| 11454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11455 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11456 | struct cfg80211_nan_conf conf = {}; |
| 11457 | u32 changed = 0; |
| 11458 | |
| 11459 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11460 | return -EOPNOTSUPP; |
| 11461 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11462 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11463 | return -ENOTCONN; |
| 11464 | |
| 11465 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11466 | conf.master_pref = |
| 11467 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11468 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11469 | return -EINVAL; |
| 11470 | |
| 11471 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11472 | } |
| 11473 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11474 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11475 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11476 | |
| 11477 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11478 | return -EOPNOTSUPP; |
| 11479 | |
| 11480 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11481 | return -EINVAL; |
| 11482 | |
| 11483 | conf.bands = bands; |
| 11484 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11485 | } |
| 11486 | |
| 11487 | if (!changed) |
| 11488 | return -EINVAL; |
| 11489 | |
| 11490 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11491 | } |
| 11492 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11493 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11494 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11495 | { |
| 11496 | struct wiphy *wiphy = wdev->wiphy; |
| 11497 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11498 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11499 | struct sk_buff *msg; |
| 11500 | void *hdr; |
| 11501 | |
| 11502 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11503 | return; |
| 11504 | |
| 11505 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11506 | if (!msg) |
| 11507 | return; |
| 11508 | |
| 11509 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11510 | if (!hdr) { |
| 11511 | nlmsg_free(msg); |
| 11512 | return; |
| 11513 | } |
| 11514 | |
| 11515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11516 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11517 | wdev->netdev->ifindex)) || |
| 11518 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11519 | NL80211_ATTR_PAD)) |
| 11520 | goto nla_put_failure; |
| 11521 | |
| 11522 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11523 | NL80211_ATTR_PAD) || |
| 11524 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11525 | goto nla_put_failure; |
| 11526 | |
| 11527 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11528 | if (!match_attr) |
| 11529 | goto nla_put_failure; |
| 11530 | |
| 11531 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11532 | if (!local_func_attr) |
| 11533 | goto nla_put_failure; |
| 11534 | |
| 11535 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11536 | goto nla_put_failure; |
| 11537 | |
| 11538 | nla_nest_end(msg, local_func_attr); |
| 11539 | |
| 11540 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11541 | if (!peer_func_attr) |
| 11542 | goto nla_put_failure; |
| 11543 | |
| 11544 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11545 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11546 | goto nla_put_failure; |
| 11547 | |
| 11548 | if (match->info && match->info_len && |
| 11549 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11550 | match->info)) |
| 11551 | goto nla_put_failure; |
| 11552 | |
| 11553 | nla_nest_end(msg, peer_func_attr); |
| 11554 | nla_nest_end(msg, match_attr); |
| 11555 | genlmsg_end(msg, hdr); |
| 11556 | |
| 11557 | if (!wdev->owner_nlportid) |
| 11558 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11559 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11560 | else |
| 11561 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11562 | wdev->owner_nlportid); |
| 11563 | |
| 11564 | return; |
| 11565 | |
| 11566 | nla_put_failure: |
| 11567 | nlmsg_free(msg); |
| 11568 | } |
| 11569 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11570 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11571 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11572 | u8 inst_id, |
| 11573 | enum nl80211_nan_func_term_reason reason, |
| 11574 | u64 cookie, gfp_t gfp) |
| 11575 | { |
| 11576 | struct wiphy *wiphy = wdev->wiphy; |
| 11577 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11578 | struct sk_buff *msg; |
| 11579 | struct nlattr *func_attr; |
| 11580 | void *hdr; |
| 11581 | |
| 11582 | if (WARN_ON(!inst_id)) |
| 11583 | return; |
| 11584 | |
| 11585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11586 | if (!msg) |
| 11587 | return; |
| 11588 | |
| 11589 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11590 | if (!hdr) { |
| 11591 | nlmsg_free(msg); |
| 11592 | return; |
| 11593 | } |
| 11594 | |
| 11595 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11596 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11597 | wdev->netdev->ifindex)) || |
| 11598 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11599 | NL80211_ATTR_PAD)) |
| 11600 | goto nla_put_failure; |
| 11601 | |
| 11602 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11603 | NL80211_ATTR_PAD)) |
| 11604 | goto nla_put_failure; |
| 11605 | |
| 11606 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11607 | if (!func_attr) |
| 11608 | goto nla_put_failure; |
| 11609 | |
| 11610 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11611 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11612 | goto nla_put_failure; |
| 11613 | |
| 11614 | nla_nest_end(msg, func_attr); |
| 11615 | genlmsg_end(msg, hdr); |
| 11616 | |
| 11617 | if (!wdev->owner_nlportid) |
| 11618 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11619 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11620 | else |
| 11621 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11622 | wdev->owner_nlportid); |
| 11623 | |
| 11624 | return; |
| 11625 | |
| 11626 | nla_put_failure: |
| 11627 | nlmsg_free(msg); |
| 11628 | } |
| 11629 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11630 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11631 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11632 | struct genl_info *info) |
| 11633 | { |
| 11634 | void *hdr; |
| 11635 | struct sk_buff *msg; |
| 11636 | |
| 11637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11638 | if (!msg) |
| 11639 | return -ENOMEM; |
| 11640 | |
| 11641 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11642 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11643 | if (!hdr) |
| 11644 | goto nla_put_failure; |
| 11645 | |
| 11646 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11647 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11648 | goto nla_put_failure; |
| 11649 | |
| 11650 | genlmsg_end(msg, hdr); |
| 11651 | return genlmsg_reply(msg, info); |
| 11652 | |
| 11653 | nla_put_failure: |
| 11654 | kfree_skb(msg); |
| 11655 | return -ENOBUFS; |
| 11656 | } |
| 11657 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11658 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11659 | { |
| 11660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11661 | struct cfg80211_update_ft_ies_params ft_params; |
| 11662 | struct net_device *dev = info->user_ptr[1]; |
| 11663 | |
| 11664 | if (!rdev->ops->update_ft_ies) |
| 11665 | return -EOPNOTSUPP; |
| 11666 | |
| 11667 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11668 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11669 | return -EINVAL; |
| 11670 | |
| 11671 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11672 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11673 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11674 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11675 | |
| 11676 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11677 | } |
| 11678 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11679 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11680 | struct genl_info *info) |
| 11681 | { |
| 11682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11683 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11684 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11685 | u16 duration; |
| 11686 | int ret; |
| 11687 | |
| 11688 | if (!rdev->ops->crit_proto_start) |
| 11689 | return -EOPNOTSUPP; |
| 11690 | |
| 11691 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11692 | return -EINVAL; |
| 11693 | |
| 11694 | if (rdev->crit_proto_nlportid) |
| 11695 | return -EBUSY; |
| 11696 | |
| 11697 | /* determine protocol if provided */ |
| 11698 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11699 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11700 | |
| 11701 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11702 | return -EINVAL; |
| 11703 | |
| 11704 | /* timeout must be provided */ |
| 11705 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11706 | return -EINVAL; |
| 11707 | |
| 11708 | duration = |
| 11709 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11710 | |
| 11711 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11712 | return -ERANGE; |
| 11713 | |
| 11714 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11715 | if (!ret) |
| 11716 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11717 | |
| 11718 | return ret; |
| 11719 | } |
| 11720 | |
| 11721 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11722 | struct genl_info *info) |
| 11723 | { |
| 11724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11725 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11726 | |
| 11727 | if (!rdev->ops->crit_proto_stop) |
| 11728 | return -EOPNOTSUPP; |
| 11729 | |
| 11730 | if (rdev->crit_proto_nlportid) { |
| 11731 | rdev->crit_proto_nlportid = 0; |
| 11732 | rdev_crit_proto_stop(rdev, wdev); |
| 11733 | } |
| 11734 | return 0; |
| 11735 | } |
| 11736 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11737 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11738 | { |
| 11739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11740 | struct wireless_dev *wdev = |
| 11741 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11742 | int i, err; |
| 11743 | u32 vid, subcmd; |
| 11744 | |
| 11745 | if (!rdev->wiphy.vendor_commands) |
| 11746 | return -EOPNOTSUPP; |
| 11747 | |
| 11748 | if (IS_ERR(wdev)) { |
| 11749 | err = PTR_ERR(wdev); |
| 11750 | if (err != -EINVAL) |
| 11751 | return err; |
| 11752 | wdev = NULL; |
| 11753 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11754 | return -EINVAL; |
| 11755 | } |
| 11756 | |
| 11757 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11758 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11759 | return -EINVAL; |
| 11760 | |
| 11761 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11762 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11763 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11764 | const struct wiphy_vendor_command *vcmd; |
| 11765 | void *data = NULL; |
| 11766 | int len = 0; |
| 11767 | |
| 11768 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11769 | |
| 11770 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11771 | continue; |
| 11772 | |
| 11773 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11774 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11775 | if (!wdev) |
| 11776 | return -EINVAL; |
| 11777 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11778 | !wdev->netdev) |
| 11779 | return -EINVAL; |
| 11780 | |
| 11781 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11782 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11783 | return -ENETDOWN; |
| 11784 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11785 | |
| 11786 | if (!vcmd->doit) |
| 11787 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11788 | } else { |
| 11789 | wdev = NULL; |
| 11790 | } |
| 11791 | |
| 11792 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11793 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11794 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11795 | } |
| 11796 | |
| 11797 | rdev->cur_cmd_info = info; |
| 11798 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11799 | data, len); |
| 11800 | rdev->cur_cmd_info = NULL; |
| 11801 | return err; |
| 11802 | } |
| 11803 | |
| 11804 | return -EOPNOTSUPP; |
| 11805 | } |
| 11806 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11807 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11808 | struct netlink_callback *cb, |
| 11809 | struct cfg80211_registered_device **rdev, |
| 11810 | struct wireless_dev **wdev) |
| 11811 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11812 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11813 | u32 vid, subcmd; |
| 11814 | unsigned int i; |
| 11815 | int vcmd_idx = -1; |
| 11816 | int err; |
| 11817 | void *data = NULL; |
| 11818 | unsigned int data_len = 0; |
| 11819 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11820 | if (cb->args[0]) { |
| 11821 | /* subtract the 1 again here */ |
| 11822 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11823 | struct wireless_dev *tmp; |
| 11824 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11825 | if (!wiphy) |
| 11826 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11827 | *rdev = wiphy_to_rdev(wiphy); |
| 11828 | *wdev = NULL; |
| 11829 | |
| 11830 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11831 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11832 | if (tmp->identifier == cb->args[1] - 1) { |
| 11833 | *wdev = tmp; |
| 11834 | break; |
| 11835 | } |
| 11836 | } |
| 11837 | } |
| 11838 | |
| 11839 | /* keep rtnl locked in successful case */ |
| 11840 | return 0; |
| 11841 | } |
| 11842 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11843 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
| 11844 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11845 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11846 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11847 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11848 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11849 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11850 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11851 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11852 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11853 | if (IS_ERR(*wdev)) |
| 11854 | *wdev = NULL; |
| 11855 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11856 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11857 | if (IS_ERR(*rdev)) |
| 11858 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11859 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11860 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11861 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11862 | |
| 11863 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11864 | const struct wiphy_vendor_command *vcmd; |
| 11865 | |
| 11866 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11867 | |
| 11868 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11869 | continue; |
| 11870 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11871 | if (!vcmd->dumpit) |
| 11872 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11873 | |
| 11874 | vcmd_idx = i; |
| 11875 | break; |
| 11876 | } |
| 11877 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11878 | if (vcmd_idx < 0) |
| 11879 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11880 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11881 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11882 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11883 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11884 | } |
| 11885 | |
| 11886 | /* 0 is the first index - add 1 to parse only once */ |
| 11887 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11888 | /* add 1 to know if it was NULL */ |
| 11889 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11890 | cb->args[2] = vcmd_idx; |
| 11891 | cb->args[3] = (unsigned long)data; |
| 11892 | cb->args[4] = data_len; |
| 11893 | |
| 11894 | /* keep rtnl locked in successful case */ |
| 11895 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11896 | } |
| 11897 | |
| 11898 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11899 | struct netlink_callback *cb) |
| 11900 | { |
| 11901 | struct cfg80211_registered_device *rdev; |
| 11902 | struct wireless_dev *wdev; |
| 11903 | unsigned int vcmd_idx; |
| 11904 | const struct wiphy_vendor_command *vcmd; |
| 11905 | void *data; |
| 11906 | int data_len; |
| 11907 | int err; |
| 11908 | struct nlattr *vendor_data; |
| 11909 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11910 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11911 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11912 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11913 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11914 | |
| 11915 | vcmd_idx = cb->args[2]; |
| 11916 | data = (void *)cb->args[3]; |
| 11917 | data_len = cb->args[4]; |
| 11918 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11919 | |
| 11920 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11921 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11922 | if (!wdev) { |
| 11923 | err = -EINVAL; |
| 11924 | goto out; |
| 11925 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11926 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11927 | !wdev->netdev) { |
| 11928 | err = -EINVAL; |
| 11929 | goto out; |
| 11930 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11931 | |
| 11932 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11933 | if (!wdev_running(wdev)) { |
| 11934 | err = -ENETDOWN; |
| 11935 | goto out; |
| 11936 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11937 | } |
| 11938 | } |
| 11939 | |
| 11940 | while (1) { |
| 11941 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11942 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11943 | NL80211_CMD_VENDOR); |
| 11944 | if (!hdr) |
| 11945 | break; |
| 11946 | |
| 11947 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11948 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11949 | wdev_id(wdev), |
| 11950 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11951 | genlmsg_cancel(skb, hdr); |
| 11952 | break; |
| 11953 | } |
| 11954 | |
| 11955 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11956 | if (!vendor_data) { |
| 11957 | genlmsg_cancel(skb, hdr); |
| 11958 | break; |
| 11959 | } |
| 11960 | |
| 11961 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11962 | (unsigned long *)&cb->args[5]); |
| 11963 | nla_nest_end(skb, vendor_data); |
| 11964 | |
| 11965 | if (err == -ENOBUFS || err == -ENOENT) { |
| 11966 | genlmsg_cancel(skb, hdr); |
| 11967 | break; |
| 11968 | } else if (err) { |
| 11969 | genlmsg_cancel(skb, hdr); |
| 11970 | goto out; |
| 11971 | } |
| 11972 | |
| 11973 | genlmsg_end(skb, hdr); |
| 11974 | } |
| 11975 | |
| 11976 | err = skb->len; |
| 11977 | out: |
| 11978 | rtnl_unlock(); |
| 11979 | return err; |
| 11980 | } |
| 11981 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11982 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 11983 | enum nl80211_commands cmd, |
| 11984 | enum nl80211_attrs attr, |
| 11985 | int approxlen) |
| 11986 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11987 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11988 | |
| 11989 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 11990 | return NULL; |
| 11991 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 11992 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11993 | rdev->cur_cmd_info->snd_portid, |
| 11994 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 11995 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11996 | } |
| 11997 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 11998 | |
| 11999 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 12000 | { |
| 12001 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 12002 | void *hdr = ((void **)skb->cb)[1]; |
| 12003 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 12004 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 12005 | /* clear CB data for netlink core to own from now on */ |
| 12006 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 12007 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12008 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 12009 | kfree_skb(skb); |
| 12010 | return -EINVAL; |
| 12011 | } |
| 12012 | |
| 12013 | nla_nest_end(skb, data); |
| 12014 | genlmsg_end(skb, hdr); |
| 12015 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 12016 | } |
| 12017 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 12018 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12019 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 12020 | struct genl_info *info) |
| 12021 | { |
| 12022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12023 | struct cfg80211_qos_map *qos_map = NULL; |
| 12024 | struct net_device *dev = info->user_ptr[1]; |
| 12025 | u8 *pos, len, num_des, des_len, des; |
| 12026 | int ret; |
| 12027 | |
| 12028 | if (!rdev->ops->set_qos_map) |
| 12029 | return -EOPNOTSUPP; |
| 12030 | |
| 12031 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 12032 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12033 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12034 | |
| 12035 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 12036 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 12037 | return -EINVAL; |
| 12038 | |
| 12039 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 12040 | if (!qos_map) |
| 12041 | return -ENOMEM; |
| 12042 | |
| 12043 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 12044 | if (num_des) { |
| 12045 | des_len = num_des * |
| 12046 | sizeof(struct cfg80211_dscp_exception); |
| 12047 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 12048 | qos_map->num_des = num_des; |
| 12049 | for (des = 0; des < num_des; des++) { |
| 12050 | if (qos_map->dscp_exception[des].up > 7) { |
| 12051 | kfree(qos_map); |
| 12052 | return -EINVAL; |
| 12053 | } |
| 12054 | } |
| 12055 | pos += des_len; |
| 12056 | } |
| 12057 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 12058 | } |
| 12059 | |
| 12060 | wdev_lock(dev->ieee80211_ptr); |
| 12061 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 12062 | if (!ret) |
| 12063 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 12064 | wdev_unlock(dev->ieee80211_ptr); |
| 12065 | |
| 12066 | kfree(qos_map); |
| 12067 | return ret; |
| 12068 | } |
| 12069 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12070 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12071 | { |
| 12072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12073 | struct net_device *dev = info->user_ptr[1]; |
| 12074 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12075 | const u8 *peer; |
| 12076 | u8 tsid, up; |
| 12077 | u16 admitted_time = 0; |
| 12078 | int err; |
| 12079 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12080 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12081 | return -EOPNOTSUPP; |
| 12082 | |
| 12083 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12084 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12085 | return -EINVAL; |
| 12086 | |
| 12087 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12088 | if (tsid >= IEEE80211_NUM_TIDS) |
| 12089 | return -EINVAL; |
| 12090 | |
| 12091 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 12092 | if (up >= IEEE80211_NUM_UPS) |
| 12093 | return -EINVAL; |
| 12094 | |
| 12095 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12096 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12097 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12098 | * need more attributes for that (e.g. BA session requirement); |
| 12099 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12100 | */ |
| 12101 | return -EINVAL; |
| 12102 | } |
| 12103 | |
| 12104 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12105 | |
| 12106 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12107 | admitted_time = |
| 12108 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12109 | if (!admitted_time) |
| 12110 | return -EINVAL; |
| 12111 | } |
| 12112 | |
| 12113 | wdev_lock(wdev); |
| 12114 | switch (wdev->iftype) { |
| 12115 | case NL80211_IFTYPE_STATION: |
| 12116 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12117 | if (wdev->current_bss) |
| 12118 | break; |
| 12119 | err = -ENOTCONN; |
| 12120 | goto out; |
| 12121 | default: |
| 12122 | err = -EOPNOTSUPP; |
| 12123 | goto out; |
| 12124 | } |
| 12125 | |
| 12126 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12127 | |
| 12128 | out: |
| 12129 | wdev_unlock(wdev); |
| 12130 | return err; |
| 12131 | } |
| 12132 | |
| 12133 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12134 | { |
| 12135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12136 | struct net_device *dev = info->user_ptr[1]; |
| 12137 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12138 | const u8 *peer; |
| 12139 | u8 tsid; |
| 12140 | int err; |
| 12141 | |
| 12142 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12143 | return -EINVAL; |
| 12144 | |
| 12145 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12146 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12147 | |
| 12148 | wdev_lock(wdev); |
| 12149 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12150 | wdev_unlock(wdev); |
| 12151 | |
| 12152 | return err; |
| 12153 | } |
| 12154 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12155 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12156 | struct genl_info *info) |
| 12157 | { |
| 12158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12159 | struct net_device *dev = info->user_ptr[1]; |
| 12160 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12161 | struct cfg80211_chan_def chandef = {}; |
| 12162 | const u8 *addr; |
| 12163 | u8 oper_class; |
| 12164 | int err; |
| 12165 | |
| 12166 | if (!rdev->ops->tdls_channel_switch || |
| 12167 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12168 | return -EOPNOTSUPP; |
| 12169 | |
| 12170 | switch (dev->ieee80211_ptr->iftype) { |
| 12171 | case NL80211_IFTYPE_STATION: |
| 12172 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12173 | break; |
| 12174 | default: |
| 12175 | return -EOPNOTSUPP; |
| 12176 | } |
| 12177 | |
| 12178 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12179 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12180 | return -EINVAL; |
| 12181 | |
| 12182 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12183 | if (err) |
| 12184 | return err; |
| 12185 | |
| 12186 | /* |
| 12187 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12188 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12189 | * specification is not defined for them. |
| 12190 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12191 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12192 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12193 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12194 | return -EINVAL; |
| 12195 | |
| 12196 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12197 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12198 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12199 | return -EINVAL; |
| 12200 | |
| 12201 | /* don't allow switching to DFS channels */ |
| 12202 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12203 | return -EINVAL; |
| 12204 | |
| 12205 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12206 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12207 | |
| 12208 | wdev_lock(wdev); |
| 12209 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12210 | wdev_unlock(wdev); |
| 12211 | |
| 12212 | return err; |
| 12213 | } |
| 12214 | |
| 12215 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12216 | struct genl_info *info) |
| 12217 | { |
| 12218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12219 | struct net_device *dev = info->user_ptr[1]; |
| 12220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12221 | const u8 *addr; |
| 12222 | |
| 12223 | if (!rdev->ops->tdls_channel_switch || |
| 12224 | !rdev->ops->tdls_cancel_channel_switch || |
| 12225 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12226 | return -EOPNOTSUPP; |
| 12227 | |
| 12228 | switch (dev->ieee80211_ptr->iftype) { |
| 12229 | case NL80211_IFTYPE_STATION: |
| 12230 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12231 | break; |
| 12232 | default: |
| 12233 | return -EOPNOTSUPP; |
| 12234 | } |
| 12235 | |
| 12236 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12237 | return -EINVAL; |
| 12238 | |
| 12239 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12240 | |
| 12241 | wdev_lock(wdev); |
| 12242 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12243 | wdev_unlock(wdev); |
| 12244 | |
| 12245 | return 0; |
| 12246 | } |
| 12247 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12248 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12249 | struct genl_info *info) |
| 12250 | { |
| 12251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12252 | struct net_device *dev = info->user_ptr[1]; |
| 12253 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12254 | const struct nlattr *nla; |
| 12255 | bool enabled; |
| 12256 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12257 | if (!rdev->ops->set_multicast_to_unicast) |
| 12258 | return -EOPNOTSUPP; |
| 12259 | |
| 12260 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12261 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12262 | return -EOPNOTSUPP; |
| 12263 | |
| 12264 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12265 | enabled = nla_get_flag(nla); |
| 12266 | |
| 12267 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12268 | } |
| 12269 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 12270 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12271 | { |
| 12272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12273 | struct net_device *dev = info->user_ptr[1]; |
| 12274 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12275 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 12276 | int ret; |
| 12277 | |
| 12278 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12279 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12280 | return -EOPNOTSUPP; |
| 12281 | |
| 12282 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12283 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12284 | return -EOPNOTSUPP; |
| 12285 | |
| 12286 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 12287 | return -EINVAL; |
| 12288 | |
| 12289 | wdev_lock(wdev); |
| 12290 | if (!wdev->current_bss) { |
| 12291 | ret = -ENOTCONN; |
| 12292 | goto out; |
| 12293 | } |
| 12294 | |
| 12295 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12296 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 12297 | ret = -EINVAL; |
| 12298 | goto out; |
| 12299 | } |
| 12300 | |
| 12301 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 12302 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 12303 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 12304 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 12305 | ret = -EINVAL; |
| 12306 | goto out; |
| 12307 | } |
| 12308 | |
| 12309 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 12310 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12311 | |
| 12312 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 12313 | ret = -EINVAL; |
| 12314 | goto out; |
| 12315 | } |
| 12316 | |
| 12317 | pmk_conf.pmk_r0_name = |
| 12318 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12319 | } |
| 12320 | |
| 12321 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 12322 | out: |
| 12323 | wdev_unlock(wdev); |
| 12324 | return ret; |
| 12325 | } |
| 12326 | |
| 12327 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12328 | { |
| 12329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12330 | struct net_device *dev = info->user_ptr[1]; |
| 12331 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12332 | const u8 *aa; |
| 12333 | int ret; |
| 12334 | |
| 12335 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12336 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12337 | return -EOPNOTSUPP; |
| 12338 | |
| 12339 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12340 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12341 | return -EOPNOTSUPP; |
| 12342 | |
| 12343 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12344 | return -EINVAL; |
| 12345 | |
| 12346 | wdev_lock(wdev); |
| 12347 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12348 | ret = rdev_del_pmk(rdev, dev, aa); |
| 12349 | wdev_unlock(wdev); |
| 12350 | |
| 12351 | return ret; |
| 12352 | } |
| 12353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12354 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12355 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12356 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12357 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 12358 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 12359 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12360 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12361 | /* 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] | 12362 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 12363 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12364 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12365 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12366 | 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] | 12367 | struct genl_info *info) |
| 12368 | { |
| 12369 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12370 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12371 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12372 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 12373 | |
| 12374 | if (rtnl) |
| 12375 | rtnl_lock(); |
| 12376 | |
| 12377 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 12378 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12379 | if (IS_ERR(rdev)) { |
| 12380 | if (rtnl) |
| 12381 | rtnl_unlock(); |
| 12382 | return PTR_ERR(rdev); |
| 12383 | } |
| 12384 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12385 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 12386 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12387 | ASSERT_RTNL(); |
| 12388 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12389 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 12390 | info->attrs); |
| 12391 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12392 | if (rtnl) |
| 12393 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12394 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12395 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12396 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12397 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12398 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12399 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12400 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 12401 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12402 | if (rtnl) |
| 12403 | rtnl_unlock(); |
| 12404 | return -EINVAL; |
| 12405 | } |
| 12406 | |
| 12407 | info->user_ptr[1] = dev; |
| 12408 | } else { |
| 12409 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12410 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12411 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12412 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 12413 | !wdev_running(wdev)) { |
| 12414 | if (rtnl) |
| 12415 | rtnl_unlock(); |
| 12416 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12417 | } |
| 12418 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12419 | if (dev) |
| 12420 | dev_hold(dev); |
| 12421 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12422 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12423 | } |
| 12424 | |
| 12425 | return 0; |
| 12426 | } |
| 12427 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12428 | 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] | 12429 | struct genl_info *info) |
| 12430 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12431 | if (info->user_ptr[1]) { |
| 12432 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 12433 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12434 | |
| 12435 | if (wdev->netdev) |
| 12436 | dev_put(wdev->netdev); |
| 12437 | } else { |
| 12438 | dev_put(info->user_ptr[1]); |
| 12439 | } |
| 12440 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12442 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 12443 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12444 | |
| 12445 | /* If needed, clear the netlink message payload from the SKB |
| 12446 | * as it might contain key data that shouldn't stick around on |
| 12447 | * the heap after the SKB is freed. The netlink message header |
| 12448 | * is still needed for further processing, so leave it intact. |
| 12449 | */ |
| 12450 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 12451 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 12452 | |
| 12453 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 12454 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12455 | } |
| 12456 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 12457 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12458 | { |
| 12459 | .cmd = NL80211_CMD_GET_WIPHY, |
| 12460 | .doit = nl80211_get_wiphy, |
| 12461 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12462 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12463 | .policy = nl80211_policy, |
| 12464 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12465 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12466 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12467 | }, |
| 12468 | { |
| 12469 | .cmd = NL80211_CMD_SET_WIPHY, |
| 12470 | .doit = nl80211_set_wiphy, |
| 12471 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12472 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12473 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12474 | }, |
| 12475 | { |
| 12476 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 12477 | .doit = nl80211_get_interface, |
| 12478 | .dumpit = nl80211_dump_interface, |
| 12479 | .policy = nl80211_policy, |
| 12480 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12481 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12482 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12483 | }, |
| 12484 | { |
| 12485 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 12486 | .doit = nl80211_set_interface, |
| 12487 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12488 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12489 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12490 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12491 | }, |
| 12492 | { |
| 12493 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 12494 | .doit = nl80211_new_interface, |
| 12495 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12496 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12497 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12498 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12499 | }, |
| 12500 | { |
| 12501 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 12502 | .doit = nl80211_del_interface, |
| 12503 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12504 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 12505 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12506 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12507 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12508 | { |
| 12509 | .cmd = NL80211_CMD_GET_KEY, |
| 12510 | .doit = nl80211_get_key, |
| 12511 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12512 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12514 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12515 | }, |
| 12516 | { |
| 12517 | .cmd = NL80211_CMD_SET_KEY, |
| 12518 | .doit = nl80211_set_key, |
| 12519 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12520 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12522 | NL80211_FLAG_NEED_RTNL | |
| 12523 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12524 | }, |
| 12525 | { |
| 12526 | .cmd = NL80211_CMD_NEW_KEY, |
| 12527 | .doit = nl80211_new_key, |
| 12528 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12529 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12531 | NL80211_FLAG_NEED_RTNL | |
| 12532 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12533 | }, |
| 12534 | { |
| 12535 | .cmd = NL80211_CMD_DEL_KEY, |
| 12536 | .doit = nl80211_del_key, |
| 12537 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12538 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12539 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12540 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12541 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12542 | { |
| 12543 | .cmd = NL80211_CMD_SET_BEACON, |
| 12544 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12545 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12546 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12548 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12549 | }, |
| 12550 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12551 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12552 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12553 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12554 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12556 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12557 | }, |
| 12558 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12559 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12560 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12561 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12562 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12564 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12565 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12566 | { |
| 12567 | .cmd = NL80211_CMD_GET_STATION, |
| 12568 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12569 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12570 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12571 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12572 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12573 | }, |
| 12574 | { |
| 12575 | .cmd = NL80211_CMD_SET_STATION, |
| 12576 | .doit = nl80211_set_station, |
| 12577 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12578 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12580 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12581 | }, |
| 12582 | { |
| 12583 | .cmd = NL80211_CMD_NEW_STATION, |
| 12584 | .doit = nl80211_new_station, |
| 12585 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12586 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12587 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12588 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12589 | }, |
| 12590 | { |
| 12591 | .cmd = NL80211_CMD_DEL_STATION, |
| 12592 | .doit = nl80211_del_station, |
| 12593 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12594 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12596 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12597 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12598 | { |
| 12599 | .cmd = NL80211_CMD_GET_MPATH, |
| 12600 | .doit = nl80211_get_mpath, |
| 12601 | .dumpit = nl80211_dump_mpath, |
| 12602 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12603 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12604 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12605 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12606 | }, |
| 12607 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12608 | .cmd = NL80211_CMD_GET_MPP, |
| 12609 | .doit = nl80211_get_mpp, |
| 12610 | .dumpit = nl80211_dump_mpp, |
| 12611 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12612 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12614 | NL80211_FLAG_NEED_RTNL, |
| 12615 | }, |
| 12616 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12617 | .cmd = NL80211_CMD_SET_MPATH, |
| 12618 | .doit = nl80211_set_mpath, |
| 12619 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12620 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12622 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12623 | }, |
| 12624 | { |
| 12625 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12626 | .doit = nl80211_new_mpath, |
| 12627 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12628 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12630 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12631 | }, |
| 12632 | { |
| 12633 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12634 | .doit = nl80211_del_mpath, |
| 12635 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12639 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12640 | { |
| 12641 | .cmd = NL80211_CMD_SET_BSS, |
| 12642 | .doit = nl80211_set_bss, |
| 12643 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12644 | .flags = GENL_UNS_ADMIN_PERM, |
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, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12647 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12648 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12649 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12650 | .doit = nl80211_get_reg_do, |
| 12651 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12652 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12653 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12654 | /* can be retrieved by unprivileged users */ |
| 12655 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12656 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12657 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12658 | .cmd = NL80211_CMD_SET_REG, |
| 12659 | .doit = nl80211_set_reg, |
| 12660 | .policy = nl80211_policy, |
| 12661 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12662 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12663 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12664 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12665 | { |
| 12666 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12667 | .doit = nl80211_req_set_reg, |
| 12668 | .policy = nl80211_policy, |
| 12669 | .flags = GENL_ADMIN_PERM, |
| 12670 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12671 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12672 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12673 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12674 | .policy = nl80211_policy, |
| 12675 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12676 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12677 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12678 | }, |
| 12679 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12680 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12681 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12682 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12683 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12684 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12685 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12686 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12687 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12688 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12689 | .doit = nl80211_trigger_scan, |
| 12690 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12691 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12692 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12693 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12694 | }, |
| 12695 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12696 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12697 | .doit = nl80211_abort_scan, |
| 12698 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12699 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12700 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12701 | NL80211_FLAG_NEED_RTNL, |
| 12702 | }, |
| 12703 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12704 | .cmd = NL80211_CMD_GET_SCAN, |
| 12705 | .policy = nl80211_policy, |
| 12706 | .dumpit = nl80211_dump_scan, |
| 12707 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12708 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12709 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12710 | .doit = nl80211_start_sched_scan, |
| 12711 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12712 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12713 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12714 | NL80211_FLAG_NEED_RTNL, |
| 12715 | }, |
| 12716 | { |
| 12717 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12718 | .doit = nl80211_stop_sched_scan, |
| 12719 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12720 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12721 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12722 | NL80211_FLAG_NEED_RTNL, |
| 12723 | }, |
| 12724 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12725 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12726 | .doit = nl80211_authenticate, |
| 12727 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12728 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12729 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12730 | NL80211_FLAG_NEED_RTNL | |
| 12731 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12732 | }, |
| 12733 | { |
| 12734 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12735 | .doit = nl80211_associate, |
| 12736 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12737 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12738 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12739 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12740 | }, |
| 12741 | { |
| 12742 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12743 | .doit = nl80211_deauthenticate, |
| 12744 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12745 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12747 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12748 | }, |
| 12749 | { |
| 12750 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12751 | .doit = nl80211_disassociate, |
| 12752 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12753 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12755 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12756 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12757 | { |
| 12758 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12759 | .doit = nl80211_join_ibss, |
| 12760 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12761 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12762 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12763 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12764 | }, |
| 12765 | { |
| 12766 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12767 | .doit = nl80211_leave_ibss, |
| 12768 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12769 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12771 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12772 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12773 | #ifdef CONFIG_NL80211_TESTMODE |
| 12774 | { |
| 12775 | .cmd = NL80211_CMD_TESTMODE, |
| 12776 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12777 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12778 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12779 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12780 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12781 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12782 | }, |
| 12783 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12784 | { |
| 12785 | .cmd = NL80211_CMD_CONNECT, |
| 12786 | .doit = nl80211_connect, |
| 12787 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12788 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12789 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12790 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12791 | }, |
| 12792 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12793 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12794 | .doit = nl80211_update_connect_params, |
| 12795 | .policy = nl80211_policy, |
| 12796 | .flags = GENL_ADMIN_PERM, |
| 12797 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12798 | NL80211_FLAG_NEED_RTNL, |
| 12799 | }, |
| 12800 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12801 | .cmd = NL80211_CMD_DISCONNECT, |
| 12802 | .doit = nl80211_disconnect, |
| 12803 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12804 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12805 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12806 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12807 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12808 | { |
| 12809 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12810 | .doit = nl80211_wiphy_netns, |
| 12811 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12812 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12813 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12814 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12815 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12816 | { |
| 12817 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12818 | .policy = nl80211_policy, |
| 12819 | .dumpit = nl80211_dump_survey, |
| 12820 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12821 | { |
| 12822 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12823 | .doit = nl80211_setdel_pmksa, |
| 12824 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12825 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12826 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12827 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12828 | }, |
| 12829 | { |
| 12830 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12831 | .doit = nl80211_setdel_pmksa, |
| 12832 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12833 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12834 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12835 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12836 | }, |
| 12837 | { |
| 12838 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12839 | .doit = nl80211_flush_pmksa, |
| 12840 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12841 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12844 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12845 | { |
| 12846 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12847 | .doit = nl80211_remain_on_channel, |
| 12848 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12849 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12850 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12851 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12852 | }, |
| 12853 | { |
| 12854 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12855 | .doit = nl80211_cancel_remain_on_channel, |
| 12856 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12857 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12858 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12859 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12860 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12861 | { |
| 12862 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12863 | .doit = nl80211_set_tx_bitrate_mask, |
| 12864 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12865 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12866 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12867 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12868 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12869 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12870 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12871 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12872 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12873 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12874 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12875 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12876 | }, |
| 12877 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12878 | .cmd = NL80211_CMD_FRAME, |
| 12879 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12880 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12881 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12882 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12883 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12884 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12885 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12886 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12887 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12888 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12889 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12890 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12891 | NL80211_FLAG_NEED_RTNL, |
| 12892 | }, |
| 12893 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12894 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12895 | .doit = nl80211_set_power_save, |
| 12896 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12897 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12898 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12899 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12900 | }, |
| 12901 | { |
| 12902 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12903 | .doit = nl80211_get_power_save, |
| 12904 | .policy = nl80211_policy, |
| 12905 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12906 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12907 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12908 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12909 | { |
| 12910 | .cmd = NL80211_CMD_SET_CQM, |
| 12911 | .doit = nl80211_set_cqm, |
| 12912 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12913 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12914 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12915 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12916 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12917 | { |
| 12918 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12919 | .doit = nl80211_set_channel, |
| 12920 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12921 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12922 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12923 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12924 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12925 | { |
| 12926 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12927 | .doit = nl80211_set_wds_peer, |
| 12928 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12929 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12930 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12931 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12932 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12933 | { |
| 12934 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12935 | .doit = nl80211_join_mesh, |
| 12936 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12937 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12939 | NL80211_FLAG_NEED_RTNL, |
| 12940 | }, |
| 12941 | { |
| 12942 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12943 | .doit = nl80211_leave_mesh, |
| 12944 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12945 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12947 | NL80211_FLAG_NEED_RTNL, |
| 12948 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12949 | { |
| 12950 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12951 | .doit = nl80211_join_ocb, |
| 12952 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12953 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12955 | NL80211_FLAG_NEED_RTNL, |
| 12956 | }, |
| 12957 | { |
| 12958 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12959 | .doit = nl80211_leave_ocb, |
| 12960 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12961 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12963 | NL80211_FLAG_NEED_RTNL, |
| 12964 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12965 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12966 | { |
| 12967 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 12968 | .doit = nl80211_get_wowlan, |
| 12969 | .policy = nl80211_policy, |
| 12970 | /* can be retrieved by unprivileged users */ |
| 12971 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12972 | NL80211_FLAG_NEED_RTNL, |
| 12973 | }, |
| 12974 | { |
| 12975 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 12976 | .doit = nl80211_set_wowlan, |
| 12977 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12978 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12979 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12980 | NL80211_FLAG_NEED_RTNL, |
| 12981 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12982 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12983 | { |
| 12984 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 12985 | .doit = nl80211_set_rekey_data, |
| 12986 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12987 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12988 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12989 | NL80211_FLAG_NEED_RTNL | |
| 12990 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12991 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12992 | { |
| 12993 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 12994 | .doit = nl80211_tdls_mgmt, |
| 12995 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12996 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12998 | NL80211_FLAG_NEED_RTNL, |
| 12999 | }, |
| 13000 | { |
| 13001 | .cmd = NL80211_CMD_TDLS_OPER, |
| 13002 | .doit = nl80211_tdls_oper, |
| 13003 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13004 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13005 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13006 | NL80211_FLAG_NEED_RTNL, |
| 13007 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13008 | { |
| 13009 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 13010 | .doit = nl80211_register_unexpected_frame, |
| 13011 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13012 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13013 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13014 | NL80211_FLAG_NEED_RTNL, |
| 13015 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13016 | { |
| 13017 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 13018 | .doit = nl80211_probe_client, |
| 13019 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13020 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13021 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13022 | NL80211_FLAG_NEED_RTNL, |
| 13023 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13024 | { |
| 13025 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 13026 | .doit = nl80211_register_beacons, |
| 13027 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13028 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13029 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13030 | NL80211_FLAG_NEED_RTNL, |
| 13031 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13032 | { |
| 13033 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 13034 | .doit = nl80211_set_noack_map, |
| 13035 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13036 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13037 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13038 | NL80211_FLAG_NEED_RTNL, |
| 13039 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13040 | { |
| 13041 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 13042 | .doit = nl80211_start_p2p_device, |
| 13043 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13044 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13045 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13046 | NL80211_FLAG_NEED_RTNL, |
| 13047 | }, |
| 13048 | { |
| 13049 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 13050 | .doit = nl80211_stop_p2p_device, |
| 13051 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13052 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13053 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13054 | NL80211_FLAG_NEED_RTNL, |
| 13055 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13056 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13057 | .cmd = NL80211_CMD_START_NAN, |
| 13058 | .doit = nl80211_start_nan, |
| 13059 | .policy = nl80211_policy, |
| 13060 | .flags = GENL_ADMIN_PERM, |
| 13061 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13062 | NL80211_FLAG_NEED_RTNL, |
| 13063 | }, |
| 13064 | { |
| 13065 | .cmd = NL80211_CMD_STOP_NAN, |
| 13066 | .doit = nl80211_stop_nan, |
| 13067 | .policy = nl80211_policy, |
| 13068 | .flags = GENL_ADMIN_PERM, |
| 13069 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13070 | NL80211_FLAG_NEED_RTNL, |
| 13071 | }, |
| 13072 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13073 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 13074 | .doit = nl80211_nan_add_func, |
| 13075 | .policy = nl80211_policy, |
| 13076 | .flags = GENL_ADMIN_PERM, |
| 13077 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13078 | NL80211_FLAG_NEED_RTNL, |
| 13079 | }, |
| 13080 | { |
| 13081 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 13082 | .doit = nl80211_nan_del_func, |
| 13083 | .policy = nl80211_policy, |
| 13084 | .flags = GENL_ADMIN_PERM, |
| 13085 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13086 | NL80211_FLAG_NEED_RTNL, |
| 13087 | }, |
| 13088 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13089 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 13090 | .doit = nl80211_nan_change_config, |
| 13091 | .policy = nl80211_policy, |
| 13092 | .flags = GENL_ADMIN_PERM, |
| 13093 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13094 | NL80211_FLAG_NEED_RTNL, |
| 13095 | }, |
| 13096 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13097 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 13098 | .doit = nl80211_set_mcast_rate, |
| 13099 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13100 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13101 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13102 | NL80211_FLAG_NEED_RTNL, |
| 13103 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13104 | { |
| 13105 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 13106 | .doit = nl80211_set_mac_acl, |
| 13107 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13108 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13109 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13110 | NL80211_FLAG_NEED_RTNL, |
| 13111 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13112 | { |
| 13113 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 13114 | .doit = nl80211_start_radar_detection, |
| 13115 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13116 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13118 | NL80211_FLAG_NEED_RTNL, |
| 13119 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13120 | { |
| 13121 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 13122 | .doit = nl80211_get_protocol_features, |
| 13123 | .policy = nl80211_policy, |
| 13124 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13125 | { |
| 13126 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 13127 | .doit = nl80211_update_ft_ies, |
| 13128 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13129 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13130 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13131 | NL80211_FLAG_NEED_RTNL, |
| 13132 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13133 | { |
| 13134 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 13135 | .doit = nl80211_crit_protocol_start, |
| 13136 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13137 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13138 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13139 | NL80211_FLAG_NEED_RTNL, |
| 13140 | }, |
| 13141 | { |
| 13142 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 13143 | .doit = nl80211_crit_protocol_stop, |
| 13144 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13145 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13146 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13147 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13148 | }, |
| 13149 | { |
| 13150 | .cmd = NL80211_CMD_GET_COALESCE, |
| 13151 | .doit = nl80211_get_coalesce, |
| 13152 | .policy = nl80211_policy, |
| 13153 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13154 | NL80211_FLAG_NEED_RTNL, |
| 13155 | }, |
| 13156 | { |
| 13157 | .cmd = NL80211_CMD_SET_COALESCE, |
| 13158 | .doit = nl80211_set_coalesce, |
| 13159 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13160 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13161 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13162 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13163 | }, |
| 13164 | { |
| 13165 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 13166 | .doit = nl80211_channel_switch, |
| 13167 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13168 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13169 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13170 | NL80211_FLAG_NEED_RTNL, |
| 13171 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13172 | { |
| 13173 | .cmd = NL80211_CMD_VENDOR, |
| 13174 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13175 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13176 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13177 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13178 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13179 | NL80211_FLAG_NEED_RTNL, |
| 13180 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13181 | { |
| 13182 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 13183 | .doit = nl80211_set_qos_map, |
| 13184 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13185 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13186 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13187 | NL80211_FLAG_NEED_RTNL, |
| 13188 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13189 | { |
| 13190 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 13191 | .doit = nl80211_add_tx_ts, |
| 13192 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13193 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13194 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13195 | NL80211_FLAG_NEED_RTNL, |
| 13196 | }, |
| 13197 | { |
| 13198 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 13199 | .doit = nl80211_del_tx_ts, |
| 13200 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13201 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13203 | NL80211_FLAG_NEED_RTNL, |
| 13204 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13205 | { |
| 13206 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 13207 | .doit = nl80211_tdls_channel_switch, |
| 13208 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13209 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13211 | NL80211_FLAG_NEED_RTNL, |
| 13212 | }, |
| 13213 | { |
| 13214 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 13215 | .doit = nl80211_tdls_cancel_channel_switch, |
| 13216 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13217 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13219 | NL80211_FLAG_NEED_RTNL, |
| 13220 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13221 | { |
| 13222 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 13223 | .doit = nl80211_set_multicast_to_unicast, |
| 13224 | .policy = nl80211_policy, |
| 13225 | .flags = GENL_UNS_ADMIN_PERM, |
| 13226 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13227 | NL80211_FLAG_NEED_RTNL, |
| 13228 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13229 | { |
| 13230 | .cmd = NL80211_CMD_SET_PMK, |
| 13231 | .doit = nl80211_set_pmk, |
| 13232 | .policy = nl80211_policy, |
| 13233 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13234 | NL80211_FLAG_NEED_RTNL, |
| 13235 | }, |
| 13236 | { |
| 13237 | .cmd = NL80211_CMD_DEL_PMK, |
| 13238 | .doit = nl80211_del_pmk, |
| 13239 | .policy = nl80211_policy, |
| 13240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13241 | NL80211_FLAG_NEED_RTNL, |
| 13242 | }, |
| 13243 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13244 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13245 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 13246 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 13247 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 13248 | .hdrsize = 0, /* no private header */ |
| 13249 | .version = 1, /* no particular meaning now */ |
| 13250 | .maxattr = NL80211_ATTR_MAX, |
| 13251 | .netnsok = true, |
| 13252 | .pre_doit = nl80211_pre_doit, |
| 13253 | .post_doit = nl80211_post_doit, |
| 13254 | .module = THIS_MODULE, |
| 13255 | .ops = nl80211_ops, |
| 13256 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 13257 | .mcgrps = nl80211_mcgrps, |
| 13258 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 13259 | }; |
| 13260 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13261 | /* notification functions */ |
| 13262 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13263 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 13264 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13265 | { |
| 13266 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13267 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13268 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13269 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13270 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13271 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13273 | if (!msg) |
| 13274 | return; |
| 13275 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13276 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13277 | nlmsg_free(msg); |
| 13278 | return; |
| 13279 | } |
| 13280 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13282 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13283 | } |
| 13284 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13285 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13286 | struct wireless_dev *wdev, |
| 13287 | enum nl80211_commands cmd) |
| 13288 | { |
| 13289 | struct sk_buff *msg; |
| 13290 | |
| 13291 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13292 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13293 | |
| 13294 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13295 | if (!msg) |
| 13296 | return; |
| 13297 | |
| 13298 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13299 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13300 | nlmsg_free(msg); |
| 13301 | return; |
| 13302 | } |
| 13303 | |
| 13304 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13305 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13306 | } |
| 13307 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13308 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13309 | struct cfg80211_registered_device *rdev) |
| 13310 | { |
| 13311 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13312 | struct nlattr *nest; |
| 13313 | int i; |
| 13314 | |
| 13315 | if (WARN_ON(!req)) |
| 13316 | return 0; |
| 13317 | |
| 13318 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13319 | if (!nest) |
| 13320 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13321 | for (i = 0; i < req->n_ssids; i++) { |
| 13322 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13323 | goto nla_put_failure; |
| 13324 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13325 | nla_nest_end(msg, nest); |
| 13326 | |
| 13327 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13328 | if (!nest) |
| 13329 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13330 | for (i = 0; i < req->n_channels; i++) { |
| 13331 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13332 | goto nla_put_failure; |
| 13333 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13334 | nla_nest_end(msg, nest); |
| 13335 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13336 | if (req->ie && |
| 13337 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 13338 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13339 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13340 | if (req->flags && |
| 13341 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 13342 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 13343 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 13344 | if (req->info.scan_start_tsf && |
| 13345 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 13346 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 13347 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 13348 | req->info.tsf_bssid))) |
| 13349 | goto nla_put_failure; |
| 13350 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13351 | return 0; |
| 13352 | nla_put_failure: |
| 13353 | return -ENOBUFS; |
| 13354 | } |
| 13355 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13356 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13357 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13358 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13359 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13360 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13361 | { |
| 13362 | void *hdr; |
| 13363 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13364 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13365 | if (!hdr) |
| 13366 | return -1; |
| 13367 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13368 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13369 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13370 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13371 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13372 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13373 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13374 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13375 | /* ignore errors and send incomplete event anyway */ |
| 13376 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13377 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13378 | genlmsg_end(msg, hdr); |
| 13379 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13380 | |
| 13381 | nla_put_failure: |
| 13382 | genlmsg_cancel(msg, hdr); |
| 13383 | return -EMSGSIZE; |
| 13384 | } |
| 13385 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13386 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13387 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13388 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13389 | { |
| 13390 | void *hdr; |
| 13391 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13392 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13393 | if (!hdr) |
| 13394 | return -1; |
| 13395 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 13397 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 13398 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 13399 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 13400 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13401 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13402 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13403 | genlmsg_end(msg, hdr); |
| 13404 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13405 | |
| 13406 | nla_put_failure: |
| 13407 | genlmsg_cancel(msg, hdr); |
| 13408 | return -EMSGSIZE; |
| 13409 | } |
| 13410 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13411 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13412 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13413 | { |
| 13414 | struct sk_buff *msg; |
| 13415 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13417 | if (!msg) |
| 13418 | return; |
| 13419 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13420 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13421 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 13422 | nlmsg_free(msg); |
| 13423 | return; |
| 13424 | } |
| 13425 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13426 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13427 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13428 | } |
| 13429 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13430 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 13431 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13432 | { |
| 13433 | struct sk_buff *msg; |
| 13434 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13436 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13437 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13438 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13439 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13440 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 13441 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13442 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13443 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13444 | } |
| 13445 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13446 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13447 | } |
| 13448 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13449 | /* send message created by nl80211_build_scan_msg() */ |
| 13450 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 13451 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13452 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13453 | if (!msg) |
| 13454 | return; |
| 13455 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13456 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13457 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13458 | } |
| 13459 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13460 | 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] | 13461 | { |
| 13462 | struct sk_buff *msg; |
| 13463 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13465 | if (!msg) |
| 13466 | return; |
| 13467 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13468 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13469 | nlmsg_free(msg); |
| 13470 | return; |
| 13471 | } |
| 13472 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13473 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13474 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13475 | } |
| 13476 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13477 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 13478 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13479 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13480 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13481 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 13482 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13483 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13484 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 13485 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13486 | NL80211_REGDOM_TYPE_WORLD)) |
| 13487 | goto nla_put_failure; |
| 13488 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 13489 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13490 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 13491 | goto nla_put_failure; |
| 13492 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 13493 | request->intersect) { |
| 13494 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13495 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 13496 | goto nla_put_failure; |
| 13497 | } else { |
| 13498 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13499 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 13500 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 13501 | request->alpha2)) |
| 13502 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13503 | } |
| 13504 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13505 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 13506 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 13507 | |
| 13508 | if (wiphy && |
| 13509 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 13510 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 13511 | |
| 13512 | if (wiphy && |
| 13513 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 13514 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 13515 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13516 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13517 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13518 | return true; |
| 13519 | |
| 13520 | nla_put_failure: |
| 13521 | return false; |
| 13522 | } |
| 13523 | |
| 13524 | /* |
| 13525 | * This can happen on global regulatory changes or device specific settings |
| 13526 | * based on custom regulatory domains. |
| 13527 | */ |
| 13528 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13529 | struct regulatory_request *request) |
| 13530 | { |
| 13531 | struct sk_buff *msg; |
| 13532 | void *hdr; |
| 13533 | |
| 13534 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13535 | if (!msg) |
| 13536 | return; |
| 13537 | |
| 13538 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13539 | if (!hdr) { |
| 13540 | nlmsg_free(msg); |
| 13541 | return; |
| 13542 | } |
| 13543 | |
| 13544 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13545 | goto nla_put_failure; |
| 13546 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13547 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13548 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13549 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13550 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13551 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13552 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13553 | |
| 13554 | return; |
| 13555 | |
| 13556 | nla_put_failure: |
| 13557 | genlmsg_cancel(msg, hdr); |
| 13558 | nlmsg_free(msg); |
| 13559 | } |
| 13560 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13561 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13562 | struct net_device *netdev, |
| 13563 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13564 | enum nl80211_commands cmd, gfp_t gfp, |
| 13565 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13566 | { |
| 13567 | struct sk_buff *msg; |
| 13568 | void *hdr; |
| 13569 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13570 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13571 | if (!msg) |
| 13572 | return; |
| 13573 | |
| 13574 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13575 | if (!hdr) { |
| 13576 | nlmsg_free(msg); |
| 13577 | return; |
| 13578 | } |
| 13579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13580 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13581 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13582 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13583 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13584 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13585 | if (uapsd_queues >= 0) { |
| 13586 | struct nlattr *nla_wmm = |
| 13587 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13588 | if (!nla_wmm) |
| 13589 | goto nla_put_failure; |
| 13590 | |
| 13591 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13592 | uapsd_queues)) |
| 13593 | goto nla_put_failure; |
| 13594 | |
| 13595 | nla_nest_end(msg, nla_wmm); |
| 13596 | } |
| 13597 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13598 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13599 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13600 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13601 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13602 | return; |
| 13603 | |
| 13604 | nla_put_failure: |
| 13605 | genlmsg_cancel(msg, hdr); |
| 13606 | nlmsg_free(msg); |
| 13607 | } |
| 13608 | |
| 13609 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13610 | struct net_device *netdev, const u8 *buf, |
| 13611 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13612 | { |
| 13613 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13614 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13615 | } |
| 13616 | |
| 13617 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13618 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13619 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13620 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13621 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13622 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13623 | } |
| 13624 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13625 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13626 | struct net_device *netdev, const u8 *buf, |
| 13627 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13628 | { |
| 13629 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13630 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13631 | } |
| 13632 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13633 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13634 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13635 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13636 | { |
| 13637 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13638 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13639 | } |
| 13640 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13641 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13642 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13643 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13644 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13645 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13646 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13647 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13648 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13649 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13650 | if (WARN_ON(len < 2)) |
| 13651 | return; |
| 13652 | |
| 13653 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13654 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13655 | else |
| 13656 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13657 | |
| 13658 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13659 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13660 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13661 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13662 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13663 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13664 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13665 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13666 | { |
| 13667 | struct sk_buff *msg; |
| 13668 | void *hdr; |
| 13669 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13670 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13671 | if (!msg) |
| 13672 | return; |
| 13673 | |
| 13674 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13675 | if (!hdr) { |
| 13676 | nlmsg_free(msg); |
| 13677 | return; |
| 13678 | } |
| 13679 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13680 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13681 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13682 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13683 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13684 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13685 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13686 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13687 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13688 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13689 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13690 | return; |
| 13691 | |
| 13692 | nla_put_failure: |
| 13693 | genlmsg_cancel(msg, hdr); |
| 13694 | nlmsg_free(msg); |
| 13695 | } |
| 13696 | |
| 13697 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13698 | struct net_device *netdev, const u8 *addr, |
| 13699 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13700 | { |
| 13701 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13702 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13703 | } |
| 13704 | |
| 13705 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13706 | struct net_device *netdev, const u8 *addr, |
| 13707 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13708 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13709 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13710 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13711 | } |
| 13712 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13713 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13714 | struct net_device *netdev, |
| 13715 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13716 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13717 | { |
| 13718 | struct sk_buff *msg; |
| 13719 | void *hdr; |
| 13720 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13721 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 13722 | cr->fils_kek_len + cr->pmk_len + |
| 13723 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13724 | if (!msg) |
| 13725 | return; |
| 13726 | |
| 13727 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13728 | if (!hdr) { |
| 13729 | nlmsg_free(msg); |
| 13730 | return; |
| 13731 | } |
| 13732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13733 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13734 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13735 | (cr->bssid && |
| 13736 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13737 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13738 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13739 | cr->status) || |
| 13740 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13741 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13742 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 13743 | cr->timeout_reason))) || |
| 13744 | (cr->req_ie && |
| 13745 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 13746 | (cr->resp_ie && |
| 13747 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13748 | cr->resp_ie)) || |
| 13749 | (cr->update_erp_next_seq_num && |
| 13750 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 13751 | cr->fils_erp_next_seq_num)) || |
| 13752 | (cr->status == WLAN_STATUS_SUCCESS && |
| 13753 | ((cr->fils_kek && |
| 13754 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, |
| 13755 | cr->fils_kek)) || |
| 13756 | (cr->pmk && |
| 13757 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || |
| 13758 | (cr->pmkid && |
| 13759 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13760 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13761 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13762 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13763 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13764 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13765 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13766 | return; |
| 13767 | |
| 13768 | nla_put_failure: |
| 13769 | genlmsg_cancel(msg, hdr); |
| 13770 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13771 | } |
| 13772 | |
| 13773 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13774 | struct net_device *netdev, |
| 13775 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13776 | { |
| 13777 | struct sk_buff *msg; |
| 13778 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13779 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13780 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13781 | 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] | 13782 | if (!msg) |
| 13783 | return; |
| 13784 | |
| 13785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13786 | if (!hdr) { |
| 13787 | nlmsg_free(msg); |
| 13788 | return; |
| 13789 | } |
| 13790 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13791 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13792 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13794 | (info->req_ie && |
| 13795 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 13796 | info->req_ie)) || |
| 13797 | (info->resp_ie && |
| 13798 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Avraham Stern | f45cbe6 | 2017-06-09 13:08:45 +0100 | [diff] [blame] | 13799 | info->resp_ie)) || |
| 13800 | (info->authorized && |
| 13801 | nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13802 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13803 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13804 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13805 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13807 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13808 | return; |
| 13809 | |
| 13810 | nla_put_failure: |
| 13811 | genlmsg_cancel(msg, hdr); |
| 13812 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13813 | } |
| 13814 | |
| 13815 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13816 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13817 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13818 | { |
| 13819 | struct sk_buff *msg; |
| 13820 | void *hdr; |
| 13821 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13822 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13823 | if (!msg) |
| 13824 | return; |
| 13825 | |
| 13826 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13827 | if (!hdr) { |
| 13828 | nlmsg_free(msg); |
| 13829 | return; |
| 13830 | } |
| 13831 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13832 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13833 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13834 | (from_ap && reason && |
| 13835 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13836 | (from_ap && |
| 13837 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13838 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13839 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13840 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13841 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13842 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13843 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13844 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13845 | return; |
| 13846 | |
| 13847 | nla_put_failure: |
| 13848 | genlmsg_cancel(msg, hdr); |
| 13849 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13850 | } |
| 13851 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13852 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13853 | struct net_device *netdev, const u8 *bssid, |
| 13854 | gfp_t gfp) |
| 13855 | { |
| 13856 | struct sk_buff *msg; |
| 13857 | void *hdr; |
| 13858 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13860 | if (!msg) |
| 13861 | return; |
| 13862 | |
| 13863 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13864 | if (!hdr) { |
| 13865 | nlmsg_free(msg); |
| 13866 | return; |
| 13867 | } |
| 13868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13870 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13871 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13872 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13873 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13874 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13875 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13876 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13877 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13878 | return; |
| 13879 | |
| 13880 | nla_put_failure: |
| 13881 | genlmsg_cancel(msg, hdr); |
| 13882 | nlmsg_free(msg); |
| 13883 | } |
| 13884 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13885 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13886 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13887 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13889 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13890 | struct sk_buff *msg; |
| 13891 | void *hdr; |
| 13892 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13893 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13894 | return; |
| 13895 | |
| 13896 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13897 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13898 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13899 | if (!msg) |
| 13900 | return; |
| 13901 | |
| 13902 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13903 | if (!hdr) { |
| 13904 | nlmsg_free(msg); |
| 13905 | return; |
| 13906 | } |
| 13907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13909 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13910 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13911 | (ie_len && ie && |
| 13912 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13913 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13914 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13915 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13916 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13917 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13918 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13919 | return; |
| 13920 | |
| 13921 | nla_put_failure: |
| 13922 | genlmsg_cancel(msg, hdr); |
| 13923 | nlmsg_free(msg); |
| 13924 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13925 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13926 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13927 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13928 | struct net_device *netdev, const u8 *addr, |
| 13929 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13930 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13931 | { |
| 13932 | struct sk_buff *msg; |
| 13933 | void *hdr; |
| 13934 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13935 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13936 | if (!msg) |
| 13937 | return; |
| 13938 | |
| 13939 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 13940 | if (!hdr) { |
| 13941 | nlmsg_free(msg); |
| 13942 | return; |
| 13943 | } |
| 13944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13945 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13946 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13947 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 13948 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 13949 | (key_id != -1 && |
| 13950 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 13951 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 13952 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13953 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13954 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13955 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13956 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13957 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13958 | return; |
| 13959 | |
| 13960 | nla_put_failure: |
| 13961 | genlmsg_cancel(msg, hdr); |
| 13962 | nlmsg_free(msg); |
| 13963 | } |
| 13964 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13965 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 13966 | struct ieee80211_channel *channel_before, |
| 13967 | struct ieee80211_channel *channel_after) |
| 13968 | { |
| 13969 | struct sk_buff *msg; |
| 13970 | void *hdr; |
| 13971 | struct nlattr *nl_freq; |
| 13972 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13973 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13974 | if (!msg) |
| 13975 | return; |
| 13976 | |
| 13977 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 13978 | if (!hdr) { |
| 13979 | nlmsg_free(msg); |
| 13980 | return; |
| 13981 | } |
| 13982 | |
| 13983 | /* |
| 13984 | * Since we are applying the beacon hint to a wiphy we know its |
| 13985 | * wiphy_idx is valid |
| 13986 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13987 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 13988 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13989 | |
| 13990 | /* Before */ |
| 13991 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 13992 | if (!nl_freq) |
| 13993 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13994 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13995 | goto nla_put_failure; |
| 13996 | nla_nest_end(msg, nl_freq); |
| 13997 | |
| 13998 | /* After */ |
| 13999 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 14000 | if (!nl_freq) |
| 14001 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 14002 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14003 | goto nla_put_failure; |
| 14004 | nla_nest_end(msg, nl_freq); |
| 14005 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14006 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14007 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14008 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14009 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14010 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14011 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14012 | |
| 14013 | return; |
| 14014 | |
| 14015 | nla_put_failure: |
| 14016 | genlmsg_cancel(msg, hdr); |
| 14017 | nlmsg_free(msg); |
| 14018 | } |
| 14019 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14020 | static void nl80211_send_remain_on_chan_event( |
| 14021 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14022 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14023 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14024 | unsigned int duration, gfp_t gfp) |
| 14025 | { |
| 14026 | struct sk_buff *msg; |
| 14027 | void *hdr; |
| 14028 | |
| 14029 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14030 | if (!msg) |
| 14031 | return; |
| 14032 | |
| 14033 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14034 | if (!hdr) { |
| 14035 | nlmsg_free(msg); |
| 14036 | return; |
| 14037 | } |
| 14038 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14039 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14040 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14041 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14042 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14043 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14044 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14045 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 14046 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14047 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14048 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14049 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14050 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14051 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 14052 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 14053 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14054 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14055 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14056 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14057 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14058 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14059 | return; |
| 14060 | |
| 14061 | nla_put_failure: |
| 14062 | genlmsg_cancel(msg, hdr); |
| 14063 | nlmsg_free(msg); |
| 14064 | } |
| 14065 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14066 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 14067 | struct ieee80211_channel *chan, |
| 14068 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14069 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14070 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14071 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14072 | |
| 14073 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14074 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14075 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14076 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14077 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14078 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14079 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14080 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 14081 | struct ieee80211_channel *chan, |
| 14082 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14083 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14084 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14085 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14086 | |
| 14087 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14088 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14089 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14090 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14091 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14092 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14093 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 14094 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14095 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14096 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14097 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14098 | struct sk_buff *msg; |
| 14099 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14100 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 14101 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14103 | if (!msg) |
| 14104 | return; |
| 14105 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14106 | 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] | 14107 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14108 | nlmsg_free(msg); |
| 14109 | return; |
| 14110 | } |
| 14111 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14112 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14113 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14114 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14115 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14116 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14117 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 14118 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14119 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14120 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14121 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14122 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14123 | struct station_info empty_sinfo = {}; |
| 14124 | |
| 14125 | if (!sinfo) |
| 14126 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14127 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14128 | trace_cfg80211_del_sta(dev, mac_addr); |
| 14129 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14131 | if (!msg) |
| 14132 | return; |
| 14133 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14134 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 14135 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14136 | nlmsg_free(msg); |
| 14137 | return; |
| 14138 | } |
| 14139 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14140 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14141 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14142 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14143 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14144 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14145 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 14146 | enum nl80211_connect_failed_reason reason, |
| 14147 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14148 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14149 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14150 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14151 | struct sk_buff *msg; |
| 14152 | void *hdr; |
| 14153 | |
| 14154 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 14155 | if (!msg) |
| 14156 | return; |
| 14157 | |
| 14158 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 14159 | if (!hdr) { |
| 14160 | nlmsg_free(msg); |
| 14161 | return; |
| 14162 | } |
| 14163 | |
| 14164 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 14166 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 14167 | goto nla_put_failure; |
| 14168 | |
| 14169 | genlmsg_end(msg, hdr); |
| 14170 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14171 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14172 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14173 | return; |
| 14174 | |
| 14175 | nla_put_failure: |
| 14176 | genlmsg_cancel(msg, hdr); |
| 14177 | nlmsg_free(msg); |
| 14178 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14179 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14180 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14181 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 14182 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14183 | { |
| 14184 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14185 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14186 | struct sk_buff *msg; |
| 14187 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14188 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14189 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14190 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14191 | return false; |
| 14192 | |
| 14193 | msg = nlmsg_new(100, gfp); |
| 14194 | if (!msg) |
| 14195 | return true; |
| 14196 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14197 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14198 | if (!hdr) { |
| 14199 | nlmsg_free(msg); |
| 14200 | return true; |
| 14201 | } |
| 14202 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14203 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14204 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14206 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14207 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14208 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14209 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14210 | return true; |
| 14211 | |
| 14212 | nla_put_failure: |
| 14213 | genlmsg_cancel(msg, hdr); |
| 14214 | nlmsg_free(msg); |
| 14215 | return true; |
| 14216 | } |
| 14217 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14218 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 14219 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14220 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14222 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14223 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14224 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 14225 | |
| 14226 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14227 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 14228 | trace_cfg80211_return_bool(false); |
| 14229 | return false; |
| 14230 | } |
| 14231 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 14232 | addr, gfp); |
| 14233 | trace_cfg80211_return_bool(ret); |
| 14234 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14235 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14236 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 14237 | |
| 14238 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 14239 | const u8 *addr, gfp_t gfp) |
| 14240 | { |
| 14241 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14242 | bool ret; |
| 14243 | |
| 14244 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 14245 | |
| 14246 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14247 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 14248 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 14249 | trace_cfg80211_return_bool(false); |
| 14250 | return false; |
| 14251 | } |
| 14252 | ret = __nl80211_unexpected_frame(dev, |
| 14253 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14254 | addr, gfp); |
| 14255 | trace_cfg80211_return_bool(ret); |
| 14256 | return ret; |
| 14257 | } |
| 14258 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14259 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14260 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14261 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14262 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14263 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14264 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14265 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14266 | struct sk_buff *msg; |
| 14267 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14268 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14269 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14270 | if (!msg) |
| 14271 | return -ENOMEM; |
| 14272 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14273 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14274 | if (!hdr) { |
| 14275 | nlmsg_free(msg); |
| 14276 | return -ENOMEM; |
| 14277 | } |
| 14278 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14279 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14280 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14281 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14282 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14283 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14284 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14285 | (sig_dbm && |
| 14286 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14287 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14288 | (flags && |
| 14289 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14290 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14291 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14292 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14293 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14294 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14295 | |
| 14296 | nla_put_failure: |
| 14297 | genlmsg_cancel(msg, hdr); |
| 14298 | nlmsg_free(msg); |
| 14299 | return -ENOBUFS; |
| 14300 | } |
| 14301 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14302 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14303 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14304 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14305 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14306 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14307 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14308 | struct sk_buff *msg; |
| 14309 | void *hdr; |
| 14310 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14311 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 14312 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14313 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14314 | if (!msg) |
| 14315 | return; |
| 14316 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14317 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14318 | if (!hdr) { |
| 14319 | nlmsg_free(msg); |
| 14320 | return; |
| 14321 | } |
| 14322 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14323 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14324 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14325 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14326 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14327 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14328 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14329 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14330 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14331 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14332 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14333 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14334 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14335 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14336 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14337 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14338 | return; |
| 14339 | |
| 14340 | nla_put_failure: |
| 14341 | genlmsg_cancel(msg, hdr); |
| 14342 | nlmsg_free(msg); |
| 14343 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14344 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14345 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14346 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 14347 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14348 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14349 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14350 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14351 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14352 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14353 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14354 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14355 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14356 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14357 | cb = (void **)msg->cb; |
| 14358 | |
| 14359 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 14360 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14361 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14362 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14363 | } |
| 14364 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14365 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14366 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14367 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14368 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14369 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14370 | goto nla_put_failure; |
| 14371 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14372 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 14373 | if (!cb[1]) |
| 14374 | goto nla_put_failure; |
| 14375 | |
| 14376 | cb[2] = rdev; |
| 14377 | |
| 14378 | return msg; |
| 14379 | nla_put_failure: |
| 14380 | nlmsg_free(msg); |
| 14381 | return NULL; |
| 14382 | } |
| 14383 | |
| 14384 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 14385 | { |
| 14386 | void **cb = (void **)msg->cb; |
| 14387 | struct cfg80211_registered_device *rdev = cb[2]; |
| 14388 | |
| 14389 | nla_nest_end(msg, cb[1]); |
| 14390 | genlmsg_end(msg, cb[0]); |
| 14391 | |
| 14392 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 14393 | |
| 14394 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14395 | NL80211_MCGRP_MLME, gfp); |
| 14396 | } |
| 14397 | |
| 14398 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 14399 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14400 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14401 | { |
| 14402 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14403 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14404 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14405 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14406 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14407 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14408 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 14409 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 14410 | return; |
| 14411 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14412 | if (wdev->cqm_config) { |
| 14413 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 14414 | |
| 14415 | cfg80211_cqm_rssi_update(rdev, dev); |
| 14416 | |
| 14417 | if (rssi_level == 0) |
| 14418 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 14419 | } |
| 14420 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14421 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14422 | if (!msg) |
| 14423 | return; |
| 14424 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14425 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 14426 | rssi_event)) |
| 14427 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14428 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14429 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 14430 | rssi_level)) |
| 14431 | goto nla_put_failure; |
| 14432 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14433 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14434 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14435 | return; |
| 14436 | |
| 14437 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14438 | nlmsg_free(msg); |
| 14439 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14440 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14441 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14442 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 14443 | const u8 *peer, u32 num_packets, |
| 14444 | u32 rate, u32 intvl, gfp_t gfp) |
| 14445 | { |
| 14446 | struct sk_buff *msg; |
| 14447 | |
| 14448 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14449 | if (!msg) |
| 14450 | return; |
| 14451 | |
| 14452 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 14453 | goto nla_put_failure; |
| 14454 | |
| 14455 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 14456 | goto nla_put_failure; |
| 14457 | |
| 14458 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 14459 | goto nla_put_failure; |
| 14460 | |
| 14461 | cfg80211_send_cqm(msg, gfp); |
| 14462 | return; |
| 14463 | |
| 14464 | nla_put_failure: |
| 14465 | nlmsg_free(msg); |
| 14466 | } |
| 14467 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 14468 | |
| 14469 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 14470 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 14471 | { |
| 14472 | struct sk_buff *msg; |
| 14473 | |
| 14474 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 14475 | |
| 14476 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14477 | if (!msg) |
| 14478 | return; |
| 14479 | |
| 14480 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 14481 | goto nla_put_failure; |
| 14482 | |
| 14483 | cfg80211_send_cqm(msg, gfp); |
| 14484 | return; |
| 14485 | |
| 14486 | nla_put_failure: |
| 14487 | nlmsg_free(msg); |
| 14488 | } |
| 14489 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 14490 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14491 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 14492 | { |
| 14493 | struct sk_buff *msg; |
| 14494 | |
| 14495 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14496 | if (!msg) |
| 14497 | return; |
| 14498 | |
| 14499 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 14500 | goto nla_put_failure; |
| 14501 | |
| 14502 | cfg80211_send_cqm(msg, gfp); |
| 14503 | return; |
| 14504 | |
| 14505 | nla_put_failure: |
| 14506 | nlmsg_free(msg); |
| 14507 | } |
| 14508 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 14509 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14510 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 14511 | struct net_device *netdev, const u8 *bssid, |
| 14512 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14513 | { |
| 14514 | struct sk_buff *msg; |
| 14515 | struct nlattr *rekey_attr; |
| 14516 | void *hdr; |
| 14517 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14519 | if (!msg) |
| 14520 | return; |
| 14521 | |
| 14522 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 14523 | if (!hdr) { |
| 14524 | nlmsg_free(msg); |
| 14525 | return; |
| 14526 | } |
| 14527 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14528 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14529 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14530 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14531 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14532 | |
| 14533 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 14534 | if (!rekey_attr) |
| 14535 | goto nla_put_failure; |
| 14536 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14537 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 14538 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 14539 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14540 | |
| 14541 | nla_nest_end(msg, rekey_attr); |
| 14542 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14543 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14544 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14545 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14546 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14547 | return; |
| 14548 | |
| 14549 | nla_put_failure: |
| 14550 | genlmsg_cancel(msg, hdr); |
| 14551 | nlmsg_free(msg); |
| 14552 | } |
| 14553 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14554 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 14555 | const u8 *replay_ctr, gfp_t gfp) |
| 14556 | { |
| 14557 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14558 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14559 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14560 | |
| 14561 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14562 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14563 | } |
| 14564 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14565 | |
| 14566 | static void |
| 14567 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14568 | struct net_device *netdev, int index, |
| 14569 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14570 | { |
| 14571 | struct sk_buff *msg; |
| 14572 | struct nlattr *attr; |
| 14573 | void *hdr; |
| 14574 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14575 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14576 | if (!msg) |
| 14577 | return; |
| 14578 | |
| 14579 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14580 | if (!hdr) { |
| 14581 | nlmsg_free(msg); |
| 14582 | return; |
| 14583 | } |
| 14584 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14585 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14586 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14587 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14588 | |
| 14589 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14590 | if (!attr) |
| 14591 | goto nla_put_failure; |
| 14592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14593 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14594 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14595 | (preauth && |
| 14596 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14597 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14598 | |
| 14599 | nla_nest_end(msg, attr); |
| 14600 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14601 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14602 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14603 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14604 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14605 | return; |
| 14606 | |
| 14607 | nla_put_failure: |
| 14608 | genlmsg_cancel(msg, hdr); |
| 14609 | nlmsg_free(msg); |
| 14610 | } |
| 14611 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14612 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14613 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14614 | { |
| 14615 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14616 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14617 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14618 | |
| 14619 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14620 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14621 | } |
| 14622 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14623 | |
| 14624 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14625 | struct net_device *netdev, |
| 14626 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14627 | gfp_t gfp, |
| 14628 | enum nl80211_commands notif, |
| 14629 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14630 | { |
| 14631 | struct sk_buff *msg; |
| 14632 | void *hdr; |
| 14633 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14634 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14635 | if (!msg) |
| 14636 | return; |
| 14637 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14638 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14639 | if (!hdr) { |
| 14640 | nlmsg_free(msg); |
| 14641 | return; |
| 14642 | } |
| 14643 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14644 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14645 | goto nla_put_failure; |
| 14646 | |
| 14647 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14648 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14649 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14650 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14651 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14652 | goto nla_put_failure; |
| 14653 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14654 | genlmsg_end(msg, hdr); |
| 14655 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14656 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14657 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14658 | return; |
| 14659 | |
| 14660 | nla_put_failure: |
| 14661 | genlmsg_cancel(msg, hdr); |
| 14662 | nlmsg_free(msg); |
| 14663 | } |
| 14664 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14665 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14666 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14667 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14668 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14669 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14670 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14671 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14672 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14673 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14674 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14675 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14676 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14677 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14678 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14679 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14680 | } |
| 14681 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14682 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14683 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14684 | struct cfg80211_chan_def *chandef, |
| 14685 | u8 count) |
| 14686 | { |
| 14687 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14688 | struct wiphy *wiphy = wdev->wiphy; |
| 14689 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14690 | |
| 14691 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14692 | |
| 14693 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14694 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14695 | } |
| 14696 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14697 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14698 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14699 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14700 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14701 | enum nl80211_radar_event event, |
| 14702 | struct net_device *netdev, gfp_t gfp) |
| 14703 | { |
| 14704 | struct sk_buff *msg; |
| 14705 | void *hdr; |
| 14706 | |
| 14707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14708 | if (!msg) |
| 14709 | return; |
| 14710 | |
| 14711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14712 | if (!hdr) { |
| 14713 | nlmsg_free(msg); |
| 14714 | return; |
| 14715 | } |
| 14716 | |
| 14717 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14718 | goto nla_put_failure; |
| 14719 | |
| 14720 | /* NOP and radar events don't need a netdev parameter */ |
| 14721 | if (netdev) { |
| 14722 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14723 | |
| 14724 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14725 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14726 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14727 | goto nla_put_failure; |
| 14728 | } |
| 14729 | |
| 14730 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14731 | goto nla_put_failure; |
| 14732 | |
| 14733 | if (nl80211_send_chandef(msg, chandef)) |
| 14734 | goto nla_put_failure; |
| 14735 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14736 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14737 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14738 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14739 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14740 | return; |
| 14741 | |
| 14742 | nla_put_failure: |
| 14743 | genlmsg_cancel(msg, hdr); |
| 14744 | nlmsg_free(msg); |
| 14745 | } |
| 14746 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14747 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14748 | u64 cookie, bool acked, gfp_t gfp) |
| 14749 | { |
| 14750 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14751 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14752 | struct sk_buff *msg; |
| 14753 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14754 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14755 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14756 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14758 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14759 | if (!msg) |
| 14760 | return; |
| 14761 | |
| 14762 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14763 | if (!hdr) { |
| 14764 | nlmsg_free(msg); |
| 14765 | return; |
| 14766 | } |
| 14767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14768 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14769 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14770 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14771 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14772 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14773 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14774 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14775 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14776 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14777 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14778 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14779 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14780 | return; |
| 14781 | |
| 14782 | nla_put_failure: |
| 14783 | genlmsg_cancel(msg, hdr); |
| 14784 | nlmsg_free(msg); |
| 14785 | } |
| 14786 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14787 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14788 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14789 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14790 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14791 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14792 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14793 | struct sk_buff *msg; |
| 14794 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14795 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14796 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14797 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14798 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14799 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14800 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14801 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14802 | if (!msg) { |
| 14803 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14804 | return; |
| 14805 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14806 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14807 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14808 | if (!hdr) |
| 14809 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14810 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14812 | (freq && |
| 14813 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14814 | (sig_dbm && |
| 14815 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14816 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14817 | goto nla_put_failure; |
| 14818 | |
| 14819 | genlmsg_end(msg, hdr); |
| 14820 | |
| 14821 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14822 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14823 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14824 | return; |
| 14825 | |
| 14826 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14827 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14828 | if (hdr) |
| 14829 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14830 | nlmsg_free(msg); |
| 14831 | } |
| 14832 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14833 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14834 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14835 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14836 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14837 | { |
| 14838 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14839 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14840 | int i, j; |
| 14841 | |
| 14842 | nl_results = nla_nest_start( |
| 14843 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14844 | if (!nl_results) |
| 14845 | return -EMSGSIZE; |
| 14846 | |
| 14847 | for (i = 0; i < nd->n_matches; i++) { |
| 14848 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14849 | |
| 14850 | nl_match = nla_nest_start(msg, i); |
| 14851 | if (!nl_match) |
| 14852 | break; |
| 14853 | |
| 14854 | /* The SSID attribute is optional in nl80211, but for |
| 14855 | * simplicity reasons it's always present in the |
| 14856 | * cfg80211 structure. If a driver can't pass the |
| 14857 | * SSID, that needs to be changed. A zero length SSID |
| 14858 | * is still a valid SSID (wildcard), so it cannot be |
| 14859 | * used for this purpose. |
| 14860 | */ |
| 14861 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14862 | match->ssid.ssid)) { |
| 14863 | nla_nest_cancel(msg, nl_match); |
| 14864 | goto out; |
| 14865 | } |
| 14866 | |
| 14867 | if (match->n_channels) { |
| 14868 | nl_freqs = nla_nest_start( |
| 14869 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14870 | if (!nl_freqs) { |
| 14871 | nla_nest_cancel(msg, nl_match); |
| 14872 | goto out; |
| 14873 | } |
| 14874 | |
| 14875 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14876 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14877 | nla_nest_cancel(msg, nl_freqs); |
| 14878 | nla_nest_cancel(msg, nl_match); |
| 14879 | goto out; |
| 14880 | } |
| 14881 | } |
| 14882 | |
| 14883 | nla_nest_end(msg, nl_freqs); |
| 14884 | } |
| 14885 | |
| 14886 | nla_nest_end(msg, nl_match); |
| 14887 | } |
| 14888 | |
| 14889 | out: |
| 14890 | nla_nest_end(msg, nl_results); |
| 14891 | return 0; |
| 14892 | } |
| 14893 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14894 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14895 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14896 | gfp_t gfp) |
| 14897 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14898 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14899 | struct sk_buff *msg; |
| 14900 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14901 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14902 | |
| 14903 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14904 | |
| 14905 | if (wakeup) |
| 14906 | size += wakeup->packet_present_len; |
| 14907 | |
| 14908 | msg = nlmsg_new(size, gfp); |
| 14909 | if (!msg) |
| 14910 | return; |
| 14911 | |
| 14912 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14913 | if (!hdr) |
| 14914 | goto free_msg; |
| 14915 | |
| 14916 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14917 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14918 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14919 | goto free_msg; |
| 14920 | |
| 14921 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14922 | wdev->netdev->ifindex)) |
| 14923 | goto free_msg; |
| 14924 | |
| 14925 | if (wakeup) { |
| 14926 | struct nlattr *reasons; |
| 14927 | |
| 14928 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14929 | if (!reasons) |
| 14930 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14931 | |
| 14932 | if (wakeup->disconnect && |
| 14933 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14934 | goto free_msg; |
| 14935 | if (wakeup->magic_pkt && |
| 14936 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14937 | goto free_msg; |
| 14938 | if (wakeup->gtk_rekey_failure && |
| 14939 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 14940 | goto free_msg; |
| 14941 | if (wakeup->eap_identity_req && |
| 14942 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 14943 | goto free_msg; |
| 14944 | if (wakeup->four_way_handshake && |
| 14945 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 14946 | goto free_msg; |
| 14947 | if (wakeup->rfkill_release && |
| 14948 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 14949 | goto free_msg; |
| 14950 | |
| 14951 | if (wakeup->pattern_idx >= 0 && |
| 14952 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 14953 | wakeup->pattern_idx)) |
| 14954 | goto free_msg; |
| 14955 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14956 | if (wakeup->tcp_match && |
| 14957 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 14958 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14959 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14960 | if (wakeup->tcp_connlost && |
| 14961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 14962 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14963 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14964 | if (wakeup->tcp_nomoretokens && |
| 14965 | nla_put_flag(msg, |
| 14966 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 14967 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14968 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14969 | if (wakeup->packet) { |
| 14970 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 14971 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 14972 | |
| 14973 | if (!wakeup->packet_80211) { |
| 14974 | pkt_attr = |
| 14975 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 14976 | len_attr = |
| 14977 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 14978 | } |
| 14979 | |
| 14980 | if (wakeup->packet_len && |
| 14981 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 14982 | goto free_msg; |
| 14983 | |
| 14984 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 14985 | wakeup->packet)) |
| 14986 | goto free_msg; |
| 14987 | } |
| 14988 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14989 | if (wakeup->net_detect && |
| 14990 | cfg80211_net_detect_results(msg, wakeup)) |
| 14991 | goto free_msg; |
| 14992 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14993 | nla_nest_end(msg, reasons); |
| 14994 | } |
| 14995 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14996 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14997 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14998 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14999 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15000 | return; |
| 15001 | |
| 15002 | free_msg: |
| 15003 | nlmsg_free(msg); |
| 15004 | } |
| 15005 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 15006 | #endif |
| 15007 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15008 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 15009 | enum nl80211_tdls_operation oper, |
| 15010 | u16 reason_code, gfp_t gfp) |
| 15011 | { |
| 15012 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15013 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15014 | struct sk_buff *msg; |
| 15015 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15016 | |
| 15017 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 15018 | reason_code); |
| 15019 | |
| 15020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15021 | if (!msg) |
| 15022 | return; |
| 15023 | |
| 15024 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 15025 | if (!hdr) { |
| 15026 | nlmsg_free(msg); |
| 15027 | return; |
| 15028 | } |
| 15029 | |
| 15030 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15031 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15032 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 15033 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 15034 | (reason_code > 0 && |
| 15035 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 15036 | goto nla_put_failure; |
| 15037 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15038 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15039 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15040 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15041 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15042 | return; |
| 15043 | |
| 15044 | nla_put_failure: |
| 15045 | genlmsg_cancel(msg, hdr); |
| 15046 | nlmsg_free(msg); |
| 15047 | } |
| 15048 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 15049 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15050 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 15051 | unsigned long state, |
| 15052 | void *_notify) |
| 15053 | { |
| 15054 | struct netlink_notify *notify = _notify; |
| 15055 | struct cfg80211_registered_device *rdev; |
| 15056 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15057 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15058 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 15059 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15060 | return NOTIFY_DONE; |
| 15061 | |
| 15062 | rcu_read_lock(); |
| 15063 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15064 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15065 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 15066 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15067 | list_for_each_entry_rcu(sched_scan_req, |
| 15068 | &rdev->sched_scan_req_list, |
| 15069 | list) { |
| 15070 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 15071 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15072 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15073 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15074 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15075 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 15076 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15077 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15078 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15079 | if (wdev->owner_nlportid == notify->portid) { |
| 15080 | wdev->nl_owner_dead = true; |
| 15081 | schedule_work(&rdev->destroy_work); |
| 15082 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 15083 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15084 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15085 | } |
| 15086 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15087 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15088 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 15089 | list) { |
| 15090 | if (reg->nlportid == notify->portid) { |
| 15091 | list_del(®->list); |
| 15092 | kfree(reg); |
| 15093 | break; |
| 15094 | } |
| 15095 | } |
| 15096 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15097 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15098 | |
| 15099 | rcu_read_unlock(); |
| 15100 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 15101 | /* |
| 15102 | * It is possible that the user space process that is controlling the |
| 15103 | * indoor setting disappeared, so notify the regulatory core. |
| 15104 | */ |
| 15105 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 15106 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15107 | } |
| 15108 | |
| 15109 | static struct notifier_block nl80211_netlink_notifier = { |
| 15110 | .notifier_call = nl80211_netlink_notify, |
| 15111 | }; |
| 15112 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15113 | void cfg80211_ft_event(struct net_device *netdev, |
| 15114 | struct cfg80211_ft_event_params *ft_event) |
| 15115 | { |
| 15116 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15117 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15118 | struct sk_buff *msg; |
| 15119 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15120 | |
| 15121 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 15122 | |
| 15123 | if (!ft_event->target_ap) |
| 15124 | return; |
| 15125 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15126 | msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15127 | if (!msg) |
| 15128 | return; |
| 15129 | |
| 15130 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15131 | if (!hdr) |
| 15132 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15133 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15134 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15135 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15136 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 15137 | goto out; |
| 15138 | |
| 15139 | if (ft_event->ies && |
| 15140 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 15141 | goto out; |
| 15142 | if (ft_event->ric_ies && |
| 15143 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 15144 | ft_event->ric_ies)) |
| 15145 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15146 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15147 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15148 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15149 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15150 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15151 | return; |
| 15152 | out: |
| 15153 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15154 | } |
| 15155 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 15156 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15157 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 15158 | { |
| 15159 | struct cfg80211_registered_device *rdev; |
| 15160 | struct sk_buff *msg; |
| 15161 | void *hdr; |
| 15162 | u32 nlportid; |
| 15163 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15164 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15165 | if (!rdev->crit_proto_nlportid) |
| 15166 | return; |
| 15167 | |
| 15168 | nlportid = rdev->crit_proto_nlportid; |
| 15169 | rdev->crit_proto_nlportid = 0; |
| 15170 | |
| 15171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15172 | if (!msg) |
| 15173 | return; |
| 15174 | |
| 15175 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 15176 | if (!hdr) |
| 15177 | goto nla_put_failure; |
| 15178 | |
| 15179 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15180 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15181 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15182 | goto nla_put_failure; |
| 15183 | |
| 15184 | genlmsg_end(msg, hdr); |
| 15185 | |
| 15186 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15187 | return; |
| 15188 | |
| 15189 | nla_put_failure: |
| 15190 | if (hdr) |
| 15191 | genlmsg_cancel(msg, hdr); |
| 15192 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15193 | } |
| 15194 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 15195 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15196 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 15197 | { |
| 15198 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15199 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15200 | struct sk_buff *msg; |
| 15201 | void *hdr; |
| 15202 | |
| 15203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15204 | if (!msg) |
| 15205 | return; |
| 15206 | |
| 15207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 15208 | if (!hdr) |
| 15209 | goto out; |
| 15210 | |
| 15211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15212 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15213 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15214 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15215 | goto out; |
| 15216 | |
| 15217 | genlmsg_end(msg, hdr); |
| 15218 | |
| 15219 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 15220 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15221 | return; |
| 15222 | out: |
| 15223 | nlmsg_free(msg); |
| 15224 | } |
| 15225 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15226 | /* initialisation/exit functions */ |
| 15227 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15228 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15229 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 15230 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15231 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15232 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15233 | if (err) |
| 15234 | return err; |
| 15235 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15236 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 15237 | if (err) |
| 15238 | goto err_out; |
| 15239 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15240 | return 0; |
| 15241 | err_out: |
| 15242 | genl_unregister_family(&nl80211_fam); |
| 15243 | return err; |
| 15244 | } |
| 15245 | |
| 15246 | void nl80211_exit(void) |
| 15247 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15248 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15249 | genl_unregister_family(&nl80211_fam); |
| 15250 | } |