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); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2125 | /* user input for center_freq is incorrect */ |
| 2126 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2127 | chandef->center_freq1 != nla_get_u32( |
| 2128 | info->attrs[NL80211_ATTR_CENTER_FREQ1])) |
| 2129 | return -EINVAL; |
| 2130 | /* center_freq2 must be zero */ |
| 2131 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2132 | nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2])) |
| 2133 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2136 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2137 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2139 | chandef->width = |
| 2140 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2141 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2142 | chandef->center_freq1 = |
| 2143 | nla_get_u32( |
| 2144 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2145 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2146 | chandef->center_freq2 = |
| 2147 | nla_get_u32( |
| 2148 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2149 | } |
| 2150 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2151 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2152 | return -EINVAL; |
| 2153 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2154 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2155 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2156 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2157 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2158 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2159 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2160 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2161 | return -EINVAL; |
| 2162 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2163 | return 0; |
| 2164 | } |
| 2165 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2166 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2167 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2168 | struct genl_info *info) |
| 2169 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2170 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2171 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2172 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2173 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2174 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2175 | if (dev) |
| 2176 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2177 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2178 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2179 | if (wdev) |
| 2180 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2181 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2182 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2183 | if (result) |
| 2184 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2185 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2186 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2187 | case NL80211_IFTYPE_AP: |
| 2188 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2189 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2190 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2191 | result = -EINVAL; |
| 2192 | break; |
| 2193 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2194 | if (wdev->beacon_interval) { |
| 2195 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2196 | !(rdev->wiphy.features & |
| 2197 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2198 | result = -EBUSY; |
| 2199 | break; |
| 2200 | } |
| 2201 | |
| 2202 | /* Only allow dynamic channel width changes */ |
| 2203 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2204 | result = -EBUSY; |
| 2205 | break; |
| 2206 | } |
| 2207 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2208 | if (result) |
| 2209 | break; |
| 2210 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2211 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2212 | result = 0; |
| 2213 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2214 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2215 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2216 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2217 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2218 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2219 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2220 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2221 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2222 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2223 | |
| 2224 | return result; |
| 2225 | } |
| 2226 | |
| 2227 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2230 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2231 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2232 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2233 | } |
| 2234 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2235 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2236 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2238 | struct net_device *dev = info->user_ptr[1]; |
| 2239 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2240 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2241 | |
| 2242 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2243 | return -EINVAL; |
| 2244 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2245 | if (netif_running(dev)) |
| 2246 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2247 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2248 | if (!rdev->ops->set_wds_peer) |
| 2249 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2250 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2251 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2252 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2253 | |
| 2254 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2255 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2256 | } |
| 2257 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2258 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2259 | { |
| 2260 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2261 | struct net_device *netdev = NULL; |
| 2262 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2263 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2264 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2265 | u32 changed; |
| 2266 | u8 retry_short = 0, retry_long = 0; |
| 2267 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2268 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2269 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2270 | ASSERT_RTNL(); |
| 2271 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2272 | /* |
| 2273 | * Try to find the wiphy and netdev. Normally this |
| 2274 | * function shouldn't need the netdev, but this is |
| 2275 | * done for backward compatibility -- previously |
| 2276 | * setting the channel was done per wiphy, but now |
| 2277 | * it is per netdev. Previous userland like hostapd |
| 2278 | * also passed a netdev to set_wiphy, so that it is |
| 2279 | * possible to let that go to the right netdev! |
| 2280 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2281 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2282 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2283 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2284 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2285 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2286 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2287 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2288 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2289 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2290 | } |
| 2291 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2292 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2293 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2294 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2295 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2296 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2297 | wdev = NULL; |
| 2298 | netdev = NULL; |
| 2299 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2300 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2301 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2302 | |
| 2303 | /* |
| 2304 | * end workaround code, by now the rdev is available |
| 2305 | * and locked, and wdev may or may not be NULL. |
| 2306 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2307 | |
| 2308 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2309 | result = cfg80211_dev_rename( |
| 2310 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2312 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2313 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2314 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2315 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2316 | struct ieee80211_txq_params txq_params; |
| 2317 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2318 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2319 | if (!rdev->ops->set_txq_params) |
| 2320 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2321 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2322 | if (!netdev) |
| 2323 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2324 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2325 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2326 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2327 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2328 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | if (!netif_running(netdev)) |
| 2330 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2331 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2332 | nla_for_each_nested(nl_txq_params, |
| 2333 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2334 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2335 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2336 | nl_txq_params, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 2337 | txq_params_policy, |
| 2338 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2339 | if (result) |
| 2340 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2341 | result = parse_txq_params(tb, &txq_params); |
| 2342 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2343 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2344 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2345 | result = rdev_set_txq_params(rdev, netdev, |
| 2346 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2347 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2348 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2352 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2353 | result = __nl80211_set_channel( |
| 2354 | rdev, |
| 2355 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2356 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2357 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2358 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2359 | } |
| 2360 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2361 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2362 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2363 | enum nl80211_tx_power_setting type; |
| 2364 | int idx, mbm = 0; |
| 2365 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2366 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2367 | txp_wdev = NULL; |
| 2368 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2369 | if (!rdev->ops->set_tx_power) |
| 2370 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2371 | |
| 2372 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2373 | type = nla_get_u32(info->attrs[idx]); |
| 2374 | |
| 2375 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2376 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2377 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2378 | |
| 2379 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2380 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2381 | mbm = nla_get_u32(info->attrs[idx]); |
| 2382 | } |
| 2383 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2384 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2385 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2386 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2387 | } |
| 2388 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2389 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2390 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2391 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2392 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2393 | if ((!rdev->wiphy.available_antennas_tx && |
| 2394 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2395 | !rdev->ops->set_antenna) |
| 2396 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2397 | |
| 2398 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2399 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2400 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2401 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2402 | * available antenna masks, except for the "all" mask */ |
| 2403 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2404 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2405 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2406 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2407 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2408 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2409 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2410 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2411 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2412 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2413 | } |
| 2414 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2415 | changed = 0; |
| 2416 | |
| 2417 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2418 | retry_short = nla_get_u8( |
| 2419 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2420 | if (retry_short == 0) |
| 2421 | return -EINVAL; |
| 2422 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2423 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2424 | } |
| 2425 | |
| 2426 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2427 | retry_long = nla_get_u8( |
| 2428 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2429 | if (retry_long == 0) |
| 2430 | return -EINVAL; |
| 2431 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2432 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2433 | } |
| 2434 | |
| 2435 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2436 | frag_threshold = nla_get_u32( |
| 2437 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2438 | if (frag_threshold < 256) |
| 2439 | return -EINVAL; |
| 2440 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2441 | if (frag_threshold != (u32) -1) { |
| 2442 | /* |
| 2443 | * Fragments (apart from the last one) are required to |
| 2444 | * have even length. Make the fragmentation code |
| 2445 | * simpler by stripping LSB should someone try to use |
| 2446 | * odd threshold value. |
| 2447 | */ |
| 2448 | frag_threshold &= ~0x1; |
| 2449 | } |
| 2450 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2451 | } |
| 2452 | |
| 2453 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2454 | rts_threshold = nla_get_u32( |
| 2455 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2456 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2457 | } |
| 2458 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2459 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2460 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2461 | return -EINVAL; |
| 2462 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2463 | coverage_class = nla_get_u8( |
| 2464 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2465 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2466 | } |
| 2467 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2468 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2469 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2470 | return -EOPNOTSUPP; |
| 2471 | |
| 2472 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2473 | } |
| 2474 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2475 | if (changed) { |
| 2476 | u8 old_retry_short, old_retry_long; |
| 2477 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2478 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2479 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2480 | if (!rdev->ops->set_wiphy_params) |
| 2481 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2482 | |
| 2483 | old_retry_short = rdev->wiphy.retry_short; |
| 2484 | old_retry_long = rdev->wiphy.retry_long; |
| 2485 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2486 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2487 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2488 | |
| 2489 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2490 | rdev->wiphy.retry_short = retry_short; |
| 2491 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2492 | rdev->wiphy.retry_long = retry_long; |
| 2493 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2494 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2495 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2496 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2497 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2498 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2499 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2500 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2501 | if (result) { |
| 2502 | rdev->wiphy.retry_short = old_retry_short; |
| 2503 | rdev->wiphy.retry_long = old_retry_long; |
| 2504 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2505 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2506 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2507 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2508 | } |
| 2509 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2510 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2511 | } |
| 2512 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2513 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2514 | { |
| 2515 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2516 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2517 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2518 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2519 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2520 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2521 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2522 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2523 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2524 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2525 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2526 | chandef->chan->center_freq)) |
| 2527 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2528 | switch (chandef->width) { |
| 2529 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2530 | case NL80211_CHAN_WIDTH_20: |
| 2531 | case NL80211_CHAN_WIDTH_40: |
| 2532 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2533 | cfg80211_get_chandef_type(chandef))) |
| 2534 | return -ENOBUFS; |
| 2535 | break; |
| 2536 | default: |
| 2537 | break; |
| 2538 | } |
| 2539 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2540 | return -ENOBUFS; |
| 2541 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2542 | return -ENOBUFS; |
| 2543 | if (chandef->center_freq2 && |
| 2544 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2545 | return -ENOBUFS; |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2549 | 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] | 2550 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2551 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2552 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2553 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2554 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2555 | void *hdr; |
| 2556 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2557 | if (removal) |
| 2558 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2559 | |
| 2560 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2561 | if (!hdr) |
| 2562 | return -1; |
| 2563 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2564 | if (dev && |
| 2565 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2566 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2567 | goto nla_put_failure; |
| 2568 | |
| 2569 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2570 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2571 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2572 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2573 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2574 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2575 | rdev->devlist_generation ^ |
| 2576 | (cfg80211_rdev_list_generation << 2))) |
| 2577 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2578 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2579 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2580 | int ret; |
| 2581 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2582 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2583 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2584 | if (ret == 0) { |
| 2585 | if (nl80211_send_chandef(msg, &chandef)) |
| 2586 | goto nla_put_failure; |
| 2587 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2588 | } |
| 2589 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2590 | if (rdev->ops->get_tx_power) { |
| 2591 | int dbm, ret; |
| 2592 | |
| 2593 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2594 | if (ret == 0 && |
| 2595 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2596 | DBM_TO_MBM(dbm))) |
| 2597 | goto nla_put_failure; |
| 2598 | } |
| 2599 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2600 | if (wdev->ssid_len) { |
| 2601 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2602 | goto nla_put_failure; |
| 2603 | } |
| 2604 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2605 | genlmsg_end(msg, hdr); |
| 2606 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2607 | |
| 2608 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2609 | genlmsg_cancel(msg, hdr); |
| 2610 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2614 | { |
| 2615 | int wp_idx = 0; |
| 2616 | int if_idx = 0; |
| 2617 | int wp_start = cb->args[0]; |
| 2618 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2619 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2620 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2621 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2622 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2623 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2624 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2625 | if (!cb->args[2]) { |
| 2626 | struct nl80211_dump_wiphy_state state = { |
| 2627 | .filter_wiphy = -1, |
| 2628 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2629 | |
| 2630 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2631 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2632 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2633 | |
| 2634 | filter_wiphy = state.filter_wiphy; |
| 2635 | |
| 2636 | /* |
| 2637 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2638 | * value needed to determine that parsing is necessary. |
| 2639 | */ |
| 2640 | if (filter_wiphy >= 0) |
| 2641 | cb->args[2] = filter_wiphy + 1; |
| 2642 | else |
| 2643 | cb->args[2] = -1; |
| 2644 | } else if (cb->args[2] > 0) { |
| 2645 | filter_wiphy = cb->args[2] - 1; |
| 2646 | } |
| 2647 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2648 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2649 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2650 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2651 | if (wp_idx < wp_start) { |
| 2652 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2653 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2654 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2655 | |
| 2656 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2657 | continue; |
| 2658 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2659 | if_idx = 0; |
| 2660 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2661 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2662 | if (if_idx < if_start) { |
| 2663 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2664 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2665 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2666 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2667 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2668 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2669 | goto out; |
| 2670 | } |
| 2671 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2672 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2673 | |
| 2674 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2675 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2676 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2677 | cb->args[0] = wp_idx; |
| 2678 | cb->args[1] = if_idx; |
| 2679 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2680 | ret = skb->len; |
| 2681 | out_unlock: |
| 2682 | rtnl_unlock(); |
| 2683 | |
| 2684 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2688 | { |
| 2689 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2691 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2692 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2693 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2694 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2696 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2697 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2698 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2699 | nlmsg_free(msg); |
| 2700 | return -ENOBUFS; |
| 2701 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2702 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2703 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2704 | } |
| 2705 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2706 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2707 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2708 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2709 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2710 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2711 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2712 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2713 | }; |
| 2714 | |
| 2715 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2716 | { |
| 2717 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2718 | int flag; |
| 2719 | |
| 2720 | *mntrflags = 0; |
| 2721 | |
| 2722 | if (!nla) |
| 2723 | return -EINVAL; |
| 2724 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2725 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
| 2726 | mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2727 | return -EINVAL; |
| 2728 | |
| 2729 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2730 | if (flags[flag]) |
| 2731 | *mntrflags |= (1<<flag); |
| 2732 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2733 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 2734 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2735 | return 0; |
| 2736 | } |
| 2737 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2738 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 2739 | enum nl80211_iftype type, |
| 2740 | struct genl_info *info, |
| 2741 | struct vif_params *params) |
| 2742 | { |
| 2743 | bool change = false; |
| 2744 | int err; |
| 2745 | |
| 2746 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 2747 | if (type != NL80211_IFTYPE_MONITOR) |
| 2748 | return -EINVAL; |
| 2749 | |
| 2750 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2751 | ¶ms->flags); |
| 2752 | if (err) |
| 2753 | return err; |
| 2754 | |
| 2755 | change = true; |
| 2756 | } |
| 2757 | |
| 2758 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 2759 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2760 | return -EOPNOTSUPP; |
| 2761 | |
| 2762 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2763 | const u8 *mumimo_groups; |
| 2764 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2765 | |
| 2766 | if (type != NL80211_IFTYPE_MONITOR) |
| 2767 | return -EINVAL; |
| 2768 | |
| 2769 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2770 | return -EOPNOTSUPP; |
| 2771 | |
| 2772 | mumimo_groups = |
| 2773 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2774 | |
| 2775 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 2776 | if ((mumimo_groups[0] & BIT(0)) || |
| 2777 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2778 | return -EINVAL; |
| 2779 | |
| 2780 | params->vht_mumimo_groups = mumimo_groups; |
| 2781 | change = true; |
| 2782 | } |
| 2783 | |
| 2784 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2785 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2786 | |
| 2787 | if (type != NL80211_IFTYPE_MONITOR) |
| 2788 | return -EINVAL; |
| 2789 | |
| 2790 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2791 | return -EOPNOTSUPP; |
| 2792 | |
| 2793 | params->vht_mumimo_follow_addr = |
| 2794 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 2795 | change = true; |
| 2796 | } |
| 2797 | |
| 2798 | return change ? 1 : 0; |
| 2799 | } |
| 2800 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2801 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2802 | struct net_device *netdev, u8 use_4addr, |
| 2803 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2804 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2805 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2806 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2807 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2808 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2809 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2810 | |
| 2811 | switch (iftype) { |
| 2812 | case NL80211_IFTYPE_AP_VLAN: |
| 2813 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2814 | return 0; |
| 2815 | break; |
| 2816 | case NL80211_IFTYPE_STATION: |
| 2817 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2818 | return 0; |
| 2819 | break; |
| 2820 | default: |
| 2821 | break; |
| 2822 | } |
| 2823 | |
| 2824 | return -EOPNOTSUPP; |
| 2825 | } |
| 2826 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2827 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2828 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2830 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2831 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2832 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2833 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2834 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2835 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2836 | memset(¶ms, 0, sizeof(params)); |
| 2837 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2838 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2839 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2840 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2841 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2842 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2843 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2844 | if (ntype > NL80211_IFTYPE_MAX) |
| 2845 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2846 | } |
| 2847 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2848 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2849 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2852 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2853 | if (netif_running(dev)) |
| 2854 | return -EBUSY; |
| 2855 | |
| 2856 | wdev_lock(wdev); |
| 2857 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2858 | IEEE80211_MAX_MESH_ID_LEN); |
| 2859 | wdev->mesh_id_up_len = |
| 2860 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2861 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2862 | wdev->mesh_id_up_len); |
| 2863 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2864 | } |
| 2865 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2866 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2867 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2868 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2869 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2870 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2871 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2872 | } else { |
| 2873 | params.use_4addr = -1; |
| 2874 | } |
| 2875 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2876 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 2877 | if (err < 0) |
| 2878 | return err; |
| 2879 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2880 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2881 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2882 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2883 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2884 | else |
| 2885 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2886 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2887 | if (!err && params.use_4addr != -1) |
| 2888 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2889 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2890 | return err; |
| 2891 | } |
| 2892 | |
| 2893 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2896 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2897 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2898 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2899 | int err; |
| 2900 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 2901 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2902 | /* to avoid failing a new interface creation due to pending removal */ |
| 2903 | cfg80211_destroy_ifaces(rdev); |
| 2904 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2905 | memset(¶ms, 0, sizeof(params)); |
| 2906 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2907 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2908 | return -EINVAL; |
| 2909 | |
| 2910 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2911 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2912 | if (type > NL80211_IFTYPE_MAX) |
| 2913 | return -EINVAL; |
| 2914 | } |
| 2915 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2916 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2918 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2919 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2920 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2921 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2922 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2923 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2924 | ETH_ALEN); |
| 2925 | if (!is_valid_ether_addr(params.macaddr)) |
| 2926 | return -EADDRNOTAVAIL; |
| 2927 | } |
| 2928 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2929 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2930 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2931 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2932 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2933 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2934 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2935 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2936 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 2937 | if (err < 0) |
| 2938 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2939 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2940 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2941 | if (!msg) |
| 2942 | return -ENOMEM; |
| 2943 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2944 | wdev = rdev_add_virtual_intf(rdev, |
| 2945 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2946 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2947 | if (WARN_ON(!wdev)) { |
| 2948 | nlmsg_free(msg); |
| 2949 | return -EPROTO; |
| 2950 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2951 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2952 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2953 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2954 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2955 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2956 | wdev->owner_nlportid = info->snd_portid; |
| 2957 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2958 | switch (type) { |
| 2959 | case NL80211_IFTYPE_MESH_POINT: |
| 2960 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2961 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2962 | wdev_lock(wdev); |
| 2963 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2964 | IEEE80211_MAX_MESH_ID_LEN); |
| 2965 | wdev->mesh_id_up_len = |
| 2966 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2967 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2968 | wdev->mesh_id_up_len); |
| 2969 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2970 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2971 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2972 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2973 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2974 | * 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] | 2975 | * through the netdev notifier and must be added here |
| 2976 | */ |
| 2977 | mutex_init(&wdev->mtx); |
| 2978 | INIT_LIST_HEAD(&wdev->event_list); |
| 2979 | spin_lock_init(&wdev->event_lock); |
| 2980 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2981 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2982 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2983 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2984 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2985 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2986 | break; |
| 2987 | default: |
| 2988 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2991 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2992 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2993 | nlmsg_free(msg); |
| 2994 | return -ENOBUFS; |
| 2995 | } |
| 2996 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2997 | /* |
| 2998 | * For wdevs which have no associated netdev object (e.g. of type |
| 2999 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 3000 | * For all other types, the event will be generated from the |
| 3001 | * netdev notifier |
| 3002 | */ |
| 3003 | if (!wdev->netdev) |
| 3004 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3005 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3006 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3010 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3012 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3013 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3014 | if (!rdev->ops->del_virtual_intf) |
| 3015 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3016 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3017 | /* |
| 3018 | * If we remove a wireless device without a netdev then clear |
| 3019 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3020 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3021 | * since the wdev has been freed, unlike with a netdev where |
| 3022 | * we need the dev_put() for the netdev to really be freed. |
| 3023 | */ |
| 3024 | if (!wdev->netdev) |
| 3025 | info->user_ptr[1] = NULL; |
| 3026 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3027 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3028 | } |
| 3029 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3030 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3031 | { |
| 3032 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3033 | struct net_device *dev = info->user_ptr[1]; |
| 3034 | u16 noack_map; |
| 3035 | |
| 3036 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3037 | return -EINVAL; |
| 3038 | |
| 3039 | if (!rdev->ops->set_noack_map) |
| 3040 | return -EOPNOTSUPP; |
| 3041 | |
| 3042 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3043 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3044 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3045 | } |
| 3046 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3047 | struct get_key_cookie { |
| 3048 | struct sk_buff *msg; |
| 3049 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3050 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3051 | }; |
| 3052 | |
| 3053 | static void get_key_callback(void *c, struct key_params *params) |
| 3054 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3055 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3056 | struct get_key_cookie *cookie = c; |
| 3057 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3058 | if ((params->key && |
| 3059 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3060 | params->key_len, params->key)) || |
| 3061 | (params->seq && |
| 3062 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3063 | params->seq_len, params->seq)) || |
| 3064 | (params->cipher && |
| 3065 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3066 | params->cipher))) |
| 3067 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3068 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3069 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3070 | if (!key) |
| 3071 | goto nla_put_failure; |
| 3072 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3073 | if ((params->key && |
| 3074 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3075 | params->key_len, params->key)) || |
| 3076 | (params->seq && |
| 3077 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3078 | params->seq_len, params->seq)) || |
| 3079 | (params->cipher && |
| 3080 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3081 | params->cipher))) |
| 3082 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3083 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3084 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3085 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3086 | |
| 3087 | nla_nest_end(cookie->msg, key); |
| 3088 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3089 | return; |
| 3090 | nla_put_failure: |
| 3091 | cookie->error = 1; |
| 3092 | } |
| 3093 | |
| 3094 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3095 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3097 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3098 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3099 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3100 | const u8 *mac_addr = NULL; |
| 3101 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3102 | struct get_key_cookie cookie = { |
| 3103 | .error = 0, |
| 3104 | }; |
| 3105 | void *hdr; |
| 3106 | struct sk_buff *msg; |
| 3107 | |
| 3108 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3109 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3110 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3111 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3112 | return -EINVAL; |
| 3113 | |
| 3114 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3115 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3116 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3117 | pairwise = !!mac_addr; |
| 3118 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3119 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3120 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3121 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3122 | return -EINVAL; |
| 3123 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3124 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3125 | return -EINVAL; |
| 3126 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3127 | } |
| 3128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3129 | if (!rdev->ops->get_key) |
| 3130 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3131 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3132 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3133 | return -ENOENT; |
| 3134 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3136 | if (!msg) |
| 3137 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3138 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3139 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3140 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3141 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3142 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3143 | |
| 3144 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3145 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3146 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3147 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3148 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3149 | goto nla_put_failure; |
| 3150 | if (mac_addr && |
| 3151 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3152 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3153 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3154 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3155 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3156 | |
| 3157 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3158 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3159 | |
| 3160 | if (cookie.error) |
| 3161 | goto nla_put_failure; |
| 3162 | |
| 3163 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3164 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3165 | |
| 3166 | nla_put_failure: |
| 3167 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3168 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3169 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3170 | return err; |
| 3171 | } |
| 3172 | |
| 3173 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3174 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3175 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3176 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3177 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3178 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3179 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3180 | err = nl80211_parse_key(info, &key); |
| 3181 | if (err) |
| 3182 | return err; |
| 3183 | |
| 3184 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3185 | return -EINVAL; |
| 3186 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3187 | /* only support setting default key */ |
| 3188 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3189 | return -EINVAL; |
| 3190 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3191 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3192 | |
| 3193 | if (key.def) { |
| 3194 | if (!rdev->ops->set_default_key) { |
| 3195 | err = -EOPNOTSUPP; |
| 3196 | goto out; |
| 3197 | } |
| 3198 | |
| 3199 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3200 | if (err) |
| 3201 | goto out; |
| 3202 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3203 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3204 | key.def_uni, key.def_multi); |
| 3205 | |
| 3206 | if (err) |
| 3207 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3208 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3209 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3210 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3211 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3212 | } else { |
| 3213 | if (key.def_uni || !key.def_multi) { |
| 3214 | err = -EINVAL; |
| 3215 | goto out; |
| 3216 | } |
| 3217 | |
| 3218 | if (!rdev->ops->set_default_mgmt_key) { |
| 3219 | err = -EOPNOTSUPP; |
| 3220 | goto out; |
| 3221 | } |
| 3222 | |
| 3223 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3224 | if (err) |
| 3225 | goto out; |
| 3226 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3227 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3228 | if (err) |
| 3229 | goto out; |
| 3230 | |
| 3231 | #ifdef CONFIG_CFG80211_WEXT |
| 3232 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3233 | #endif |
| 3234 | } |
| 3235 | |
| 3236 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3237 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3238 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3239 | return err; |
| 3240 | } |
| 3241 | |
| 3242 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3243 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3245 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3246 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3247 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3248 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3249 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3250 | err = nl80211_parse_key(info, &key); |
| 3251 | if (err) |
| 3252 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3253 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3254 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3255 | return -EINVAL; |
| 3256 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3257 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3258 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3259 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3260 | if (key.type == -1) { |
| 3261 | if (mac_addr) |
| 3262 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3263 | else |
| 3264 | key.type = NL80211_KEYTYPE_GROUP; |
| 3265 | } |
| 3266 | |
| 3267 | /* for now */ |
| 3268 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3269 | key.type != NL80211_KEYTYPE_GROUP) |
| 3270 | return -EINVAL; |
| 3271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3272 | if (!rdev->ops->add_key) |
| 3273 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3274 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3275 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3276 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3277 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3278 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3279 | |
| 3280 | wdev_lock(dev->ieee80211_ptr); |
| 3281 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3282 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3283 | err = rdev_add_key(rdev, dev, key.idx, |
| 3284 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3285 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3286 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3287 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3288 | return err; |
| 3289 | } |
| 3290 | |
| 3291 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3292 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3294 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3295 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3296 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3297 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3298 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3299 | err = nl80211_parse_key(info, &key); |
| 3300 | if (err) |
| 3301 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3302 | |
| 3303 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3304 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3305 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3306 | if (key.type == -1) { |
| 3307 | if (mac_addr) |
| 3308 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3309 | else |
| 3310 | key.type = NL80211_KEYTYPE_GROUP; |
| 3311 | } |
| 3312 | |
| 3313 | /* for now */ |
| 3314 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3315 | key.type != NL80211_KEYTYPE_GROUP) |
| 3316 | return -EINVAL; |
| 3317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3318 | if (!rdev->ops->del_key) |
| 3319 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3320 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3321 | wdev_lock(dev->ieee80211_ptr); |
| 3322 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3323 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3324 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3325 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3326 | err = -ENOENT; |
| 3327 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3328 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3329 | err = rdev_del_key(rdev, dev, key.idx, |
| 3330 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3331 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3332 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3333 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3334 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3335 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3336 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3337 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3338 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3339 | } |
| 3340 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3341 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3342 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3343 | return err; |
| 3344 | } |
| 3345 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3346 | /* This function returns an error or the number of nested attributes */ |
| 3347 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3348 | { |
| 3349 | struct nlattr *attr; |
| 3350 | int n_entries = 0, tmp; |
| 3351 | |
| 3352 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3353 | if (nla_len(attr) != ETH_ALEN) |
| 3354 | return -EINVAL; |
| 3355 | |
| 3356 | n_entries++; |
| 3357 | } |
| 3358 | |
| 3359 | return n_entries; |
| 3360 | } |
| 3361 | |
| 3362 | /* |
| 3363 | * This function parses ACL information and allocates memory for ACL data. |
| 3364 | * On successful return, the calling function is responsible to free the |
| 3365 | * ACL buffer returned by this function. |
| 3366 | */ |
| 3367 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3368 | struct genl_info *info) |
| 3369 | { |
| 3370 | enum nl80211_acl_policy acl_policy; |
| 3371 | struct nlattr *attr; |
| 3372 | struct cfg80211_acl_data *acl; |
| 3373 | int i = 0, n_entries, tmp; |
| 3374 | |
| 3375 | if (!wiphy->max_acl_mac_addrs) |
| 3376 | return ERR_PTR(-EOPNOTSUPP); |
| 3377 | |
| 3378 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3379 | return ERR_PTR(-EINVAL); |
| 3380 | |
| 3381 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3382 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3383 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3384 | return ERR_PTR(-EINVAL); |
| 3385 | |
| 3386 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3387 | return ERR_PTR(-EINVAL); |
| 3388 | |
| 3389 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3390 | if (n_entries < 0) |
| 3391 | return ERR_PTR(n_entries); |
| 3392 | |
| 3393 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3394 | return ERR_PTR(-ENOTSUPP); |
| 3395 | |
| 3396 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3397 | GFP_KERNEL); |
| 3398 | if (!acl) |
| 3399 | return ERR_PTR(-ENOMEM); |
| 3400 | |
| 3401 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3402 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3403 | i++; |
| 3404 | } |
| 3405 | |
| 3406 | acl->n_acl_entries = n_entries; |
| 3407 | acl->acl_policy = acl_policy; |
| 3408 | |
| 3409 | return acl; |
| 3410 | } |
| 3411 | |
| 3412 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3413 | { |
| 3414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3415 | struct net_device *dev = info->user_ptr[1]; |
| 3416 | struct cfg80211_acl_data *acl; |
| 3417 | int err; |
| 3418 | |
| 3419 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3420 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3421 | return -EOPNOTSUPP; |
| 3422 | |
| 3423 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3424 | return -EINVAL; |
| 3425 | |
| 3426 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3427 | if (IS_ERR(acl)) |
| 3428 | return PTR_ERR(acl); |
| 3429 | |
| 3430 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3431 | |
| 3432 | kfree(acl); |
| 3433 | |
| 3434 | return err; |
| 3435 | } |
| 3436 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3437 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3438 | u8 *rates, u8 rates_len) |
| 3439 | { |
| 3440 | u8 i; |
| 3441 | u32 mask = 0; |
| 3442 | |
| 3443 | for (i = 0; i < rates_len; i++) { |
| 3444 | int rate = (rates[i] & 0x7f) * 5; |
| 3445 | int ridx; |
| 3446 | |
| 3447 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3448 | struct ieee80211_rate *srate = |
| 3449 | &sband->bitrates[ridx]; |
| 3450 | if (rate == srate->bitrate) { |
| 3451 | mask |= 1 << ridx; |
| 3452 | break; |
| 3453 | } |
| 3454 | } |
| 3455 | if (ridx == sband->n_bitrates) |
| 3456 | return 0; /* rate not found */ |
| 3457 | } |
| 3458 | |
| 3459 | return mask; |
| 3460 | } |
| 3461 | |
| 3462 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3463 | u8 *rates, u8 rates_len, |
| 3464 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3465 | { |
| 3466 | u8 i; |
| 3467 | |
| 3468 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3469 | |
| 3470 | for (i = 0; i < rates_len; i++) { |
| 3471 | int ridx, rbit; |
| 3472 | |
| 3473 | ridx = rates[i] / 8; |
| 3474 | rbit = BIT(rates[i] % 8); |
| 3475 | |
| 3476 | /* check validity */ |
| 3477 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3478 | return false; |
| 3479 | |
| 3480 | /* check availability */ |
| 3481 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3482 | mcs[ridx] |= rbit; |
| 3483 | else |
| 3484 | return false; |
| 3485 | } |
| 3486 | |
| 3487 | return true; |
| 3488 | } |
| 3489 | |
| 3490 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3491 | { |
| 3492 | u16 mcs_mask = 0; |
| 3493 | |
| 3494 | switch (vht_mcs_map) { |
| 3495 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3496 | break; |
| 3497 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3498 | mcs_mask = 0x00FF; |
| 3499 | break; |
| 3500 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3501 | mcs_mask = 0x01FF; |
| 3502 | break; |
| 3503 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3504 | mcs_mask = 0x03FF; |
| 3505 | break; |
| 3506 | default: |
| 3507 | break; |
| 3508 | } |
| 3509 | |
| 3510 | return mcs_mask; |
| 3511 | } |
| 3512 | |
| 3513 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3514 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3515 | { |
| 3516 | u8 nss; |
| 3517 | |
| 3518 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3519 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3520 | vht_mcs_map >>= 2; |
| 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3525 | struct nl80211_txrate_vht *txrate, |
| 3526 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3527 | { |
| 3528 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3529 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3530 | u8 i; |
| 3531 | |
| 3532 | if (!sband->vht_cap.vht_supported) |
| 3533 | return false; |
| 3534 | |
| 3535 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3536 | |
| 3537 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3538 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3539 | |
| 3540 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3541 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3542 | mcs[i] = txrate->mcs[i]; |
| 3543 | else |
| 3544 | return false; |
| 3545 | } |
| 3546 | |
| 3547 | return true; |
| 3548 | } |
| 3549 | |
| 3550 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3551 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3552 | .len = NL80211_MAX_SUPP_RATES }, |
| 3553 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3554 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3555 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3556 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3557 | }; |
| 3558 | |
| 3559 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3560 | struct cfg80211_bitrate_mask *mask) |
| 3561 | { |
| 3562 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3564 | int rem, i; |
| 3565 | struct nlattr *tx_rates; |
| 3566 | struct ieee80211_supported_band *sband; |
| 3567 | u16 vht_tx_mcs_map; |
| 3568 | |
| 3569 | memset(mask, 0, sizeof(*mask)); |
| 3570 | /* Default to all rates enabled */ |
| 3571 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3572 | sband = rdev->wiphy.bands[i]; |
| 3573 | |
| 3574 | if (!sband) |
| 3575 | continue; |
| 3576 | |
| 3577 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3578 | memcpy(mask->control[i].ht_mcs, |
| 3579 | sband->ht_cap.mcs.rx_mask, |
| 3580 | sizeof(mask->control[i].ht_mcs)); |
| 3581 | |
| 3582 | if (!sband->vht_cap.vht_supported) |
| 3583 | continue; |
| 3584 | |
| 3585 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3586 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3587 | } |
| 3588 | |
| 3589 | /* if no rates are given set it back to the defaults */ |
| 3590 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3591 | goto out; |
| 3592 | |
| 3593 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3594 | * directly to the enum nl80211_band values used in cfg80211. |
| 3595 | */ |
| 3596 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3597 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3598 | enum nl80211_band band = nla_type(tx_rates); |
| 3599 | int err; |
| 3600 | |
| 3601 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3602 | return -EINVAL; |
| 3603 | sband = rdev->wiphy.bands[band]; |
| 3604 | if (sband == NULL) |
| 3605 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3606 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 3607 | nl80211_txattr_policy, info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3608 | if (err) |
| 3609 | return err; |
| 3610 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3611 | mask->control[band].legacy = rateset_to_mask( |
| 3612 | sband, |
| 3613 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3614 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3615 | if ((mask->control[band].legacy == 0) && |
| 3616 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3617 | return -EINVAL; |
| 3618 | } |
| 3619 | if (tb[NL80211_TXRATE_HT]) { |
| 3620 | if (!ht_rateset_to_mask( |
| 3621 | sband, |
| 3622 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3623 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3624 | mask->control[band].ht_mcs)) |
| 3625 | return -EINVAL; |
| 3626 | } |
| 3627 | if (tb[NL80211_TXRATE_VHT]) { |
| 3628 | if (!vht_set_mcs_mask( |
| 3629 | sband, |
| 3630 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3631 | mask->control[band].vht_mcs)) |
| 3632 | return -EINVAL; |
| 3633 | } |
| 3634 | if (tb[NL80211_TXRATE_GI]) { |
| 3635 | mask->control[band].gi = |
| 3636 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3637 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3638 | return -EINVAL; |
| 3639 | } |
| 3640 | |
| 3641 | if (mask->control[band].legacy == 0) { |
| 3642 | /* don't allow empty legacy rates if HT or VHT |
| 3643 | * are not even supported. |
| 3644 | */ |
| 3645 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3646 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3647 | return -EINVAL; |
| 3648 | |
| 3649 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3650 | if (mask->control[band].ht_mcs[i]) |
| 3651 | goto out; |
| 3652 | |
| 3653 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3654 | if (mask->control[band].vht_mcs[i]) |
| 3655 | goto out; |
| 3656 | |
| 3657 | /* legacy and mcs rates may not be both empty */ |
| 3658 | return -EINVAL; |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | out: |
| 3663 | return 0; |
| 3664 | } |
| 3665 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3666 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3667 | enum nl80211_band band, |
| 3668 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3669 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3670 | u32 count_ht, count_vht, i; |
| 3671 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3672 | |
| 3673 | /* Allow only one rate */ |
| 3674 | if (hweight32(rate) > 1) |
| 3675 | return -EINVAL; |
| 3676 | |
| 3677 | count_ht = 0; |
| 3678 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3679 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3680 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3681 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3682 | count_ht++; |
| 3683 | if (count_ht > 1) |
| 3684 | return -EINVAL; |
| 3685 | } |
| 3686 | if (count_ht && rate) |
| 3687 | return -EINVAL; |
| 3688 | } |
| 3689 | |
| 3690 | count_vht = 0; |
| 3691 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3692 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3693 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3694 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3695 | count_vht++; |
| 3696 | if (count_vht > 1) |
| 3697 | return -EINVAL; |
| 3698 | } |
| 3699 | if (count_vht && rate) |
| 3700 | return -EINVAL; |
| 3701 | } |
| 3702 | |
| 3703 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3704 | return -EINVAL; |
| 3705 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3706 | if (rate && |
| 3707 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3708 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3709 | return -EINVAL; |
| 3710 | if (count_ht && |
| 3711 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3712 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3713 | return -EINVAL; |
| 3714 | if (count_vht && |
| 3715 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3716 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3717 | return -EINVAL; |
| 3718 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3719 | return 0; |
| 3720 | } |
| 3721 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3722 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3723 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3724 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3725 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3726 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3727 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3728 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3729 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3730 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3731 | return -EINVAL; |
| 3732 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3733 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3734 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3735 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3736 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3737 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3738 | if (!bcn->head_len) |
| 3739 | return -EINVAL; |
| 3740 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3741 | } |
| 3742 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3743 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3744 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3745 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3746 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3747 | } |
| 3748 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3749 | if (!haveinfo) |
| 3750 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3751 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3752 | if (attrs[NL80211_ATTR_IE]) { |
| 3753 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3754 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3755 | } |
| 3756 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3757 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3758 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3759 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3760 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3761 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3762 | } |
| 3763 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3764 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3765 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3766 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3767 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3768 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3769 | } |
| 3770 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3771 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3772 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3773 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3774 | } |
| 3775 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3776 | return 0; |
| 3777 | } |
| 3778 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3779 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 3780 | const u8 *rates) |
| 3781 | { |
| 3782 | int i; |
| 3783 | |
| 3784 | if (!rates) |
| 3785 | return; |
| 3786 | |
| 3787 | for (i = 0; i < rates[1]; i++) { |
| 3788 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 3789 | params->ht_required = true; |
| 3790 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 3791 | params->vht_required = true; |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /* |
| 3796 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 3797 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 3798 | * benefit of drivers that rebuild IEs in the firmware. |
| 3799 | */ |
| 3800 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 3801 | { |
| 3802 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 3803 | size_t ies_len = bcn->tail_len; |
| 3804 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3805 | const u8 *rates; |
| 3806 | const u8 *cap; |
| 3807 | |
| 3808 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 3809 | nl80211_check_ap_rate_selectors(params, rates); |
| 3810 | |
| 3811 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 3812 | nl80211_check_ap_rate_selectors(params, rates); |
| 3813 | |
| 3814 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 3815 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 3816 | params->ht_cap = (void *)(cap + 2); |
| 3817 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 3818 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 3819 | params->vht_cap = (void *)(cap + 2); |
| 3820 | } |
| 3821 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3822 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3823 | struct cfg80211_ap_settings *params) |
| 3824 | { |
| 3825 | struct wireless_dev *wdev; |
| 3826 | bool ret = false; |
| 3827 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3828 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3829 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3830 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3831 | continue; |
| 3832 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3833 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3834 | continue; |
| 3835 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3836 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3837 | ret = true; |
| 3838 | break; |
| 3839 | } |
| 3840 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3841 | return ret; |
| 3842 | } |
| 3843 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3844 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3845 | enum nl80211_auth_type auth_type, |
| 3846 | enum nl80211_commands cmd) |
| 3847 | { |
| 3848 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3849 | return false; |
| 3850 | |
| 3851 | switch (cmd) { |
| 3852 | case NL80211_CMD_AUTHENTICATE: |
| 3853 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3854 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3855 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3856 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3857 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3858 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3859 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3860 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3861 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3862 | return true; |
| 3863 | case NL80211_CMD_CONNECT: |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3864 | /* SAE not supported yet */ |
| 3865 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3866 | return false; |
| 3867 | /* FILS with SK PFS or PK not supported yet */ |
| 3868 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3869 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3870 | return false; |
| 3871 | if (!wiphy_ext_feature_isset( |
| 3872 | &rdev->wiphy, |
| 3873 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 3874 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 3875 | return false; |
| 3876 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3877 | case NL80211_CMD_START_AP: |
| 3878 | /* SAE not supported yet */ |
| 3879 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3880 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3881 | /* FILS not supported yet */ |
| 3882 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3883 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3884 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3885 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3886 | return true; |
| 3887 | default: |
| 3888 | return false; |
| 3889 | } |
| 3890 | } |
| 3891 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3892 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3893 | { |
| 3894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3895 | struct net_device *dev = info->user_ptr[1]; |
| 3896 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3897 | struct cfg80211_ap_settings params; |
| 3898 | int err; |
| 3899 | |
| 3900 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3901 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3902 | return -EOPNOTSUPP; |
| 3903 | |
| 3904 | if (!rdev->ops->start_ap) |
| 3905 | return -EOPNOTSUPP; |
| 3906 | |
| 3907 | if (wdev->beacon_interval) |
| 3908 | return -EALREADY; |
| 3909 | |
| 3910 | memset(¶ms, 0, sizeof(params)); |
| 3911 | |
| 3912 | /* these are required for START_AP */ |
| 3913 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3914 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3915 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3916 | return -EINVAL; |
| 3917 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3918 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3919 | if (err) |
| 3920 | return err; |
| 3921 | |
| 3922 | params.beacon_interval = |
| 3923 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3924 | params.dtim_period = |
| 3925 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3926 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3927 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3928 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3929 | if (err) |
| 3930 | return err; |
| 3931 | |
| 3932 | /* |
| 3933 | * In theory, some of these attributes should be required here |
| 3934 | * but since they were not used when the command was originally |
| 3935 | * added, keep them optional for old user space programs to let |
| 3936 | * them continue to work with drivers that do not need the |
| 3937 | * additional information -- drivers must check! |
| 3938 | */ |
| 3939 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3940 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3941 | params.ssid_len = |
| 3942 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3943 | if (params.ssid_len == 0 || |
| 3944 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3945 | return -EINVAL; |
| 3946 | } |
| 3947 | |
| 3948 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3949 | params.hidden_ssid = nla_get_u32( |
| 3950 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3951 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3952 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3953 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3954 | return -EINVAL; |
| 3955 | } |
| 3956 | |
| 3957 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3958 | |
| 3959 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3960 | params.auth_type = nla_get_u32( |
| 3961 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3962 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3963 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3964 | return -EINVAL; |
| 3965 | } else |
| 3966 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3967 | |
| 3968 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3969 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3970 | if (err) |
| 3971 | return err; |
| 3972 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3973 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3974 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3975 | return -EOPNOTSUPP; |
| 3976 | params.inactivity_timeout = nla_get_u16( |
| 3977 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3978 | } |
| 3979 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3980 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3981 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3982 | return -EINVAL; |
| 3983 | params.p2p_ctwindow = |
| 3984 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3985 | if (params.p2p_ctwindow > 127) |
| 3986 | return -EINVAL; |
| 3987 | if (params.p2p_ctwindow != 0 && |
| 3988 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3989 | return -EINVAL; |
| 3990 | } |
| 3991 | |
| 3992 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3993 | u8 tmp; |
| 3994 | |
| 3995 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3996 | return -EINVAL; |
| 3997 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3998 | if (tmp > 1) |
| 3999 | return -EINVAL; |
| 4000 | params.p2p_opp_ps = tmp; |
| 4001 | if (params.p2p_opp_ps != 0 && |
| 4002 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4003 | return -EINVAL; |
| 4004 | } |
| 4005 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4006 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4007 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4008 | if (err) |
| 4009 | return err; |
| 4010 | } else if (wdev->preset_chandef.chan) { |
| 4011 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4012 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4013 | return -EINVAL; |
| 4014 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4015 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4016 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4017 | return -EINVAL; |
| 4018 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4019 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4020 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4021 | if (err) |
| 4022 | return err; |
| 4023 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4024 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4025 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4026 | if (err) |
| 4027 | return err; |
| 4028 | } |
| 4029 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4030 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4031 | params.smps_mode = |
| 4032 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4033 | switch (params.smps_mode) { |
| 4034 | case NL80211_SMPS_OFF: |
| 4035 | break; |
| 4036 | case NL80211_SMPS_STATIC: |
| 4037 | if (!(rdev->wiphy.features & |
| 4038 | NL80211_FEATURE_STATIC_SMPS)) |
| 4039 | return -EINVAL; |
| 4040 | break; |
| 4041 | case NL80211_SMPS_DYNAMIC: |
| 4042 | if (!(rdev->wiphy.features & |
| 4043 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4044 | return -EINVAL; |
| 4045 | break; |
| 4046 | default: |
| 4047 | return -EINVAL; |
| 4048 | } |
| 4049 | } else { |
| 4050 | params.smps_mode = NL80211_SMPS_OFF; |
| 4051 | } |
| 4052 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4053 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4054 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4055 | return -EOPNOTSUPP; |
| 4056 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4057 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4058 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4059 | if (IS_ERR(params.acl)) |
| 4060 | return PTR_ERR(params.acl); |
| 4061 | } |
| 4062 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4063 | nl80211_calculate_ap_params(¶ms); |
| 4064 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4065 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4066 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4067 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4068 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4069 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4070 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4071 | wdev->ssid_len = params.ssid_len; |
| 4072 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4073 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4074 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4075 | |
| 4076 | kfree(params.acl); |
| 4077 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4078 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4079 | } |
| 4080 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4081 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4082 | { |
| 4083 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4084 | struct net_device *dev = info->user_ptr[1]; |
| 4085 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4086 | struct cfg80211_beacon_data params; |
| 4087 | int err; |
| 4088 | |
| 4089 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4090 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4091 | return -EOPNOTSUPP; |
| 4092 | |
| 4093 | if (!rdev->ops->change_beacon) |
| 4094 | return -EOPNOTSUPP; |
| 4095 | |
| 4096 | if (!wdev->beacon_interval) |
| 4097 | return -EINVAL; |
| 4098 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4099 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4100 | if (err) |
| 4101 | return err; |
| 4102 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4103 | wdev_lock(wdev); |
| 4104 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4105 | wdev_unlock(wdev); |
| 4106 | |
| 4107 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | 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] | 4111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4113 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4114 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4115 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4118 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4119 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4120 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4121 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4122 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4123 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4124 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4125 | }; |
| 4126 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4127 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4128 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4129 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4130 | { |
| 4131 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4132 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4133 | int flag; |
| 4134 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4135 | /* |
| 4136 | * Try parsing the new attribute first so userspace |
| 4137 | * can specify both for older kernels. |
| 4138 | */ |
| 4139 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4140 | if (nla) { |
| 4141 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4142 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4143 | sta_flags = nla_data(nla); |
| 4144 | params->sta_flags_mask = sta_flags->mask; |
| 4145 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4146 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4147 | if ((params->sta_flags_mask | |
| 4148 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4149 | return -EINVAL; |
| 4150 | return 0; |
| 4151 | } |
| 4152 | |
| 4153 | /* if present, parse the old attribute */ |
| 4154 | |
| 4155 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4156 | if (!nla) |
| 4157 | return 0; |
| 4158 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 4159 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4160 | sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4161 | return -EINVAL; |
| 4162 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4163 | /* |
| 4164 | * Only allow certain flags for interface types so that |
| 4165 | * other attributes are silently ignored. Remember that |
| 4166 | * this is backward compatibility code with old userspace |
| 4167 | * and shouldn't be hit in other cases anyway. |
| 4168 | */ |
| 4169 | switch (iftype) { |
| 4170 | case NL80211_IFTYPE_AP: |
| 4171 | case NL80211_IFTYPE_AP_VLAN: |
| 4172 | case NL80211_IFTYPE_P2P_GO: |
| 4173 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4174 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4175 | BIT(NL80211_STA_FLAG_WME) | |
| 4176 | BIT(NL80211_STA_FLAG_MFP); |
| 4177 | break; |
| 4178 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4179 | case NL80211_IFTYPE_STATION: |
| 4180 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4181 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4182 | break; |
| 4183 | case NL80211_IFTYPE_MESH_POINT: |
| 4184 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4185 | BIT(NL80211_STA_FLAG_MFP) | |
| 4186 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4187 | default: |
| 4188 | return -EINVAL; |
| 4189 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4190 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4191 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4192 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4193 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4194 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4195 | /* no longer support new API additions in old API */ |
| 4196 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4197 | return -EINVAL; |
| 4198 | } |
| 4199 | } |
| 4200 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4201 | return 0; |
| 4202 | } |
| 4203 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4204 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4205 | int attr) |
| 4206 | { |
| 4207 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4208 | u32 bitrate; |
| 4209 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4210 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4211 | |
| 4212 | rate = nla_nest_start(msg, attr); |
| 4213 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4214 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4215 | |
| 4216 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4217 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4218 | /* report 16-bit bitrate only if we can */ |
| 4219 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4220 | if (bitrate > 0 && |
| 4221 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4222 | return false; |
| 4223 | if (bitrate_compat > 0 && |
| 4224 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4225 | return false; |
| 4226 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4227 | switch (info->bw) { |
| 4228 | case RATE_INFO_BW_5: |
| 4229 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4230 | break; |
| 4231 | case RATE_INFO_BW_10: |
| 4232 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4233 | break; |
| 4234 | default: |
| 4235 | WARN_ON(1); |
| 4236 | /* fall through */ |
| 4237 | case RATE_INFO_BW_20: |
| 4238 | rate_flg = 0; |
| 4239 | break; |
| 4240 | case RATE_INFO_BW_40: |
| 4241 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4242 | break; |
| 4243 | case RATE_INFO_BW_80: |
| 4244 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4245 | break; |
| 4246 | case RATE_INFO_BW_160: |
| 4247 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4248 | break; |
| 4249 | } |
| 4250 | |
| 4251 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4252 | return false; |
| 4253 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4254 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4255 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4256 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4257 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4258 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4259 | return false; |
| 4260 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4261 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4262 | return false; |
| 4263 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4264 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4265 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4266 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4267 | return false; |
| 4268 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4269 | |
| 4270 | nla_nest_end(msg, rate); |
| 4271 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4274 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4275 | int id) |
| 4276 | { |
| 4277 | void *attr; |
| 4278 | int i = 0; |
| 4279 | |
| 4280 | if (!mask) |
| 4281 | return true; |
| 4282 | |
| 4283 | attr = nla_nest_start(msg, id); |
| 4284 | if (!attr) |
| 4285 | return false; |
| 4286 | |
| 4287 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4288 | if (!(mask & BIT(i))) |
| 4289 | continue; |
| 4290 | |
| 4291 | if (nla_put_u8(msg, i, signal[i])) |
| 4292 | return false; |
| 4293 | } |
| 4294 | |
| 4295 | nla_nest_end(msg, attr); |
| 4296 | |
| 4297 | return true; |
| 4298 | } |
| 4299 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4300 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4301 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4302 | struct cfg80211_registered_device *rdev, |
| 4303 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4304 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4305 | { |
| 4306 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4307 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4308 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4309 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4310 | if (!hdr) |
| 4311 | return -1; |
| 4312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4313 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4314 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4315 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4316 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4317 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4318 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4319 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4320 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4321 | |
| 4322 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4323 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4324 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4325 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4326 | sinfo->memb)) \ |
| 4327 | goto nla_put_failure; \ |
| 4328 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4329 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4330 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4331 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4332 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4333 | goto nla_put_failure; \ |
| 4334 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4335 | |
| 4336 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4337 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4338 | |
| 4339 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4340 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4341 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4342 | (u32)sinfo->rx_bytes)) |
| 4343 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4344 | |
| 4345 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4346 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4347 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4348 | (u32)sinfo->tx_bytes)) |
| 4349 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4350 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4351 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4352 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4353 | PUT_SINFO(LLID, llid, u16); |
| 4354 | PUT_SINFO(PLID, plid, u16); |
| 4355 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4356 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4357 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4358 | switch (rdev->wiphy.signal_type) { |
| 4359 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4360 | PUT_SINFO(SIGNAL, signal, u8); |
| 4361 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4362 | break; |
| 4363 | default: |
| 4364 | break; |
| 4365 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4366 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4367 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4368 | sinfo->chain_signal, |
| 4369 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4370 | goto nla_put_failure; |
| 4371 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4372 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4373 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4374 | sinfo->chain_signal_avg, |
| 4375 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4376 | goto nla_put_failure; |
| 4377 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4378 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4379 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4380 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4381 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4382 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4383 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4384 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4385 | NL80211_STA_INFO_RX_BITRATE)) |
| 4386 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4387 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4388 | |
| 4389 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4390 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4391 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4392 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4393 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4394 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4395 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4396 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4397 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4398 | |
| 4399 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4400 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4401 | if (!bss_param) |
| 4402 | goto nla_put_failure; |
| 4403 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4404 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4405 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4406 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4407 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4408 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4409 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4410 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4411 | sinfo->bss_param.dtim_period) || |
| 4412 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4413 | sinfo->bss_param.beacon_interval)) |
| 4414 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4415 | |
| 4416 | nla_nest_end(msg, bss_param); |
| 4417 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4418 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4419 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4420 | sizeof(struct nl80211_sta_flag_update), |
| 4421 | &sinfo->sta_flags)) |
| 4422 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4423 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4424 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4425 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4426 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4427 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4428 | |
| 4429 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4430 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4431 | |
| 4432 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4433 | struct nlattr *tidsattr; |
| 4434 | int tid; |
| 4435 | |
| 4436 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4437 | if (!tidsattr) |
| 4438 | goto nla_put_failure; |
| 4439 | |
| 4440 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4441 | struct cfg80211_tid_stats *tidstats; |
| 4442 | struct nlattr *tidattr; |
| 4443 | |
| 4444 | tidstats = &sinfo->pertid[tid]; |
| 4445 | |
| 4446 | if (!tidstats->filled) |
| 4447 | continue; |
| 4448 | |
| 4449 | tidattr = nla_nest_start(msg, tid + 1); |
| 4450 | if (!tidattr) |
| 4451 | goto nla_put_failure; |
| 4452 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4453 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4454 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4455 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4456 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4457 | goto nla_put_failure; \ |
| 4458 | } while (0) |
| 4459 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4460 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4461 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4462 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4463 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4464 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4465 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4466 | nla_nest_end(msg, tidattr); |
| 4467 | } |
| 4468 | |
| 4469 | nla_nest_end(msg, tidsattr); |
| 4470 | } |
| 4471 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4472 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4473 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4474 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4475 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4476 | sinfo->assoc_req_ies)) |
| 4477 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4478 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4479 | genlmsg_end(msg, hdr); |
| 4480 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4481 | |
| 4482 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4483 | genlmsg_cancel(msg, hdr); |
| 4484 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4487 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4488 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4489 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4490 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4491 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4492 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4493 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4494 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4495 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4496 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4497 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4498 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4499 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4500 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4501 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4502 | if (!wdev->netdev) { |
| 4503 | err = -EINVAL; |
| 4504 | goto out_err; |
| 4505 | } |
| 4506 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4507 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4508 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4509 | goto out_err; |
| 4510 | } |
| 4511 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4512 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4513 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4514 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4515 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4516 | if (err == -ENOENT) |
| 4517 | break; |
| 4518 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4519 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4520 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4521 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4522 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4523 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4524 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4525 | &sinfo) < 0) |
| 4526 | goto out; |
| 4527 | |
| 4528 | sta_idx++; |
| 4529 | } |
| 4530 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4531 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4532 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4533 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4534 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4535 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4536 | |
| 4537 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4538 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4539 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4540 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4541 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4543 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4544 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4545 | struct sk_buff *msg; |
| 4546 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4547 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4548 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4549 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4550 | |
| 4551 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4552 | return -EINVAL; |
| 4553 | |
| 4554 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4555 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4556 | if (!rdev->ops->get_station) |
| 4557 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4558 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4559 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4560 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4562 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4564 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4566 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4567 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4568 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4569 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | nlmsg_free(msg); |
| 4571 | return -ENOBUFS; |
| 4572 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4574 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4575 | } |
| 4576 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4577 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4578 | struct station_parameters *params, |
| 4579 | enum cfg80211_station_type statype) |
| 4580 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4581 | if (params->listen_interval != -1 && |
| 4582 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4583 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4584 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4585 | if (params->support_p2p_ps != -1 && |
| 4586 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4587 | return -EINVAL; |
| 4588 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4589 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4590 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4591 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4592 | return -EINVAL; |
| 4593 | |
| 4594 | /* When you run into this, adjust the code below for the new flag */ |
| 4595 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4596 | |
| 4597 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4598 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4599 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4600 | /* |
| 4601 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4602 | * code doesn't have the bug of including TDLS in the |
| 4603 | * mask everywhere. |
| 4604 | */ |
| 4605 | if (params->sta_flags_mask & |
| 4606 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4607 | BIT(NL80211_STA_FLAG_MFP) | |
| 4608 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4609 | return -EINVAL; |
| 4610 | break; |
| 4611 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4612 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4613 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4614 | return -EINVAL; |
| 4615 | /* ignore since it can't change */ |
| 4616 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4617 | break; |
| 4618 | default: |
| 4619 | /* disallow mesh-specific things */ |
| 4620 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4621 | return -EINVAL; |
| 4622 | if (params->local_pm) |
| 4623 | return -EINVAL; |
| 4624 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4625 | return -EINVAL; |
| 4626 | } |
| 4627 | |
| 4628 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4629 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4630 | /* TDLS can't be set, ... */ |
| 4631 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4632 | return -EINVAL; |
| 4633 | /* |
| 4634 | * ... but don't bother the driver with it. This works around |
| 4635 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4636 | * TLDS_PEER flag in the mask even for AP mode. |
| 4637 | */ |
| 4638 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4639 | } |
| 4640 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4641 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4642 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4643 | /* reject other things that can't change */ |
| 4644 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4645 | return -EINVAL; |
| 4646 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4647 | return -EINVAL; |
| 4648 | if (params->supported_rates) |
| 4649 | return -EINVAL; |
| 4650 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4651 | return -EINVAL; |
| 4652 | } |
| 4653 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4654 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4655 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4656 | if (params->vlan) |
| 4657 | return -EINVAL; |
| 4658 | } |
| 4659 | |
| 4660 | switch (statype) { |
| 4661 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4662 | /* Use this only for authorizing/unauthorizing a station */ |
| 4663 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4664 | return -EOPNOTSUPP; |
| 4665 | break; |
| 4666 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4667 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4668 | /* accept only the listed bits */ |
| 4669 | if (params->sta_flags_mask & |
| 4670 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4671 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4672 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4673 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4674 | BIT(NL80211_STA_FLAG_WME) | |
| 4675 | BIT(NL80211_STA_FLAG_MFP))) |
| 4676 | return -EINVAL; |
| 4677 | |
| 4678 | /* but authenticated/associated only if driver handles it */ |
| 4679 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4680 | params->sta_flags_mask & |
| 4681 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4682 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4683 | return -EINVAL; |
| 4684 | break; |
| 4685 | case CFG80211_STA_IBSS: |
| 4686 | case CFG80211_STA_AP_STA: |
| 4687 | /* reject any changes other than AUTHORIZED */ |
| 4688 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4689 | return -EINVAL; |
| 4690 | break; |
| 4691 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4692 | /* reject any changes other than AUTHORIZED or WME */ |
| 4693 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4694 | BIT(NL80211_STA_FLAG_WME))) |
| 4695 | return -EINVAL; |
| 4696 | /* force (at least) rates when authorizing */ |
| 4697 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4698 | !params->supported_rates) |
| 4699 | return -EINVAL; |
| 4700 | break; |
| 4701 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4702 | /* reject any changes */ |
| 4703 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4704 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4705 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4706 | return -EINVAL; |
| 4707 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4708 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4709 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4710 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4711 | return -EINVAL; |
| 4712 | break; |
| 4713 | } |
| 4714 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4715 | /* |
| 4716 | * Older kernel versions ignored this attribute entirely, so don't |
| 4717 | * reject attempts to update it but mark it as unused instead so the |
| 4718 | * driver won't look at the data. |
| 4719 | */ |
| 4720 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 4721 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 4722 | params->opmode_notif_used = false; |
| 4723 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4724 | return 0; |
| 4725 | } |
| 4726 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4727 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4728 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4729 | * 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] | 4730 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4731 | static struct net_device *get_vlan(struct genl_info *info, |
| 4732 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4733 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4734 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4735 | struct net_device *v; |
| 4736 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4737 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4738 | if (!vlanattr) |
| 4739 | return NULL; |
| 4740 | |
| 4741 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4742 | if (!v) |
| 4743 | return ERR_PTR(-ENODEV); |
| 4744 | |
| 4745 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4746 | ret = -EINVAL; |
| 4747 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4748 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4749 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4750 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4751 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4752 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4753 | ret = -EINVAL; |
| 4754 | goto error; |
| 4755 | } |
| 4756 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4757 | if (!netif_running(v)) { |
| 4758 | ret = -ENETDOWN; |
| 4759 | goto error; |
| 4760 | } |
| 4761 | |
| 4762 | return v; |
| 4763 | error: |
| 4764 | dev_put(v); |
| 4765 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4766 | } |
| 4767 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4768 | static const struct nla_policy |
| 4769 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4770 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4771 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4772 | }; |
| 4773 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4774 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4775 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4776 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4777 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4778 | struct nlattr *nla; |
| 4779 | int err; |
| 4780 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4781 | /* parse WME attributes if present */ |
| 4782 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4783 | return 0; |
| 4784 | |
| 4785 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4786 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 4787 | nl80211_sta_wme_policy, info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4788 | if (err) |
| 4789 | return err; |
| 4790 | |
| 4791 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4792 | params->uapsd_queues = nla_get_u8( |
| 4793 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4794 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4795 | return -EINVAL; |
| 4796 | |
| 4797 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4798 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4799 | |
| 4800 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4801 | return -EINVAL; |
| 4802 | |
| 4803 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4804 | |
| 4805 | return 0; |
| 4806 | } |
| 4807 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4808 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4809 | struct station_parameters *params) |
| 4810 | { |
| 4811 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4812 | params->supported_channels = |
| 4813 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4814 | params->supported_channels_len = |
| 4815 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4816 | /* |
| 4817 | * Need to include at least one (first channel, number of |
| 4818 | * channels) tuple for each subband, and must have proper |
| 4819 | * tuples for the rest of the data as well. |
| 4820 | */ |
| 4821 | if (params->supported_channels_len < 2) |
| 4822 | return -EINVAL; |
| 4823 | if (params->supported_channels_len % 2) |
| 4824 | return -EINVAL; |
| 4825 | } |
| 4826 | |
| 4827 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4828 | params->supported_oper_classes = |
| 4829 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4830 | params->supported_oper_classes_len = |
| 4831 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4832 | /* |
| 4833 | * The value of the Length field of the Supported Operating |
| 4834 | * Classes element is between 2 and 253. |
| 4835 | */ |
| 4836 | if (params->supported_oper_classes_len < 2 || |
| 4837 | params->supported_oper_classes_len > 253) |
| 4838 | return -EINVAL; |
| 4839 | } |
| 4840 | return 0; |
| 4841 | } |
| 4842 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4843 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4844 | struct station_parameters *params) |
| 4845 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4846 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4847 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4848 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4849 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4850 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4851 | params->ht_capa = |
| 4852 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4853 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4854 | params->vht_capa = |
| 4855 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4856 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4857 | err = nl80211_parse_sta_channel_info(info, params); |
| 4858 | if (err) |
| 4859 | return err; |
| 4860 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4861 | return nl80211_parse_sta_wme(info, params); |
| 4862 | } |
| 4863 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4864 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4865 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4867 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4868 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4869 | u8 *mac_addr; |
| 4870 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4871 | |
| 4872 | memset(¶ms, 0, sizeof(params)); |
| 4873 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4874 | if (!rdev->ops->change_station) |
| 4875 | return -EOPNOTSUPP; |
| 4876 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4877 | /* |
| 4878 | * AID and listen_interval properties can be set only for unassociated |
| 4879 | * station. Include these parameters here and will check them in |
| 4880 | * cfg80211_check_station_change(). |
| 4881 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4882 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4883 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4884 | |
| 4885 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4886 | params.listen_interval = |
| 4887 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4888 | else |
| 4889 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4890 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4891 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4892 | u8 tmp; |
| 4893 | |
| 4894 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4895 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4896 | return -EINVAL; |
| 4897 | |
| 4898 | params.support_p2p_ps = tmp; |
| 4899 | } else { |
| 4900 | params.support_p2p_ps = -1; |
| 4901 | } |
| 4902 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4903 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4904 | return -EINVAL; |
| 4905 | |
| 4906 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4907 | |
| 4908 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4909 | params.supported_rates = |
| 4910 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4911 | params.supported_rates_len = |
| 4912 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4913 | } |
| 4914 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4915 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4916 | params.capability = |
| 4917 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4918 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4919 | } |
| 4920 | |
| 4921 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4922 | params.ext_capab = |
| 4923 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4924 | params.ext_capab_len = |
| 4925 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4926 | } |
| 4927 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4928 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4929 | return -EINVAL; |
| 4930 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4931 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4932 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4933 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4934 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4935 | return -EINVAL; |
| 4936 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4937 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4938 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4939 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4940 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4941 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4942 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4944 | params.peer_aid = nla_get_u16( |
| 4945 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4946 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4947 | return -EINVAL; |
| 4948 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4949 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4950 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4951 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4952 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4953 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4954 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4955 | |
| 4956 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4957 | pm > NL80211_MESH_POWER_MAX) |
| 4958 | return -EINVAL; |
| 4959 | |
| 4960 | params.local_pm = pm; |
| 4961 | } |
| 4962 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4964 | params.opmode_notif_used = true; |
| 4965 | params.opmode_notif = |
| 4966 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4967 | } |
| 4968 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4969 | /* Include parameters for TDLS peer (will check later) */ |
| 4970 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4971 | if (err) |
| 4972 | return err; |
| 4973 | |
| 4974 | params.vlan = get_vlan(info, rdev); |
| 4975 | if (IS_ERR(params.vlan)) |
| 4976 | return PTR_ERR(params.vlan); |
| 4977 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4978 | switch (dev->ieee80211_ptr->iftype) { |
| 4979 | case NL80211_IFTYPE_AP: |
| 4980 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4981 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4982 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4983 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4984 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4985 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4986 | break; |
| 4987 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4988 | err = -EOPNOTSUPP; |
| 4989 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4990 | } |
| 4991 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4992 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4993 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4994 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4995 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4996 | if (params.vlan) |
| 4997 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4998 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4999 | return err; |
| 5000 | } |
| 5001 | |
| 5002 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 5003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5005 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5006 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5007 | struct station_parameters params; |
| 5008 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5009 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5010 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5011 | |
| 5012 | memset(¶ms, 0, sizeof(params)); |
| 5013 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5014 | if (!rdev->ops->add_station) |
| 5015 | return -EOPNOTSUPP; |
| 5016 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5017 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5018 | return -EINVAL; |
| 5019 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5020 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5021 | return -EINVAL; |
| 5022 | |
| 5023 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5024 | return -EINVAL; |
| 5025 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5026 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5027 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5028 | return -EINVAL; |
| 5029 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5030 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5031 | params.supported_rates = |
| 5032 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5033 | params.supported_rates_len = |
| 5034 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5035 | params.listen_interval = |
| 5036 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5037 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5038 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5039 | u8 tmp; |
| 5040 | |
| 5041 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5042 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5043 | return -EINVAL; |
| 5044 | |
| 5045 | params.support_p2p_ps = tmp; |
| 5046 | } else { |
| 5047 | /* |
| 5048 | * if not specified, assume it's supported for P2P GO interface, |
| 5049 | * and is NOT supported for AP interface |
| 5050 | */ |
| 5051 | params.support_p2p_ps = |
| 5052 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5053 | } |
| 5054 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5055 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5056 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5057 | else |
| 5058 | 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] | 5059 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 5060 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5061 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5062 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5063 | params.capability = |
| 5064 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5065 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5066 | } |
| 5067 | |
| 5068 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5069 | params.ext_capab = |
| 5070 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5071 | params.ext_capab_len = |
| 5072 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5073 | } |
| 5074 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5075 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5076 | params.ht_capa = |
| 5077 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5078 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5080 | params.vht_capa = |
| 5081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5082 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5083 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5084 | params.opmode_notif_used = true; |
| 5085 | params.opmode_notif = |
| 5086 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5087 | } |
| 5088 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5089 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5090 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5091 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5092 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5093 | return -EINVAL; |
| 5094 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5095 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5096 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5097 | if (err) |
| 5098 | return err; |
| 5099 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5100 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5101 | if (err) |
| 5102 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5103 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5104 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5105 | return -EINVAL; |
| 5106 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5107 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5108 | * as userspace might just pass through the capabilities from the IEs |
| 5109 | * directly, rather than enforcing this restriction and returning an |
| 5110 | * error in this case. |
| 5111 | */ |
| 5112 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5113 | params.ht_capa = NULL; |
| 5114 | params.vht_capa = NULL; |
| 5115 | } |
| 5116 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5117 | /* When you run into this, adjust the code below for the new flag */ |
| 5118 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5119 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5120 | switch (dev->ieee80211_ptr->iftype) { |
| 5121 | case NL80211_IFTYPE_AP: |
| 5122 | case NL80211_IFTYPE_AP_VLAN: |
| 5123 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5124 | /* ignore WME attributes if iface/sta is not capable */ |
| 5125 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5126 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5127 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5128 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5129 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5130 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5131 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5132 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5133 | /* but don't bother the driver with it */ |
| 5134 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5135 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5136 | /* allow authenticated/associated only if driver handles it */ |
| 5137 | if (!(rdev->wiphy.features & |
| 5138 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5139 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5140 | return -EINVAL; |
| 5141 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5142 | /* Older userspace, or userspace wanting to be compatible with |
| 5143 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5144 | * and assoc flags in the mask, but assumes the station will be |
| 5145 | * added as associated anyway since this was the required driver |
| 5146 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5147 | * introduced. |
| 5148 | * In order to not bother drivers with this quirk in the API |
| 5149 | * set the flags in both the mask and set for new stations in |
| 5150 | * this case. |
| 5151 | */ |
| 5152 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5153 | params.sta_flags_mask |= auth_assoc; |
| 5154 | params.sta_flags_set |= auth_assoc; |
| 5155 | } |
| 5156 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5157 | /* must be last in here for error handling */ |
| 5158 | params.vlan = get_vlan(info, rdev); |
| 5159 | if (IS_ERR(params.vlan)) |
| 5160 | return PTR_ERR(params.vlan); |
| 5161 | break; |
| 5162 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5163 | /* ignore uAPSD data */ |
| 5164 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5165 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5166 | /* associated is disallowed */ |
| 5167 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5168 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5169 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5170 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5171 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5172 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5173 | break; |
| 5174 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5175 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5176 | /* ignore uAPSD data */ |
| 5177 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5178 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5179 | /* these are disallowed */ |
| 5180 | if (params.sta_flags_mask & |
| 5181 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5182 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5183 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5184 | /* Only TDLS peers can be added */ |
| 5185 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5186 | return -EINVAL; |
| 5187 | /* Can only add if TDLS ... */ |
| 5188 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5189 | return -EOPNOTSUPP; |
| 5190 | /* ... with external setup is supported */ |
| 5191 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5192 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5193 | /* |
| 5194 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5195 | * as authorized, but it shouldn't yet be. |
| 5196 | */ |
| 5197 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5198 | break; |
| 5199 | default: |
| 5200 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5201 | } |
| 5202 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5203 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5204 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5205 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5206 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5207 | if (params.vlan) |
| 5208 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5209 | return err; |
| 5210 | } |
| 5211 | |
| 5212 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5215 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5216 | struct station_del_parameters params; |
| 5217 | |
| 5218 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5219 | |
| 5220 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5221 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5222 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5223 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5224 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5225 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5226 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5227 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5228 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5229 | if (!rdev->ops->del_station) |
| 5230 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5231 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5232 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5233 | params.subtype = |
| 5234 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5235 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5236 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5237 | return -EINVAL; |
| 5238 | } else { |
| 5239 | /* Default to Deauthentication frame */ |
| 5240 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5241 | } |
| 5242 | |
| 5243 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5244 | params.reason_code = |
| 5245 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5246 | if (params.reason_code == 0) |
| 5247 | return -EINVAL; /* 0 is reserved */ |
| 5248 | } else { |
| 5249 | /* Default to reason code 2 */ |
| 5250 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5251 | } |
| 5252 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5253 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5254 | } |
| 5255 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5256 | 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] | 5257 | int flags, struct net_device *dev, |
| 5258 | u8 *dst, u8 *next_hop, |
| 5259 | struct mpath_info *pinfo) |
| 5260 | { |
| 5261 | void *hdr; |
| 5262 | struct nlattr *pinfoattr; |
| 5263 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5264 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5265 | if (!hdr) |
| 5266 | return -1; |
| 5267 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5268 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5269 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5270 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5271 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5272 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5273 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5274 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5275 | if (!pinfoattr) |
| 5276 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5277 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5278 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5279 | pinfo->frame_qlen)) |
| 5280 | goto nla_put_failure; |
| 5281 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5282 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5283 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5284 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5285 | pinfo->metric)) || |
| 5286 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5287 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5288 | pinfo->exptime)) || |
| 5289 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5290 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5291 | pinfo->flags)) || |
| 5292 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5293 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5294 | pinfo->discovery_timeout)) || |
| 5295 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5296 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5297 | pinfo->discovery_retries))) |
| 5298 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5299 | |
| 5300 | nla_nest_end(msg, pinfoattr); |
| 5301 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5302 | genlmsg_end(msg, hdr); |
| 5303 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5304 | |
| 5305 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5306 | genlmsg_cancel(msg, hdr); |
| 5307 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5311 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5312 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5313 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5314 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5315 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5316 | u8 dst[ETH_ALEN]; |
| 5317 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5318 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5319 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5320 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5321 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5322 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5323 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5324 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5325 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5326 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5327 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5328 | goto out_err; |
| 5329 | } |
| 5330 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5331 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5332 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5333 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5334 | } |
| 5335 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5336 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5337 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5338 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5339 | if (err == -ENOENT) |
| 5340 | break; |
| 5341 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5342 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5343 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5344 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5345 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5346 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5347 | &pinfo) < 0) |
| 5348 | goto out; |
| 5349 | |
| 5350 | path_idx++; |
| 5351 | } |
| 5352 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5353 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5354 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5355 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5356 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5357 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5358 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5362 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5364 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5365 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5366 | struct mpath_info pinfo; |
| 5367 | struct sk_buff *msg; |
| 5368 | u8 *dst = NULL; |
| 5369 | u8 next_hop[ETH_ALEN]; |
| 5370 | |
| 5371 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5372 | |
| 5373 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5374 | return -EINVAL; |
| 5375 | |
| 5376 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5378 | if (!rdev->ops->get_mpath) |
| 5379 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5380 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5382 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5383 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5384 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5385 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5386 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5387 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5389 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5390 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5391 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5392 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5393 | dev, dst, next_hop, &pinfo) < 0) { |
| 5394 | nlmsg_free(msg); |
| 5395 | return -ENOBUFS; |
| 5396 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5398 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5402 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5404 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5405 | u8 *dst = NULL; |
| 5406 | u8 *next_hop = NULL; |
| 5407 | |
| 5408 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5409 | return -EINVAL; |
| 5410 | |
| 5411 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5412 | return -EINVAL; |
| 5413 | |
| 5414 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5415 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5416 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | if (!rdev->ops->change_mpath) |
| 5418 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5419 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5420 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5421 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5422 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5423 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5424 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5425 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5426 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5429 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5430 | u8 *dst = NULL; |
| 5431 | u8 *next_hop = NULL; |
| 5432 | |
| 5433 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5434 | return -EINVAL; |
| 5435 | |
| 5436 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5437 | return -EINVAL; |
| 5438 | |
| 5439 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5440 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5442 | if (!rdev->ops->add_mpath) |
| 5443 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5446 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5447 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5448 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5454 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5455 | u8 *dst = NULL; |
| 5456 | |
| 5457 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5458 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5459 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5460 | if (!rdev->ops->del_mpath) |
| 5461 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5462 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5463 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5464 | } |
| 5465 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5466 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5467 | { |
| 5468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5469 | int err; |
| 5470 | struct net_device *dev = info->user_ptr[1]; |
| 5471 | struct mpath_info pinfo; |
| 5472 | struct sk_buff *msg; |
| 5473 | u8 *dst = NULL; |
| 5474 | u8 mpp[ETH_ALEN]; |
| 5475 | |
| 5476 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5477 | |
| 5478 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5479 | return -EINVAL; |
| 5480 | |
| 5481 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5482 | |
| 5483 | if (!rdev->ops->get_mpp) |
| 5484 | return -EOPNOTSUPP; |
| 5485 | |
| 5486 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5487 | return -EOPNOTSUPP; |
| 5488 | |
| 5489 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5490 | if (err) |
| 5491 | return err; |
| 5492 | |
| 5493 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5494 | if (!msg) |
| 5495 | return -ENOMEM; |
| 5496 | |
| 5497 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5498 | dev, dst, mpp, &pinfo) < 0) { |
| 5499 | nlmsg_free(msg); |
| 5500 | return -ENOBUFS; |
| 5501 | } |
| 5502 | |
| 5503 | return genlmsg_reply(msg, info); |
| 5504 | } |
| 5505 | |
| 5506 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5507 | struct netlink_callback *cb) |
| 5508 | { |
| 5509 | struct mpath_info pinfo; |
| 5510 | struct cfg80211_registered_device *rdev; |
| 5511 | struct wireless_dev *wdev; |
| 5512 | u8 dst[ETH_ALEN]; |
| 5513 | u8 mpp[ETH_ALEN]; |
| 5514 | int path_idx = cb->args[2]; |
| 5515 | int err; |
| 5516 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5517 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5518 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5519 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5520 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5521 | |
| 5522 | if (!rdev->ops->dump_mpp) { |
| 5523 | err = -EOPNOTSUPP; |
| 5524 | goto out_err; |
| 5525 | } |
| 5526 | |
| 5527 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5528 | err = -EOPNOTSUPP; |
| 5529 | goto out_err; |
| 5530 | } |
| 5531 | |
| 5532 | while (1) { |
| 5533 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5534 | mpp, &pinfo); |
| 5535 | if (err == -ENOENT) |
| 5536 | break; |
| 5537 | if (err) |
| 5538 | goto out_err; |
| 5539 | |
| 5540 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5541 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5542 | wdev->netdev, dst, mpp, |
| 5543 | &pinfo) < 0) |
| 5544 | goto out; |
| 5545 | |
| 5546 | path_idx++; |
| 5547 | } |
| 5548 | |
| 5549 | out: |
| 5550 | cb->args[2] = path_idx; |
| 5551 | err = skb->len; |
| 5552 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5553 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5554 | return err; |
| 5555 | } |
| 5556 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5557 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5558 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5560 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5561 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5562 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5563 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5564 | |
| 5565 | memset(¶ms, 0, sizeof(params)); |
| 5566 | /* default to not changing parameters */ |
| 5567 | params.use_cts_prot = -1; |
| 5568 | params.use_short_preamble = -1; |
| 5569 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5570 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5571 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5572 | params.p2p_ctwindow = -1; |
| 5573 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5574 | |
| 5575 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5576 | params.use_cts_prot = |
| 5577 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5578 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5579 | params.use_short_preamble = |
| 5580 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5581 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5582 | params.use_short_slot_time = |
| 5583 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5584 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5585 | params.basic_rates = |
| 5586 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5587 | params.basic_rates_len = |
| 5588 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5589 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5590 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5591 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5592 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5593 | params.ht_opmode = |
| 5594 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5595 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5596 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5598 | return -EINVAL; |
| 5599 | params.p2p_ctwindow = |
| 5600 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5601 | if (params.p2p_ctwindow < 0) |
| 5602 | return -EINVAL; |
| 5603 | if (params.p2p_ctwindow != 0 && |
| 5604 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5605 | return -EINVAL; |
| 5606 | } |
| 5607 | |
| 5608 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5609 | u8 tmp; |
| 5610 | |
| 5611 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5612 | return -EINVAL; |
| 5613 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5614 | if (tmp > 1) |
| 5615 | return -EINVAL; |
| 5616 | params.p2p_opp_ps = tmp; |
| 5617 | if (params.p2p_opp_ps && |
| 5618 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5619 | return -EINVAL; |
| 5620 | } |
| 5621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5622 | if (!rdev->ops->change_bss) |
| 5623 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5624 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5625 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5626 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5627 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5628 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5629 | wdev_lock(wdev); |
| 5630 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5631 | wdev_unlock(wdev); |
| 5632 | |
| 5633 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5634 | } |
| 5635 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5636 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5637 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5638 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5639 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5640 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5641 | u32 owner_nlportid; |
| 5642 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5643 | /* |
| 5644 | * You should only get this when cfg80211 hasn't yet initialized |
| 5645 | * completely when built-in to the kernel right between the time |
| 5646 | * window between nl80211_init() and regulatory_init(), if that is |
| 5647 | * even possible. |
| 5648 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5649 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5650 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5651 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5652 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5653 | user_reg_hint_type = |
| 5654 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5655 | else |
| 5656 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5657 | |
| 5658 | switch (user_reg_hint_type) { |
| 5659 | case NL80211_USER_REG_HINT_USER: |
| 5660 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5661 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5662 | return -EINVAL; |
| 5663 | |
| 5664 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5665 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5666 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5667 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5668 | owner_nlportid = info->snd_portid; |
| 5669 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5670 | } else { |
| 5671 | owner_nlportid = 0; |
| 5672 | is_indoor = true; |
| 5673 | } |
| 5674 | |
| 5675 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5676 | default: |
| 5677 | return -EINVAL; |
| 5678 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5681 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5682 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5683 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5685 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5686 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5687 | struct mesh_config cur_params; |
| 5688 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5689 | void *hdr; |
| 5690 | struct nlattr *pinfoattr; |
| 5691 | struct sk_buff *msg; |
| 5692 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5693 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5694 | return -EOPNOTSUPP; |
| 5695 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5696 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5697 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5698 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5699 | wdev_lock(wdev); |
| 5700 | /* If not connected, get default parameters */ |
| 5701 | if (!wdev->mesh_id_len) |
| 5702 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5703 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5704 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5705 | wdev_unlock(wdev); |
| 5706 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5707 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5708 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5709 | |
| 5710 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5711 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5712 | if (!msg) |
| 5713 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5714 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5715 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5716 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5717 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5718 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5719 | if (!pinfoattr) |
| 5720 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5721 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5722 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5723 | cur_params.dot11MeshRetryTimeout) || |
| 5724 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5725 | cur_params.dot11MeshConfirmTimeout) || |
| 5726 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5727 | cur_params.dot11MeshHoldingTimeout) || |
| 5728 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5729 | cur_params.dot11MeshMaxPeerLinks) || |
| 5730 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5731 | cur_params.dot11MeshMaxRetries) || |
| 5732 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5733 | cur_params.dot11MeshTTL) || |
| 5734 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5735 | cur_params.element_ttl) || |
| 5736 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5737 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5738 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5739 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5740 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5741 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5742 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5743 | cur_params.path_refresh_time) || |
| 5744 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5745 | cur_params.min_discovery_timeout) || |
| 5746 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5747 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5748 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5749 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5750 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5751 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5752 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5753 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5754 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5755 | cur_params.dot11MeshHWMPRootMode) || |
| 5756 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5757 | cur_params.dot11MeshHWMPRannInterval) || |
| 5758 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5759 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5760 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5761 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 5762 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5763 | cur_params.rssi_threshold) || |
| 5764 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5765 | cur_params.ht_opmode) || |
| 5766 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5767 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5768 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5769 | cur_params.dot11MeshHWMProotInterval) || |
| 5770 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5771 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5772 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5773 | cur_params.power_mode) || |
| 5774 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5775 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5776 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5777 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5778 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5779 | nla_nest_end(msg, pinfoattr); |
| 5780 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5781 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5782 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5783 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5784 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5785 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5786 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5787 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5788 | } |
| 5789 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5790 | 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] | 5791 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5792 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5793 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5794 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5795 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5796 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5797 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5798 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5799 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5800 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5801 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5802 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5803 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5804 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5805 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5806 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5807 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5808 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5809 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5810 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5811 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5812 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5813 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5814 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5815 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5816 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5817 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5818 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5819 | }; |
| 5820 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5821 | static const struct nla_policy |
| 5822 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5823 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5824 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5825 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5826 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5827 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5828 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5829 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5830 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5831 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5832 | }; |
| 5833 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5834 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *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_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5844 | { |
| 5845 | u8 val = nla_get_u8(nla); |
| 5846 | if (val < min || val > max) |
| 5847 | return -EINVAL; |
| 5848 | *out = val; |
| 5849 | return 0; |
| 5850 | } |
| 5851 | |
| 5852 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5853 | { |
| 5854 | u16 val = nla_get_u16(nla); |
| 5855 | if (val < min || val > max) |
| 5856 | return -EINVAL; |
| 5857 | *out = val; |
| 5858 | return 0; |
| 5859 | } |
| 5860 | |
| 5861 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5862 | { |
| 5863 | u32 val = nla_get_u32(nla); |
| 5864 | if (val < min || val > max) |
| 5865 | return -EINVAL; |
| 5866 | *out = val; |
| 5867 | return 0; |
| 5868 | } |
| 5869 | |
| 5870 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5871 | { |
| 5872 | s32 val = nla_get_s32(nla); |
| 5873 | if (val < min || val > max) |
| 5874 | return -EINVAL; |
| 5875 | *out = val; |
| 5876 | return 0; |
| 5877 | } |
| 5878 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5879 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5880 | enum nl80211_mesh_power_mode min, |
| 5881 | enum nl80211_mesh_power_mode max, |
| 5882 | enum nl80211_mesh_power_mode *out) |
| 5883 | { |
| 5884 | u32 val = nla_get_u32(nla); |
| 5885 | if (val < min || val > max) |
| 5886 | return -EINVAL; |
| 5887 | *out = val; |
| 5888 | return 0; |
| 5889 | } |
| 5890 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5891 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5892 | struct mesh_config *cfg, |
| 5893 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5894 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5895 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5896 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5897 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5898 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5899 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5900 | do { \ |
| 5901 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5902 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5903 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5904 | mask |= (1 << (attr - 1)); \ |
| 5905 | } \ |
| 5906 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5907 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5908 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5909 | return -EINVAL; |
| 5910 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5911 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 5912 | nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5913 | return -EINVAL; |
| 5914 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5915 | /* This makes sure that there aren't more than 32 mesh config |
| 5916 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5917 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5918 | |
| 5919 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5921 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
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, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5924 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5925 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5927 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5928 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5930 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5931 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5933 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5934 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5936 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5937 | 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] | 5938 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5939 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5940 | 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] | 5941 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5942 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5944 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5945 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5946 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5948 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5949 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5950 | 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] | 5951 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5952 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5953 | 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] | 5954 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5955 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5956 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5957 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5958 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5959 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5960 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5961 | 1, 65535, mask, |
| 5962 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5963 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5965 | 1, 65535, mask, |
| 5966 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5967 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5968 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5969 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5970 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5971 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5972 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5973 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5974 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5975 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5977 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5978 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5980 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5981 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5982 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5983 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5984 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5985 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5986 | 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] | 5987 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5988 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5989 | /* |
| 5990 | * Check HT operation mode based on |
| 5991 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5992 | */ |
| 5993 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5994 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5995 | |
| 5996 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5997 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5998 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5999 | return -EINVAL; |
| 6000 | |
| 6001 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 6002 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6003 | return -EINVAL; |
| 6004 | |
| 6005 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 6006 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 6007 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 6008 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 6009 | return -EINVAL; |
| 6010 | break; |
| 6011 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 6012 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 6013 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6014 | return -EINVAL; |
| 6015 | break; |
| 6016 | } |
| 6017 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6018 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6019 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6021 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6022 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6023 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6024 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6025 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6026 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6028 | dot11MeshHWMPconfirmationInterval, |
| 6029 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6030 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6031 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6032 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 6033 | NL80211_MESH_POWER_ACTIVE, |
| 6034 | NL80211_MESH_POWER_MAX, |
| 6035 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6036 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6037 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 6038 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6039 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 6040 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6041 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6042 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6043 | if (mask_out) |
| 6044 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6045 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6046 | return 0; |
| 6047 | |
| 6048 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6049 | } |
| 6050 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6051 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6052 | struct mesh_setup *setup) |
| 6053 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6055 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6056 | |
| 6057 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6058 | return -EINVAL; |
| 6059 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6060 | info->attrs[NL80211_ATTR_MESH_SETUP], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6061 | nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6062 | return -EINVAL; |
| 6063 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6064 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6065 | setup->sync_method = |
| 6066 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6067 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6068 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6069 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6070 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6071 | setup->path_sel_proto = |
| 6072 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6073 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6074 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6075 | |
| 6076 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6077 | setup->path_metric = |
| 6078 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6079 | IEEE80211_PATH_METRIC_VENDOR : |
| 6080 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6081 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6082 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6083 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6084 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6085 | if (!is_valid_ie_attr(ieattr)) |
| 6086 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6087 | setup->ie = nla_data(ieattr); |
| 6088 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6089 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6090 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6091 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6092 | return -EINVAL; |
| 6093 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6094 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6095 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6096 | if (setup->is_secure) |
| 6097 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6098 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6099 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6100 | if (!setup->user_mpm) |
| 6101 | return -EINVAL; |
| 6102 | setup->auth_id = |
| 6103 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6104 | } |
| 6105 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6106 | return 0; |
| 6107 | } |
| 6108 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6109 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6110 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6111 | { |
| 6112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6113 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6114 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6115 | struct mesh_config cfg; |
| 6116 | u32 mask; |
| 6117 | int err; |
| 6118 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6119 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6120 | return -EOPNOTSUPP; |
| 6121 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6122 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6123 | return -EOPNOTSUPP; |
| 6124 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6125 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6126 | if (err) |
| 6127 | return err; |
| 6128 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6129 | wdev_lock(wdev); |
| 6130 | if (!wdev->mesh_id_len) |
| 6131 | err = -ENOLINK; |
| 6132 | |
| 6133 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6134 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6135 | |
| 6136 | wdev_unlock(wdev); |
| 6137 | |
| 6138 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6139 | } |
| 6140 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6141 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6142 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6143 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6144 | struct nlattr *nl_reg_rules; |
| 6145 | unsigned int i; |
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 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6148 | (regdom->dfs_region && |
| 6149 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6150 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6151 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6152 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6153 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6154 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6155 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6156 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6157 | struct nlattr *nl_reg_rule; |
| 6158 | const struct ieee80211_reg_rule *reg_rule; |
| 6159 | const struct ieee80211_freq_range *freq_range; |
| 6160 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6161 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6162 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6163 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6164 | freq_range = ®_rule->freq_range; |
| 6165 | power_rule = ®_rule->power_rule; |
| 6166 | |
| 6167 | nl_reg_rule = nla_nest_start(msg, i); |
| 6168 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6169 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6170 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6171 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6172 | if (!max_bandwidth_khz) |
| 6173 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6174 | reg_rule); |
| 6175 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6176 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6177 | reg_rule->flags) || |
| 6178 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6179 | freq_range->start_freq_khz) || |
| 6180 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6181 | freq_range->end_freq_khz) || |
| 6182 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6183 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6184 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6185 | power_rule->max_antenna_gain) || |
| 6186 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6187 | power_rule->max_eirp) || |
| 6188 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6189 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6190 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6191 | |
| 6192 | nla_nest_end(msg, nl_reg_rule); |
| 6193 | } |
| 6194 | |
| 6195 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6196 | return 0; |
| 6197 | |
| 6198 | nla_put_failure: |
| 6199 | return -EMSGSIZE; |
| 6200 | } |
| 6201 | |
| 6202 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6203 | { |
| 6204 | const struct ieee80211_regdomain *regdom = NULL; |
| 6205 | struct cfg80211_registered_device *rdev; |
| 6206 | struct wiphy *wiphy = NULL; |
| 6207 | struct sk_buff *msg; |
| 6208 | void *hdr; |
| 6209 | |
| 6210 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6211 | if (!msg) |
| 6212 | return -ENOBUFS; |
| 6213 | |
| 6214 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6215 | NL80211_CMD_GET_REG); |
| 6216 | if (!hdr) |
| 6217 | goto put_failure; |
| 6218 | |
| 6219 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6220 | bool self_managed; |
| 6221 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6222 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6223 | if (IS_ERR(rdev)) { |
| 6224 | nlmsg_free(msg); |
| 6225 | return PTR_ERR(rdev); |
| 6226 | } |
| 6227 | |
| 6228 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6229 | self_managed = wiphy->regulatory_flags & |
| 6230 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6231 | regdom = get_wiphy_regdom(wiphy); |
| 6232 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6233 | /* a self-managed-reg device must have a private regdom */ |
| 6234 | if (WARN_ON(!regdom && self_managed)) { |
| 6235 | nlmsg_free(msg); |
| 6236 | return -EINVAL; |
| 6237 | } |
| 6238 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6239 | if (regdom && |
| 6240 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6241 | goto nla_put_failure; |
| 6242 | } |
| 6243 | |
| 6244 | if (!wiphy && reg_last_request_cell_base() && |
| 6245 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6246 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6247 | goto nla_put_failure; |
| 6248 | |
| 6249 | rcu_read_lock(); |
| 6250 | |
| 6251 | if (!regdom) |
| 6252 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6253 | |
| 6254 | if (nl80211_put_regdom(regdom, msg)) |
| 6255 | goto nla_put_failure_rcu; |
| 6256 | |
| 6257 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6258 | |
| 6259 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6260 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6261 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6262 | nla_put_failure_rcu: |
| 6263 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6264 | nla_put_failure: |
| 6265 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6266 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6267 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6268 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6269 | } |
| 6270 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6271 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6272 | u32 seq, int flags, struct wiphy *wiphy, |
| 6273 | const struct ieee80211_regdomain *regdom) |
| 6274 | { |
| 6275 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6276 | NL80211_CMD_GET_REG); |
| 6277 | |
| 6278 | if (!hdr) |
| 6279 | return -1; |
| 6280 | |
| 6281 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6282 | |
| 6283 | if (nl80211_put_regdom(regdom, msg)) |
| 6284 | goto nla_put_failure; |
| 6285 | |
| 6286 | if (!wiphy && reg_last_request_cell_base() && |
| 6287 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6288 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6289 | goto nla_put_failure; |
| 6290 | |
| 6291 | if (wiphy && |
| 6292 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6293 | goto nla_put_failure; |
| 6294 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6295 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6296 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6297 | goto nla_put_failure; |
| 6298 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6299 | genlmsg_end(msg, hdr); |
| 6300 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6301 | |
| 6302 | nla_put_failure: |
| 6303 | genlmsg_cancel(msg, hdr); |
| 6304 | return -EMSGSIZE; |
| 6305 | } |
| 6306 | |
| 6307 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6308 | struct netlink_callback *cb) |
| 6309 | { |
| 6310 | const struct ieee80211_regdomain *regdom = NULL; |
| 6311 | struct cfg80211_registered_device *rdev; |
| 6312 | int err, reg_idx, start = cb->args[2]; |
| 6313 | |
| 6314 | rtnl_lock(); |
| 6315 | |
| 6316 | if (cfg80211_regdomain && start == 0) { |
| 6317 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6318 | NLM_F_MULTI, NULL, |
| 6319 | rtnl_dereference(cfg80211_regdomain)); |
| 6320 | if (err < 0) |
| 6321 | goto out_err; |
| 6322 | } |
| 6323 | |
| 6324 | /* the global regdom is idx 0 */ |
| 6325 | reg_idx = 1; |
| 6326 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6327 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6328 | if (!regdom) |
| 6329 | continue; |
| 6330 | |
| 6331 | if (++reg_idx <= start) |
| 6332 | continue; |
| 6333 | |
| 6334 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6335 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6336 | if (err < 0) { |
| 6337 | reg_idx--; |
| 6338 | break; |
| 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | cb->args[2] = reg_idx; |
| 6343 | err = skb->len; |
| 6344 | out_err: |
| 6345 | rtnl_unlock(); |
| 6346 | return err; |
| 6347 | } |
| 6348 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6349 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6350 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6351 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6352 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6353 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6354 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6355 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6356 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6357 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6358 | }; |
| 6359 | |
| 6360 | static int parse_reg_rule(struct nlattr *tb[], |
| 6361 | struct ieee80211_reg_rule *reg_rule) |
| 6362 | { |
| 6363 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6364 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6365 | |
| 6366 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6367 | return -EINVAL; |
| 6368 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6369 | return -EINVAL; |
| 6370 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6371 | return -EINVAL; |
| 6372 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6373 | return -EINVAL; |
| 6374 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6375 | return -EINVAL; |
| 6376 | |
| 6377 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6378 | |
| 6379 | freq_range->start_freq_khz = |
| 6380 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6381 | freq_range->end_freq_khz = |
| 6382 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6383 | freq_range->max_bandwidth_khz = |
| 6384 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6385 | |
| 6386 | power_rule->max_eirp = |
| 6387 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6388 | |
| 6389 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6390 | power_rule->max_antenna_gain = |
| 6391 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6392 | |
| 6393 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6394 | reg_rule->dfs_cac_ms = |
| 6395 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6396 | |
| 6397 | return 0; |
| 6398 | } |
| 6399 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6400 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6401 | { |
| 6402 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6403 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6404 | char *alpha2; |
| 6405 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6406 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6407 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6408 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6409 | |
| 6410 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6414 | return -EINVAL; |
| 6415 | |
| 6416 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6417 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6418 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6419 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6420 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6421 | 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] | 6422 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6423 | num_rules++; |
| 6424 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6425 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6426 | } |
| 6427 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6428 | if (!reg_is_valid_request(alpha2)) |
| 6429 | return -EINVAL; |
| 6430 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6431 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6432 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6433 | |
| 6434 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6435 | if (!rd) |
| 6436 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6437 | |
| 6438 | rd->n_reg_rules = num_rules; |
| 6439 | rd->alpha2[0] = alpha2[0]; |
| 6440 | rd->alpha2[1] = alpha2[1]; |
| 6441 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6442 | /* |
| 6443 | * Disable DFS master mode if the DFS region was |
| 6444 | * not supported or known on this kernel. |
| 6445 | */ |
| 6446 | if (reg_supported_dfs_region(dfs_region)) |
| 6447 | rd->dfs_region = dfs_region; |
| 6448 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6449 | 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] | 6450 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6451 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 6452 | nl_reg_rule, reg_rule_policy, |
| 6453 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6454 | if (r) |
| 6455 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6456 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6457 | if (r) |
| 6458 | goto bad_reg; |
| 6459 | |
| 6460 | rule_idx++; |
| 6461 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6462 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6463 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6464 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6465 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6466 | } |
| 6467 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6468 | /* set_regdom takes ownership of rd */ |
| 6469 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6470 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6471 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6472 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6473 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6474 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6475 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6476 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6477 | { |
| 6478 | struct nlattr *attr1, *attr2; |
| 6479 | int n_channels = 0, tmp1, tmp2; |
| 6480 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6481 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6482 | if (nla_len(attr1) != sizeof(u32)) |
| 6483 | return 0; |
| 6484 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6485 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6486 | n_channels++; |
| 6487 | /* |
| 6488 | * Some hardware has a limited channel list for |
| 6489 | * scanning, and it is pretty much nonsensical |
| 6490 | * to scan for a channel twice, so disallow that |
| 6491 | * and don't require drivers to check that the |
| 6492 | * channel list they get isn't longer than what |
| 6493 | * they can scan, as long as they can scan all |
| 6494 | * the channels they registered at once. |
| 6495 | */ |
| 6496 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6497 | if (attr1 != attr2 && |
| 6498 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6499 | return 0; |
| 6500 | } |
| 6501 | |
| 6502 | return n_channels; |
| 6503 | } |
| 6504 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6505 | 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] | 6506 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6507 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6511 | struct cfg80211_bss_selection *bss_select) |
| 6512 | { |
| 6513 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6514 | struct nlattr *nest; |
| 6515 | int err; |
| 6516 | bool found = false; |
| 6517 | int i; |
| 6518 | |
| 6519 | /* only process one nested attribute */ |
| 6520 | nest = nla_data(nla); |
| 6521 | if (!nla_ok(nest, nla_len(nest))) |
| 6522 | return -EINVAL; |
| 6523 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6524 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 6525 | nl80211_bss_select_policy, NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6526 | if (err) |
| 6527 | return err; |
| 6528 | |
| 6529 | /* only one attribute may be given */ |
| 6530 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6531 | if (attr[i]) { |
| 6532 | if (found) |
| 6533 | return -EINVAL; |
| 6534 | found = true; |
| 6535 | } |
| 6536 | } |
| 6537 | |
| 6538 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6539 | |
| 6540 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6541 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6542 | |
| 6543 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6544 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6545 | bss_select->param.band_pref = |
| 6546 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6547 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6548 | return -EINVAL; |
| 6549 | } |
| 6550 | |
| 6551 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6552 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6553 | |
| 6554 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6555 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6556 | bss_select->param.adjust.band = adj_param->band; |
| 6557 | bss_select->param.adjust.delta = adj_param->delta; |
| 6558 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6559 | return -EINVAL; |
| 6560 | } |
| 6561 | |
| 6562 | /* user-space did not provide behaviour attribute */ |
| 6563 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6564 | return -EINVAL; |
| 6565 | |
| 6566 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6567 | return -EINVAL; |
| 6568 | |
| 6569 | return 0; |
| 6570 | } |
| 6571 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6572 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6573 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6574 | { |
| 6575 | int i; |
| 6576 | |
| 6577 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6578 | eth_zero_addr(mac_addr); |
| 6579 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6580 | mac_addr[0] = 0x2; |
| 6581 | mac_addr_mask[0] = 0x3; |
| 6582 | |
| 6583 | return 0; |
| 6584 | } |
| 6585 | |
| 6586 | /* need both or none */ |
| 6587 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6588 | return -EINVAL; |
| 6589 | |
| 6590 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6591 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6592 | |
| 6593 | /* don't allow or configure an mcast address */ |
| 6594 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6595 | is_multicast_ether_addr(mac_addr)) |
| 6596 | return -EINVAL; |
| 6597 | |
| 6598 | /* |
| 6599 | * allow users to pass a MAC address that has bits set outside |
| 6600 | * of the mask, but don't bother drivers with having to deal |
| 6601 | * with such bits |
| 6602 | */ |
| 6603 | for (i = 0; i < ETH_ALEN; i++) |
| 6604 | mac_addr[i] &= mac_addr_mask[i]; |
| 6605 | |
| 6606 | return 0; |
| 6607 | } |
| 6608 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6609 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 6610 | { |
| 6611 | ASSERT_WDEV_LOCK(wdev); |
| 6612 | |
| 6613 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 6614 | return true; |
| 6615 | |
| 6616 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 6617 | return true; |
| 6618 | |
| 6619 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 6620 | } |
| 6621 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 6622 | static int |
| 6623 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 6624 | void *request, struct nlattr **attrs, |
| 6625 | bool is_sched_scan) |
| 6626 | { |
| 6627 | u8 *mac_addr, *mac_addr_mask; |
| 6628 | u32 *flags; |
| 6629 | enum nl80211_feature_flags randomness_flag; |
| 6630 | |
| 6631 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 6632 | return 0; |
| 6633 | |
| 6634 | if (is_sched_scan) { |
| 6635 | struct cfg80211_sched_scan_request *req = request; |
| 6636 | |
| 6637 | randomness_flag = wdev ? |
| 6638 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 6639 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6640 | flags = &req->flags; |
| 6641 | mac_addr = req->mac_addr; |
| 6642 | mac_addr_mask = req->mac_addr_mask; |
| 6643 | } else { |
| 6644 | struct cfg80211_scan_request *req = request; |
| 6645 | |
| 6646 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 6647 | flags = &req->flags; |
| 6648 | mac_addr = req->mac_addr; |
| 6649 | mac_addr_mask = req->mac_addr_mask; |
| 6650 | } |
| 6651 | |
| 6652 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 6653 | |
| 6654 | if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6655 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) |
| 6656 | return -EOPNOTSUPP; |
| 6657 | |
| 6658 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6659 | int err; |
| 6660 | |
| 6661 | if (!(wiphy->features & randomness_flag) || |
| 6662 | (wdev && wdev->current_bss)) |
| 6663 | return -EOPNOTSUPP; |
| 6664 | |
| 6665 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 6666 | if (err) |
| 6667 | return err; |
| 6668 | } |
| 6669 | |
| 6670 | if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) && |
| 6671 | !wiphy_ext_feature_isset(wiphy, |
| 6672 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME)) |
| 6673 | return -EOPNOTSUPP; |
| 6674 | |
| 6675 | if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) && |
| 6676 | !wiphy_ext_feature_isset(wiphy, |
| 6677 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP)) |
| 6678 | return -EOPNOTSUPP; |
| 6679 | |
| 6680 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) && |
| 6681 | !wiphy_ext_feature_isset(wiphy, |
| 6682 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION)) |
| 6683 | return -EOPNOTSUPP; |
| 6684 | |
| 6685 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) && |
| 6686 | !wiphy_ext_feature_isset(wiphy, |
| 6687 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE)) |
| 6688 | return -EOPNOTSUPP; |
| 6689 | |
| 6690 | return 0; |
| 6691 | } |
| 6692 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6693 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6694 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6696 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6697 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6698 | struct nlattr *attr; |
| 6699 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6700 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6701 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6702 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6703 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6704 | return -EINVAL; |
| 6705 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6706 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6707 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6708 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6709 | return -EOPNOTSUPP; |
| 6710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6711 | if (!rdev->ops->scan) |
| 6712 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6713 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6714 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6715 | err = -EBUSY; |
| 6716 | goto unlock; |
| 6717 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6718 | |
| 6719 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6720 | n_channels = validate_scan_freqs( |
| 6721 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6722 | if (!n_channels) { |
| 6723 | err = -EINVAL; |
| 6724 | goto unlock; |
| 6725 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6726 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6727 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6731 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6732 | n_ssids++; |
| 6733 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6734 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6735 | err = -EINVAL; |
| 6736 | goto unlock; |
| 6737 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6738 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6739 | if (info->attrs[NL80211_ATTR_IE]) |
| 6740 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6741 | else |
| 6742 | ie_len = 0; |
| 6743 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6744 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6745 | err = -EINVAL; |
| 6746 | goto unlock; |
| 6747 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6748 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6749 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6750 | + sizeof(*request->ssids) * n_ssids |
| 6751 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6752 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6753 | if (!request) { |
| 6754 | err = -ENOMEM; |
| 6755 | goto unlock; |
| 6756 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6757 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6758 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6759 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6760 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6761 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6762 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6763 | request->ie = (void *)(request->ssids + n_ssids); |
| 6764 | else |
| 6765 | request->ie = (void *)(request->channels + n_channels); |
| 6766 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6767 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6768 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6769 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6770 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6771 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6772 | struct ieee80211_channel *chan; |
| 6773 | |
| 6774 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6775 | |
| 6776 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6777 | err = -EINVAL; |
| 6778 | goto out_free; |
| 6779 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6780 | |
| 6781 | /* ignore disabled channels */ |
| 6782 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6783 | continue; |
| 6784 | |
| 6785 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6786 | i++; |
| 6787 | } |
| 6788 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6789 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6790 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6791 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6792 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6793 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6794 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6795 | if (!wiphy->bands[band]) |
| 6796 | continue; |
| 6797 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6798 | struct ieee80211_channel *chan; |
| 6799 | |
| 6800 | chan = &wiphy->bands[band]->channels[j]; |
| 6801 | |
| 6802 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6803 | continue; |
| 6804 | |
| 6805 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6806 | i++; |
| 6807 | } |
| 6808 | } |
| 6809 | } |
| 6810 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6811 | if (!i) { |
| 6812 | err = -EINVAL; |
| 6813 | goto out_free; |
| 6814 | } |
| 6815 | |
| 6816 | request->n_channels = i; |
| 6817 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6818 | wdev_lock(wdev); |
| 6819 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 6820 | struct ieee80211_channel *chan; |
| 6821 | |
| 6822 | if (request->n_channels != 1) { |
| 6823 | wdev_unlock(wdev); |
| 6824 | err = -EBUSY; |
| 6825 | goto out_free; |
| 6826 | } |
| 6827 | |
| 6828 | chan = request->channels[0]; |
| 6829 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 6830 | wdev_unlock(wdev); |
| 6831 | err = -EBUSY; |
| 6832 | goto out_free; |
| 6833 | } |
| 6834 | } |
| 6835 | wdev_unlock(wdev); |
| 6836 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6837 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6838 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6839 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6840 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6841 | err = -EINVAL; |
| 6842 | goto out_free; |
| 6843 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6844 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6845 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6846 | i++; |
| 6847 | } |
| 6848 | } |
| 6849 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6850 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6851 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6852 | memcpy((void *)request->ie, |
| 6853 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6854 | request->ie_len); |
| 6855 | } |
| 6856 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6857 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6858 | if (wiphy->bands[i]) |
| 6859 | request->rates[i] = |
| 6860 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6861 | |
| 6862 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6863 | nla_for_each_nested(attr, |
| 6864 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6865 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6866 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6867 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6868 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6869 | err = -EINVAL; |
| 6870 | goto out_free; |
| 6871 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6872 | |
| 6873 | if (!wiphy->bands[band]) |
| 6874 | continue; |
| 6875 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6876 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6877 | nla_data(attr), |
| 6878 | nla_len(attr), |
| 6879 | &request->rates[band]); |
| 6880 | if (err) |
| 6881 | goto out_free; |
| 6882 | } |
| 6883 | } |
| 6884 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6885 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6886 | if (!wiphy_ext_feature_isset(wiphy, |
| 6887 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6888 | err = -EOPNOTSUPP; |
| 6889 | goto out_free; |
| 6890 | } |
| 6891 | |
| 6892 | request->duration = |
| 6893 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6894 | request->duration_mandatory = |
| 6895 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6896 | } |
| 6897 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 6898 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 6899 | false); |
| 6900 | if (err) |
| 6901 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6902 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6903 | request->no_cck = |
| 6904 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6905 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6906 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6907 | * BSSID to scan for. This was problematic because that same attribute |
| 6908 | * was already used for another purpose (local random MAC address). The |
| 6909 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6910 | * compatibility with older userspace components, also use the |
| 6911 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6912 | * the specific BSSID use case instead of the random MAC address |
| 6913 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6914 | */ |
| 6915 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6916 | memcpy(request->bssid, |
| 6917 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6918 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6919 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6920 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6921 | ETH_ALEN); |
| 6922 | else |
| 6923 | eth_broadcast_addr(request->bssid); |
| 6924 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6925 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6926 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6927 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6928 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6929 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6930 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6931 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6932 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6933 | nl80211_send_scan_start(rdev, wdev); |
| 6934 | if (wdev->netdev) |
| 6935 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6936 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6937 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6938 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6939 | kfree(request); |
| 6940 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6941 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6942 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6943 | return err; |
| 6944 | } |
| 6945 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6946 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6947 | { |
| 6948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6949 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6950 | |
| 6951 | if (!rdev->ops->abort_scan) |
| 6952 | return -EOPNOTSUPP; |
| 6953 | |
| 6954 | if (rdev->scan_msg) |
| 6955 | return 0; |
| 6956 | |
| 6957 | if (!rdev->scan_req) |
| 6958 | return -ENOENT; |
| 6959 | |
| 6960 | rdev_abort_scan(rdev, wdev); |
| 6961 | return 0; |
| 6962 | } |
| 6963 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6964 | static int |
| 6965 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6966 | struct cfg80211_sched_scan_request *request, |
| 6967 | struct nlattr **attrs) |
| 6968 | { |
| 6969 | int tmp, err, i = 0; |
| 6970 | struct nlattr *attr; |
| 6971 | |
| 6972 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6973 | u32 interval; |
| 6974 | |
| 6975 | /* |
| 6976 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 6977 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6978 | * case one scan plan will be set with the specified scan |
| 6979 | * interval and infinite number of iterations. |
| 6980 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6981 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6982 | if (!interval) |
| 6983 | return -EINVAL; |
| 6984 | |
| 6985 | request->scan_plans[0].interval = |
| 6986 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6987 | if (!request->scan_plans[0].interval) |
| 6988 | return -EINVAL; |
| 6989 | |
| 6990 | if (request->scan_plans[0].interval > |
| 6991 | wiphy->max_sched_scan_plan_interval) |
| 6992 | request->scan_plans[0].interval = |
| 6993 | wiphy->max_sched_scan_plan_interval; |
| 6994 | |
| 6995 | return 0; |
| 6996 | } |
| 6997 | |
| 6998 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6999 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 7000 | |
| 7001 | if (WARN_ON(i >= n_plans)) |
| 7002 | return -EINVAL; |
| 7003 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7004 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7005 | attr, nl80211_plan_policy, NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7006 | if (err) |
| 7007 | return err; |
| 7008 | |
| 7009 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 7010 | return -EINVAL; |
| 7011 | |
| 7012 | request->scan_plans[i].interval = |
| 7013 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 7014 | if (!request->scan_plans[i].interval || |
| 7015 | request->scan_plans[i].interval > |
| 7016 | wiphy->max_sched_scan_plan_interval) |
| 7017 | return -EINVAL; |
| 7018 | |
| 7019 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 7020 | request->scan_plans[i].iterations = |
| 7021 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 7022 | if (!request->scan_plans[i].iterations || |
| 7023 | (request->scan_plans[i].iterations > |
| 7024 | wiphy->max_sched_scan_plan_iterations)) |
| 7025 | return -EINVAL; |
| 7026 | } else if (i < n_plans - 1) { |
| 7027 | /* |
| 7028 | * All scan plans but the last one must specify |
| 7029 | * a finite number of iterations |
| 7030 | */ |
| 7031 | return -EINVAL; |
| 7032 | } |
| 7033 | |
| 7034 | i++; |
| 7035 | } |
| 7036 | |
| 7037 | /* |
| 7038 | * The last scan plan must not specify the number of |
| 7039 | * iterations, it is supposed to run infinitely |
| 7040 | */ |
| 7041 | if (request->scan_plans[n_plans - 1].iterations) |
| 7042 | return -EINVAL; |
| 7043 | |
| 7044 | return 0; |
| 7045 | } |
| 7046 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7047 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7048 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7049 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7050 | { |
| 7051 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7052 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7053 | 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] | 7054 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7055 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7056 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7057 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7058 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7059 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 7060 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7061 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7062 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7063 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7064 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7065 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7066 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7067 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7068 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7069 | } |
| 7070 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7071 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7072 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7073 | tmp) |
| 7074 | n_ssids++; |
| 7075 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7076 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7077 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7078 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7079 | /* |
| 7080 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7081 | * the old implementation, matchsets containing only the RSSI attribute |
| 7082 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7083 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7084 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7085 | * older userspace that treated a matchset with only the RSSI as the |
| 7086 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7087 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7088 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7089 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7090 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7091 | tmp) { |
| 7092 | struct nlattr *rssi; |
| 7093 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7094 | err = nla_parse_nested(tb, |
| 7095 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7096 | attr, nl80211_match_policy, |
| 7097 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7098 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7099 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7100 | |
| 7101 | /* SSID and BSSID are mutually exclusive */ |
| 7102 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 7103 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 7104 | return ERR_PTR(-EINVAL); |
| 7105 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7106 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7107 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 7108 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7109 | n_match_sets++; |
| 7110 | continue; |
| 7111 | } |
| 7112 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7113 | if (rssi) |
| 7114 | default_match_rssi = nla_get_s32(rssi); |
| 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | /* However, if there's no other matchset, add the RSSI one */ |
| 7119 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7120 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7121 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7122 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7123 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7124 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7125 | if (attrs[NL80211_ATTR_IE]) |
| 7126 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7127 | else |
| 7128 | ie_len = 0; |
| 7129 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7130 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7131 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7132 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7133 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7134 | /* |
| 7135 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7136 | * each scan plan already specifies its own interval |
| 7137 | */ |
| 7138 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7139 | return ERR_PTR(-EINVAL); |
| 7140 | |
| 7141 | nla_for_each_nested(attr, |
| 7142 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7143 | n_plans++; |
| 7144 | } else { |
| 7145 | /* |
| 7146 | * The scan interval attribute is kept for backward |
| 7147 | * compatibility. If no scan plans are specified and sched scan |
| 7148 | * interval is specified, one scan plan will be set with this |
| 7149 | * scan interval and infinite number of iterations. |
| 7150 | */ |
| 7151 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7152 | return ERR_PTR(-EINVAL); |
| 7153 | |
| 7154 | n_plans = 1; |
| 7155 | } |
| 7156 | |
| 7157 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7158 | return ERR_PTR(-EINVAL); |
| 7159 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7160 | if (!wiphy_ext_feature_isset( |
| 7161 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7162 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7163 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7164 | return ERR_PTR(-EINVAL); |
| 7165 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7166 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7167 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7168 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7169 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7170 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7171 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7172 | if (!request) |
| 7173 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7174 | |
| 7175 | if (n_ssids) |
| 7176 | request->ssids = (void *)&request->channels[n_channels]; |
| 7177 | request->n_ssids = n_ssids; |
| 7178 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7179 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7180 | request->ie = (void *)(request->ssids + n_ssids); |
| 7181 | else |
| 7182 | request->ie = (void *)(request->channels + n_channels); |
| 7183 | } |
| 7184 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7185 | if (n_match_sets) { |
| 7186 | if (request->ie) |
| 7187 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7188 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7189 | request->match_sets = |
| 7190 | (void *)(request->ssids + n_ssids); |
| 7191 | else |
| 7192 | request->match_sets = |
| 7193 | (void *)(request->channels + n_channels); |
| 7194 | } |
| 7195 | request->n_match_sets = n_match_sets; |
| 7196 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7197 | if (n_match_sets) |
| 7198 | request->scan_plans = (void *)(request->match_sets + |
| 7199 | n_match_sets); |
| 7200 | else if (request->ie) |
| 7201 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7202 | else if (n_ssids) |
| 7203 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7204 | else |
| 7205 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7206 | |
| 7207 | request->n_scan_plans = n_plans; |
| 7208 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7209 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7210 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7211 | /* user specified, bail out if channel not found */ |
| 7212 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7213 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7214 | tmp) { |
| 7215 | struct ieee80211_channel *chan; |
| 7216 | |
| 7217 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7218 | |
| 7219 | if (!chan) { |
| 7220 | err = -EINVAL; |
| 7221 | goto out_free; |
| 7222 | } |
| 7223 | |
| 7224 | /* ignore disabled channels */ |
| 7225 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7226 | continue; |
| 7227 | |
| 7228 | request->channels[i] = chan; |
| 7229 | i++; |
| 7230 | } |
| 7231 | } else { |
| 7232 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7233 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7234 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7235 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7236 | if (!wiphy->bands[band]) |
| 7237 | continue; |
| 7238 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7239 | struct ieee80211_channel *chan; |
| 7240 | |
| 7241 | chan = &wiphy->bands[band]->channels[j]; |
| 7242 | |
| 7243 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7244 | continue; |
| 7245 | |
| 7246 | request->channels[i] = chan; |
| 7247 | i++; |
| 7248 | } |
| 7249 | } |
| 7250 | } |
| 7251 | |
| 7252 | if (!i) { |
| 7253 | err = -EINVAL; |
| 7254 | goto out_free; |
| 7255 | } |
| 7256 | |
| 7257 | request->n_channels = i; |
| 7258 | |
| 7259 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7260 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7261 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7262 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7263 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7264 | err = -EINVAL; |
| 7265 | goto out_free; |
| 7266 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7267 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7268 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7269 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7270 | i++; |
| 7271 | } |
| 7272 | } |
| 7273 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7274 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7275 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7276 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7277 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7278 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7279 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7280 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7281 | err = nla_parse_nested(tb, |
| 7282 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 7283 | attr, nl80211_match_policy, |
| 7284 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7285 | if (err) |
| 7286 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7287 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7288 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| 7289 | if (ssid || bssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7290 | if (WARN_ON(i >= n_match_sets)) { |
| 7291 | /* this indicates a programming error, |
| 7292 | * the loop above should have verified |
| 7293 | * things properly |
| 7294 | */ |
| 7295 | err = -EINVAL; |
| 7296 | goto out_free; |
| 7297 | } |
| 7298 | |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7299 | if (ssid) { |
| 7300 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7301 | err = -EINVAL; |
| 7302 | goto out_free; |
| 7303 | } |
| 7304 | memcpy(request->match_sets[i].ssid.ssid, |
| 7305 | nla_data(ssid), nla_len(ssid)); |
| 7306 | request->match_sets[i].ssid.ssid_len = |
| 7307 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7308 | } |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 7309 | if (bssid) { |
| 7310 | if (nla_len(bssid) != ETH_ALEN) { |
| 7311 | err = -EINVAL; |
| 7312 | goto out_free; |
| 7313 | } |
| 7314 | memcpy(request->match_sets[i].bssid, |
| 7315 | nla_data(bssid), ETH_ALEN); |
| 7316 | } |
| 7317 | |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7318 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7319 | request->match_sets[i].rssi_thold = |
| 7320 | default_match_rssi; |
| 7321 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7322 | if (rssi) |
| 7323 | request->match_sets[i].rssi_thold = |
| 7324 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7325 | } |
| 7326 | i++; |
| 7327 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7328 | |
| 7329 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7330 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7331 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7332 | |
| 7333 | request->min_rssi_thold = INT_MAX; |
| 7334 | for (i = 0; i < n_match_sets; i++) |
| 7335 | request->min_rssi_thold = |
| 7336 | min(request->match_sets[i].rssi_thold, |
| 7337 | request->min_rssi_thold); |
| 7338 | } else { |
| 7339 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7340 | } |
| 7341 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7342 | if (ie_len) { |
| 7343 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7344 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7345 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7346 | request->ie_len); |
| 7347 | } |
| 7348 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7349 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 7350 | if (err) |
| 7351 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7352 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7353 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7354 | request->delay = |
| 7355 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7356 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7357 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7358 | request->relative_rssi = nla_get_s8( |
| 7359 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7360 | request->relative_rssi_set = true; |
| 7361 | } |
| 7362 | |
| 7363 | if (request->relative_rssi_set && |
| 7364 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7365 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7366 | |
| 7367 | rssi_adjust = nla_data( |
| 7368 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7369 | request->rssi_adjust.band = rssi_adjust->band; |
| 7370 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7371 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7372 | err = -EINVAL; |
| 7373 | goto out_free; |
| 7374 | } |
| 7375 | } |
| 7376 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7377 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7378 | if (err) |
| 7379 | goto out_free; |
| 7380 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7381 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7382 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7383 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7384 | |
| 7385 | out_free: |
| 7386 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7387 | return ERR_PTR(err); |
| 7388 | } |
| 7389 | |
| 7390 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7391 | struct genl_info *info) |
| 7392 | { |
| 7393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7394 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7395 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7396 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7397 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7398 | int err; |
| 7399 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7400 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7401 | return -EOPNOTSUPP; |
| 7402 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7403 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 7404 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 7405 | if (err) |
| 7406 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7407 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7408 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7409 | info->attrs, |
| 7410 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7411 | |
| 7412 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7413 | if (err) |
| 7414 | goto out_err; |
| 7415 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7416 | /* leave request id zero for legacy request |
| 7417 | * or if driver does not support multi-scheduled scan |
| 7418 | */ |
| 7419 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { |
| 7420 | while (!sched_scan_req->reqid) |
| 7421 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; |
| 7422 | } |
| 7423 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7424 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7425 | if (err) |
| 7426 | goto out_free; |
| 7427 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7428 | sched_scan_req->dev = dev; |
| 7429 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7430 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7431 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7432 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7433 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7434 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7435 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7436 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7437 | return 0; |
| 7438 | |
| 7439 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7440 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7441 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7442 | return err; |
| 7443 | } |
| 7444 | |
| 7445 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7446 | struct genl_info *info) |
| 7447 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7448 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7450 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7451 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7452 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7453 | return -EOPNOTSUPP; |
| 7454 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 7455 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 7456 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7457 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 7458 | } |
| 7459 | |
| 7460 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 7461 | struct cfg80211_sched_scan_request, |
| 7462 | list); |
| 7463 | if (!req || req->reqid || |
| 7464 | (req->owner_nlportid && |
| 7465 | req->owner_nlportid != info->snd_portid)) |
| 7466 | return -ENOENT; |
| 7467 | |
| 7468 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7469 | } |
| 7470 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7471 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7472 | struct genl_info *info) |
| 7473 | { |
| 7474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7475 | struct net_device *dev = info->user_ptr[1]; |
| 7476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7477 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7478 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7479 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7480 | int err; |
| 7481 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7482 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7483 | if (dfs_region == NL80211_DFS_UNSET) |
| 7484 | return -EINVAL; |
| 7485 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7486 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7487 | if (err) |
| 7488 | return err; |
| 7489 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7490 | if (netif_carrier_ok(dev)) |
| 7491 | return -EBUSY; |
| 7492 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7493 | if (wdev->cac_started) |
| 7494 | return -EBUSY; |
| 7495 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7496 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7497 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7498 | if (err < 0) |
| 7499 | return err; |
| 7500 | |
| 7501 | if (err == 0) |
| 7502 | return -EINVAL; |
| 7503 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7504 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7505 | return -EINVAL; |
| 7506 | |
| 7507 | if (!rdev->ops->start_radar_detection) |
| 7508 | return -EOPNOTSUPP; |
| 7509 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7510 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7511 | if (WARN_ON(!cac_time_ms)) |
| 7512 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7513 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7514 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7515 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7516 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7517 | wdev->cac_started = true; |
| 7518 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7519 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7520 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7521 | return err; |
| 7522 | } |
| 7523 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7524 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7525 | { |
| 7526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7527 | struct net_device *dev = info->user_ptr[1]; |
| 7528 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7529 | struct cfg80211_csa_settings params; |
| 7530 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7531 | * function is called under RTNL lock, so this should not be a problem. |
| 7532 | */ |
| 7533 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7534 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7535 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7536 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7537 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7538 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7539 | |
| 7540 | if (!rdev->ops->channel_switch || |
| 7541 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7542 | return -EOPNOTSUPP; |
| 7543 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7544 | switch (dev->ieee80211_ptr->iftype) { |
| 7545 | case NL80211_IFTYPE_AP: |
| 7546 | case NL80211_IFTYPE_P2P_GO: |
| 7547 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7548 | /* For all modes except AP the handle_dfs flag needs to be |
| 7549 | * supplied to tell the kernel that userspace will handle radar |
| 7550 | * events when they happen. Otherwise a switch to a channel |
| 7551 | * requiring DFS will be rejected. |
| 7552 | */ |
| 7553 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7554 | |
| 7555 | /* useless if AP is not running */ |
| 7556 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7557 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7558 | break; |
| 7559 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7560 | if (!wdev->ssid_len) |
| 7561 | return -ENOTCONN; |
| 7562 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7563 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7564 | if (!wdev->mesh_id_len) |
| 7565 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7566 | break; |
| 7567 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7568 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7569 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7570 | |
| 7571 | memset(¶ms, 0, sizeof(params)); |
| 7572 | |
| 7573 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7574 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7575 | return -EINVAL; |
| 7576 | |
| 7577 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7578 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7579 | return -EINVAL; |
| 7580 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7581 | /* Even though the attribute is u32, the specification says |
| 7582 | * u8, so let's make sure we don't overflow. |
| 7583 | */ |
| 7584 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7585 | if (cs_count > 255) |
| 7586 | return -EINVAL; |
| 7587 | |
| 7588 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7589 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7590 | if (!need_new_beacon) |
| 7591 | goto skip_beacons; |
| 7592 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7593 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7594 | if (err) |
| 7595 | return err; |
| 7596 | |
| 7597 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7598 | info->attrs[NL80211_ATTR_CSA_IES], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 7599 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7600 | if (err) |
| 7601 | return err; |
| 7602 | |
| 7603 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7604 | if (err) |
| 7605 | return err; |
| 7606 | |
| 7607 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7608 | return -EINVAL; |
| 7609 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7610 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7611 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7612 | return -EINVAL; |
| 7613 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7614 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7615 | if (rdev->wiphy.max_num_csa_counters && |
| 7616 | (params.n_counter_offsets_beacon > |
| 7617 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7618 | return -EINVAL; |
| 7619 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7620 | params.counter_offsets_beacon = |
| 7621 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7622 | |
| 7623 | /* sanity checks - counters should fit and be the same */ |
| 7624 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7625 | u16 offset = params.counter_offsets_beacon[i]; |
| 7626 | |
| 7627 | if (offset >= params.beacon_csa.tail_len) |
| 7628 | return -EINVAL; |
| 7629 | |
| 7630 | if (params.beacon_csa.tail[offset] != params.count) |
| 7631 | return -EINVAL; |
| 7632 | } |
| 7633 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7634 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7635 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7636 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7637 | return -EINVAL; |
| 7638 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7639 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7640 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7641 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7642 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7643 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7644 | |
| 7645 | params.counter_offsets_presp = |
| 7646 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7647 | |
| 7648 | /* sanity checks - counters should fit and be the same */ |
| 7649 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7650 | u16 offset = params.counter_offsets_presp[i]; |
| 7651 | |
| 7652 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7653 | return -EINVAL; |
| 7654 | |
| 7655 | if (params.beacon_csa.probe_resp[offset] != |
| 7656 | params.count) |
| 7657 | return -EINVAL; |
| 7658 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7659 | } |
| 7660 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7661 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7662 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7663 | if (err) |
| 7664 | return err; |
| 7665 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7666 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7667 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7668 | return -EINVAL; |
| 7669 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7670 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7671 | ¶ms.chandef, |
| 7672 | wdev->iftype); |
| 7673 | if (err < 0) |
| 7674 | return err; |
| 7675 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7676 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7677 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 7678 | if (need_handle_dfs_flag && |
| 7679 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 7680 | return -EINVAL; |
| 7681 | } |
| 7682 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7683 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7684 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7685 | params.block_tx = true; |
| 7686 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7687 | wdev_lock(wdev); |
| 7688 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7689 | wdev_unlock(wdev); |
| 7690 | |
| 7691 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7692 | } |
| 7693 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7694 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7695 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7696 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7697 | struct wireless_dev *wdev, |
| 7698 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7699 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7700 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7701 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7702 | void *hdr; |
| 7703 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7704 | |
| 7705 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7706 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7707 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7708 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7709 | if (!hdr) |
| 7710 | return -1; |
| 7711 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7712 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7713 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7714 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7715 | goto nla_put_failure; |
| 7716 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7717 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7718 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7719 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7720 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7721 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7722 | |
| 7723 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7724 | if (!bss) |
| 7725 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7726 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7727 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7728 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7729 | |
| 7730 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7731 | /* indicate whether we have probe response data or not */ |
| 7732 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7733 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7734 | goto fail_unlock_rcu; |
| 7735 | |
| 7736 | /* this pointer prefers to be pointed to probe response data |
| 7737 | * but is always valid |
| 7738 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7739 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7740 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7741 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7742 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7743 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7744 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7745 | ies->len, ies->data)) |
| 7746 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7747 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7748 | |
| 7749 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7750 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7751 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7752 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7753 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7754 | goto fail_unlock_rcu; |
| 7755 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7756 | ies->len, ies->data)) |
| 7757 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7758 | } |
| 7759 | rcu_read_unlock(); |
| 7760 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7761 | if (res->beacon_interval && |
| 7762 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7763 | goto nla_put_failure; |
| 7764 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7765 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7766 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7767 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7768 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7769 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7770 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7771 | if (intbss->parent_tsf && |
| 7772 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7773 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7774 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7775 | intbss->parent_bssid))) |
| 7776 | goto nla_put_failure; |
| 7777 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7778 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7779 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7780 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7781 | goto nla_put_failure; |
| 7782 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7783 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7784 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7785 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7786 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7787 | break; |
| 7788 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7789 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7790 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7791 | break; |
| 7792 | default: |
| 7793 | break; |
| 7794 | } |
| 7795 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7796 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7797 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7798 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7799 | if (intbss == wdev->current_bss && |
| 7800 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7801 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7802 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7803 | break; |
| 7804 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7805 | if (intbss == wdev->current_bss && |
| 7806 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7807 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7808 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7809 | break; |
| 7810 | default: |
| 7811 | break; |
| 7812 | } |
| 7813 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7814 | nla_nest_end(msg, bss); |
| 7815 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7816 | genlmsg_end(msg, hdr); |
| 7817 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7818 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7819 | fail_unlock_rcu: |
| 7820 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7821 | nla_put_failure: |
| 7822 | genlmsg_cancel(msg, hdr); |
| 7823 | return -EMSGSIZE; |
| 7824 | } |
| 7825 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7826 | 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] | 7827 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7828 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7829 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7830 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7831 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7832 | int err; |
| 7833 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7834 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7835 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7836 | if (err) { |
| 7837 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7838 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7839 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7840 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7841 | wdev_lock(wdev); |
| 7842 | spin_lock_bh(&rdev->bss_lock); |
| 7843 | cfg80211_bss_expire(rdev); |
| 7844 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7845 | cb->seq = rdev->bss_generation; |
| 7846 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7847 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7848 | if (++idx <= start) |
| 7849 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7850 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7851 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7852 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7853 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7854 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7855 | } |
| 7856 | } |
| 7857 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7858 | spin_unlock_bh(&rdev->bss_lock); |
| 7859 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7860 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7861 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7862 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7863 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7864 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7865 | } |
| 7866 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7867 | 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] | 7868 | int flags, struct net_device *dev, |
| 7869 | bool allow_radio_stats, |
| 7870 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7871 | { |
| 7872 | void *hdr; |
| 7873 | struct nlattr *infoattr; |
| 7874 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7875 | /* skip radio stats if userspace didn't request them */ |
| 7876 | if (!survey->channel && !allow_radio_stats) |
| 7877 | return 0; |
| 7878 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7879 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7880 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7881 | if (!hdr) |
| 7882 | return -ENOMEM; |
| 7883 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7884 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7885 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7886 | |
| 7887 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7888 | if (!infoattr) |
| 7889 | goto nla_put_failure; |
| 7890 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7891 | if (survey->channel && |
| 7892 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7893 | survey->channel->center_freq)) |
| 7894 | goto nla_put_failure; |
| 7895 | |
| 7896 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7897 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7898 | goto nla_put_failure; |
| 7899 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7900 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7901 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7902 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7903 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7904 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7905 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7906 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7907 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7908 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7909 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7910 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7911 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7912 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7913 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7914 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7915 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7916 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7917 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7918 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7919 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7920 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7921 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7922 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7923 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7924 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7925 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7926 | |
| 7927 | nla_nest_end(msg, infoattr); |
| 7928 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7929 | genlmsg_end(msg, hdr); |
| 7930 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7931 | |
| 7932 | nla_put_failure: |
| 7933 | genlmsg_cancel(msg, hdr); |
| 7934 | return -EMSGSIZE; |
| 7935 | } |
| 7936 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7937 | 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] | 7938 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7939 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7940 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7941 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7942 | struct wireless_dev *wdev; |
| 7943 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7944 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7945 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7946 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7947 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7948 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7949 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7950 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7951 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7952 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7953 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7954 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7955 | if (!wdev->netdev) { |
| 7956 | res = -EINVAL; |
| 7957 | goto out_err; |
| 7958 | } |
| 7959 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7960 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7961 | res = -EOPNOTSUPP; |
| 7962 | goto out_err; |
| 7963 | } |
| 7964 | |
| 7965 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7966 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7967 | if (res == -ENOENT) |
| 7968 | break; |
| 7969 | if (res) |
| 7970 | goto out_err; |
| 7971 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7972 | /* don't send disabled channels, but do send non-channel data */ |
| 7973 | if (survey.channel && |
| 7974 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7975 | survey_idx++; |
| 7976 | continue; |
| 7977 | } |
| 7978 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7979 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7980 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7981 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7982 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7983 | goto out; |
| 7984 | survey_idx++; |
| 7985 | } |
| 7986 | |
| 7987 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7988 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7989 | res = skb->len; |
| 7990 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7991 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7992 | return res; |
| 7993 | } |
| 7994 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7995 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7996 | { |
| 7997 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7998 | NL80211_WPA_VERSION_2)); |
| 7999 | } |
| 8000 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8001 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 8002 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8004 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8005 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8006 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 8007 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8008 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8009 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8010 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8011 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8012 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8013 | return -EINVAL; |
| 8014 | |
| 8015 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8016 | return -EINVAL; |
| 8017 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 8018 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 8019 | return -EINVAL; |
| 8020 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8021 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 8022 | return -EINVAL; |
| 8023 | |
| 8024 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8025 | return -EINVAL; |
| 8026 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8027 | err = nl80211_parse_key(info, &key); |
| 8028 | if (err) |
| 8029 | return err; |
| 8030 | |
| 8031 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 8032 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 8033 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8034 | if (!key.p.key || !key.p.key_len) |
| 8035 | return -EINVAL; |
| 8036 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 8037 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 8038 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 8039 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 8040 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 8041 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8042 | return -EINVAL; |
| 8043 | } else { |
| 8044 | key.p.key_len = 0; |
| 8045 | key.p.key = NULL; |
| 8046 | } |
| 8047 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8048 | if (key.idx >= 0) { |
| 8049 | int i; |
| 8050 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8051 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8052 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 8053 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 8054 | ok = true; |
| 8055 | break; |
| 8056 | } |
| 8057 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8058 | if (!ok) |
| 8059 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 8060 | } |
| 8061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8062 | if (!rdev->ops->auth) |
| 8063 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8064 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8065 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8066 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8067 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8068 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8069 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8070 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8071 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8072 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8073 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8074 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8075 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8076 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8077 | |
| 8078 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8079 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8080 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8081 | } |
| 8082 | |
| 8083 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8084 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8085 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8086 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8087 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 8088 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 8089 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 8090 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8091 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8092 | return -EINVAL; |
| 8093 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8094 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8095 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8096 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8097 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8098 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8099 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8100 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8101 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8102 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8103 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8104 | return -EINVAL; |
| 8105 | } |
| 8106 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8107 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8108 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8109 | /* |
| 8110 | * Since we no longer track auth state, ignore |
| 8111 | * requests to only change local state. |
| 8112 | */ |
| 8113 | if (local_state_change) |
| 8114 | return 0; |
| 8115 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8116 | wdev_lock(dev->ieee80211_ptr); |
| 8117 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8118 | ssid, ssid_len, ie, ie_len, |
| 8119 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8120 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8121 | wdev_unlock(dev->ieee80211_ptr); |
| 8122 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8123 | } |
| 8124 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8125 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8126 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8127 | struct cfg80211_crypto_settings *settings, |
| 8128 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8129 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8130 | memset(settings, 0, sizeof(*settings)); |
| 8131 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8132 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8133 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8134 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8135 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8136 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8137 | proto = nla_get_u16( |
| 8138 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8139 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8140 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8141 | proto != ETH_P_PAE) |
| 8142 | return -EINVAL; |
| 8143 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8144 | settings->control_port_no_encrypt = true; |
| 8145 | } else |
| 8146 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8147 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8148 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8149 | void *data; |
| 8150 | int len, i; |
| 8151 | |
| 8152 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8153 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8154 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8155 | |
| 8156 | if (len % sizeof(u32)) |
| 8157 | return -EINVAL; |
| 8158 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8159 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8160 | return -EINVAL; |
| 8161 | |
| 8162 | memcpy(settings->ciphers_pairwise, data, len); |
| 8163 | |
| 8164 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8165 | if (!cfg80211_supported_cipher_suite( |
| 8166 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8167 | settings->ciphers_pairwise[i])) |
| 8168 | return -EINVAL; |
| 8169 | } |
| 8170 | |
| 8171 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8172 | settings->cipher_group = |
| 8173 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8174 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8175 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8176 | return -EINVAL; |
| 8177 | } |
| 8178 | |
| 8179 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8180 | settings->wpa_versions = |
| 8181 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8182 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8183 | return -EINVAL; |
| 8184 | } |
| 8185 | |
| 8186 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8187 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8188 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8189 | |
| 8190 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8191 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8192 | settings->n_akm_suites = len / sizeof(u32); |
| 8193 | |
| 8194 | if (len % sizeof(u32)) |
| 8195 | return -EINVAL; |
| 8196 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8197 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8198 | return -EINVAL; |
| 8199 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8200 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8201 | } |
| 8202 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 8203 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 8204 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 8205 | return -EINVAL; |
| 8206 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8207 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) |
| 8208 | return -EINVAL; |
| 8209 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 8210 | } |
| 8211 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8212 | return 0; |
| 8213 | } |
| 8214 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8215 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8216 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8218 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8219 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8220 | struct cfg80211_assoc_request req = {}; |
| 8221 | const u8 *bssid, *ssid; |
| 8222 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8223 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8224 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8225 | return -EINVAL; |
| 8226 | |
| 8227 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8228 | !info->attrs[NL80211_ATTR_SSID] || |
| 8229 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8230 | return -EINVAL; |
| 8231 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8232 | if (!rdev->ops->assoc) |
| 8233 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8234 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8236 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8237 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8238 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8239 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8240 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8241 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8242 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8243 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8244 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8245 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8246 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8247 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8248 | |
| 8249 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8250 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8251 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8252 | } |
| 8253 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8254 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8255 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8256 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8257 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8258 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8259 | else if (mfp != NL80211_MFP_NO) |
| 8260 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8261 | } |
| 8262 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8263 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8264 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8265 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8266 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8267 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8268 | |
| 8269 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8270 | memcpy(&req.ht_capa_mask, |
| 8271 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8272 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8273 | |
| 8274 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8275 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8276 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8277 | memcpy(&req.ht_capa, |
| 8278 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8279 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8280 | } |
| 8281 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8282 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8283 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8284 | |
| 8285 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8286 | memcpy(&req.vht_capa_mask, |
| 8287 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8288 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8289 | |
| 8290 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8291 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8292 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8293 | memcpy(&req.vht_capa, |
| 8294 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8295 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8296 | } |
| 8297 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8298 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8299 | if (!((rdev->wiphy.features & |
| 8300 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8301 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8302 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8303 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8304 | return -EINVAL; |
| 8305 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8306 | } |
| 8307 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8308 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8309 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8310 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8311 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8312 | return -EINVAL; |
| 8313 | req.fils_nonces = |
| 8314 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8315 | } |
| 8316 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8317 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8318 | if (!err) { |
| 8319 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8320 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8321 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8322 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8323 | |
| 8324 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8325 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8326 | info->snd_portid; |
| 8327 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8328 | bssid, ETH_ALEN); |
| 8329 | } |
| 8330 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8331 | wdev_unlock(dev->ieee80211_ptr); |
| 8332 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8333 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8334 | return err; |
| 8335 | } |
| 8336 | |
| 8337 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8340 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8341 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8342 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8343 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8344 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8345 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8346 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8347 | return -EINVAL; |
| 8348 | |
| 8349 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8350 | return -EINVAL; |
| 8351 | |
| 8352 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8353 | return -EINVAL; |
| 8354 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8355 | if (!rdev->ops->deauth) |
| 8356 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8357 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8358 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8359 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8360 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8361 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8362 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8363 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8364 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8365 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8366 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8367 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8368 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8369 | |
| 8370 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8371 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8372 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8373 | } |
| 8374 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8375 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8376 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8377 | wdev_lock(dev->ieee80211_ptr); |
| 8378 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8379 | local_state_change); |
| 8380 | wdev_unlock(dev->ieee80211_ptr); |
| 8381 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8382 | } |
| 8383 | |
| 8384 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8387 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8388 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8389 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8390 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8391 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8392 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8393 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8394 | return -EINVAL; |
| 8395 | |
| 8396 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8397 | return -EINVAL; |
| 8398 | |
| 8399 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8400 | return -EINVAL; |
| 8401 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8402 | if (!rdev->ops->disassoc) |
| 8403 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8404 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8405 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8406 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8407 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8408 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8409 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8410 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8411 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8412 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8413 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8414 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8415 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8416 | |
| 8417 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8418 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8419 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8420 | } |
| 8421 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8422 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8423 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8424 | wdev_lock(dev->ieee80211_ptr); |
| 8425 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8426 | local_state_change); |
| 8427 | wdev_unlock(dev->ieee80211_ptr); |
| 8428 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8429 | } |
| 8430 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8431 | static bool |
| 8432 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8433 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8434 | int rateval) |
| 8435 | { |
| 8436 | struct wiphy *wiphy = &rdev->wiphy; |
| 8437 | bool found = false; |
| 8438 | int band, i; |
| 8439 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8440 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8441 | struct ieee80211_supported_band *sband; |
| 8442 | |
| 8443 | sband = wiphy->bands[band]; |
| 8444 | if (!sband) |
| 8445 | continue; |
| 8446 | |
| 8447 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8448 | if (sband->bitrates[i].bitrate == rateval) { |
| 8449 | mcast_rate[band] = i + 1; |
| 8450 | found = true; |
| 8451 | break; |
| 8452 | } |
| 8453 | } |
| 8454 | } |
| 8455 | |
| 8456 | return found; |
| 8457 | } |
| 8458 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8459 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8460 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8462 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8463 | struct cfg80211_ibss_params ibss; |
| 8464 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8465 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8466 | int err; |
| 8467 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8468 | memset(&ibss, 0, sizeof(ibss)); |
| 8469 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8470 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8471 | return -EINVAL; |
| 8472 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8473 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8474 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8475 | return -EINVAL; |
| 8476 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8477 | ibss.beacon_interval = 100; |
| 8478 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8479 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8480 | ibss.beacon_interval = |
| 8481 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8482 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8483 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8484 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8485 | if (err) |
| 8486 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8488 | if (!rdev->ops->join_ibss) |
| 8489 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8490 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8492 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8493 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8494 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8495 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8496 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8497 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8498 | |
| 8499 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8500 | return -EINVAL; |
| 8501 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8502 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8503 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8504 | |
| 8505 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8506 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8507 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8508 | } |
| 8509 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8510 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8511 | if (err) |
| 8512 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8513 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8514 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8515 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8516 | return -EINVAL; |
| 8517 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8518 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8519 | case NL80211_CHAN_WIDTH_5: |
| 8520 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8521 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8522 | break; |
| 8523 | case NL80211_CHAN_WIDTH_20: |
| 8524 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8525 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8526 | return -EINVAL; |
| 8527 | break; |
| 8528 | case NL80211_CHAN_WIDTH_80: |
| 8529 | case NL80211_CHAN_WIDTH_80P80: |
| 8530 | case NL80211_CHAN_WIDTH_160: |
| 8531 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8532 | return -EINVAL; |
| 8533 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8534 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8535 | return -EINVAL; |
| 8536 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8537 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8538 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8539 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8540 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8541 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8542 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8543 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8544 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8545 | u8 *rates = |
| 8546 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8547 | int n_rates = |
| 8548 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8549 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8550 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8551 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8552 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8553 | &ibss.basic_rates); |
| 8554 | if (err) |
| 8555 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8556 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8557 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8558 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8559 | memcpy(&ibss.ht_capa_mask, |
| 8560 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8561 | sizeof(ibss.ht_capa_mask)); |
| 8562 | |
| 8563 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8564 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8565 | return -EINVAL; |
| 8566 | memcpy(&ibss.ht_capa, |
| 8567 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8568 | sizeof(ibss.ht_capa)); |
| 8569 | } |
| 8570 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8571 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8572 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8573 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8574 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8575 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8576 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8577 | bool no_ht = false; |
| 8578 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8579 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8580 | info->attrs[NL80211_ATTR_KEYS], |
| 8581 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8582 | if (IS_ERR(connkeys)) |
| 8583 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8584 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8585 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8586 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8587 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8588 | return -EINVAL; |
| 8589 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8590 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8591 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8592 | ibss.control_port = |
| 8593 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8594 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8595 | ibss.userspace_handles_dfs = |
| 8596 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8597 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8598 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8599 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8600 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8601 | return err; |
| 8602 | } |
| 8603 | |
| 8604 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8605 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8607 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8608 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8609 | if (!rdev->ops->leave_ibss) |
| 8610 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8612 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8613 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8614 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8615 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8616 | } |
| 8617 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8618 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8619 | { |
| 8620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8621 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8622 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8623 | u32 nla_rate; |
| 8624 | int err; |
| 8625 | |
| 8626 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8627 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8628 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8629 | return -EOPNOTSUPP; |
| 8630 | |
| 8631 | if (!rdev->ops->set_mcast_rate) |
| 8632 | return -EOPNOTSUPP; |
| 8633 | |
| 8634 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8635 | |
| 8636 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8637 | return -EINVAL; |
| 8638 | |
| 8639 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8640 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8641 | return -EINVAL; |
| 8642 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8643 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8644 | |
| 8645 | return err; |
| 8646 | } |
| 8647 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8648 | static struct sk_buff * |
| 8649 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8650 | struct wireless_dev *wdev, int approxlen, |
| 8651 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8652 | enum nl80211_attrs attr, |
| 8653 | const struct nl80211_vendor_cmd_info *info, |
| 8654 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8655 | { |
| 8656 | struct sk_buff *skb; |
| 8657 | void *hdr; |
| 8658 | struct nlattr *data; |
| 8659 | |
| 8660 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8661 | if (!skb) |
| 8662 | return NULL; |
| 8663 | |
| 8664 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8665 | if (!hdr) { |
| 8666 | kfree_skb(skb); |
| 8667 | return NULL; |
| 8668 | } |
| 8669 | |
| 8670 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8671 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8672 | |
| 8673 | if (info) { |
| 8674 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8675 | info->vendor_id)) |
| 8676 | goto nla_put_failure; |
| 8677 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8678 | info->subcmd)) |
| 8679 | goto nla_put_failure; |
| 8680 | } |
| 8681 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8682 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8683 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8684 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8685 | goto nla_put_failure; |
| 8686 | if (wdev->netdev && |
| 8687 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8688 | wdev->netdev->ifindex)) |
| 8689 | goto nla_put_failure; |
| 8690 | } |
| 8691 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8692 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8693 | if (!data) |
| 8694 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8695 | |
| 8696 | ((void **)skb->cb)[0] = rdev; |
| 8697 | ((void **)skb->cb)[1] = hdr; |
| 8698 | ((void **)skb->cb)[2] = data; |
| 8699 | |
| 8700 | return skb; |
| 8701 | |
| 8702 | nla_put_failure: |
| 8703 | kfree_skb(skb); |
| 8704 | return NULL; |
| 8705 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8706 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8707 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8708 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8709 | enum nl80211_commands cmd, |
| 8710 | enum nl80211_attrs attr, |
| 8711 | int vendor_event_idx, |
| 8712 | int approxlen, gfp_t gfp) |
| 8713 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8714 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8715 | const struct nl80211_vendor_cmd_info *info; |
| 8716 | |
| 8717 | switch (cmd) { |
| 8718 | case NL80211_CMD_TESTMODE: |
| 8719 | if (WARN_ON(vendor_event_idx != -1)) |
| 8720 | return NULL; |
| 8721 | info = NULL; |
| 8722 | break; |
| 8723 | case NL80211_CMD_VENDOR: |
| 8724 | if (WARN_ON(vendor_event_idx < 0 || |
| 8725 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8726 | return NULL; |
| 8727 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8728 | break; |
| 8729 | default: |
| 8730 | WARN_ON(1); |
| 8731 | return NULL; |
| 8732 | } |
| 8733 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8734 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8735 | cmd, attr, info, gfp); |
| 8736 | } |
| 8737 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8738 | |
| 8739 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8740 | { |
| 8741 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8742 | void *hdr = ((void **)skb->cb)[1]; |
| 8743 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8744 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8745 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8746 | /* clear CB data for netlink core to own from now on */ |
| 8747 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8748 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8749 | nla_nest_end(skb, data); |
| 8750 | genlmsg_end(skb, hdr); |
| 8751 | |
| 8752 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8753 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8754 | |
| 8755 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8756 | mcgrp, gfp); |
| 8757 | } |
| 8758 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8759 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8760 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8761 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8764 | struct wireless_dev *wdev = |
| 8765 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8766 | int err; |
| 8767 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8768 | if (!rdev->ops->testmode_cmd) |
| 8769 | return -EOPNOTSUPP; |
| 8770 | |
| 8771 | if (IS_ERR(wdev)) { |
| 8772 | err = PTR_ERR(wdev); |
| 8773 | if (err != -EINVAL) |
| 8774 | return err; |
| 8775 | wdev = NULL; |
| 8776 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8777 | return -EINVAL; |
| 8778 | } |
| 8779 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8780 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8781 | return -EINVAL; |
| 8782 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8783 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8784 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8785 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8786 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8787 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8788 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8789 | return err; |
| 8790 | } |
| 8791 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8792 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8793 | struct netlink_callback *cb) |
| 8794 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8795 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8796 | int err; |
| 8797 | long phy_idx; |
| 8798 | void *data = NULL; |
| 8799 | int data_len = 0; |
| 8800 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8801 | rtnl_lock(); |
| 8802 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8803 | if (cb->args[0]) { |
| 8804 | /* |
| 8805 | * 0 is a valid index, but not valid for args[0], |
| 8806 | * so we need to offset by 1. |
| 8807 | */ |
| 8808 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 8809 | |
| 8810 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8811 | if (!rdev) { |
| 8812 | err = -ENOENT; |
| 8813 | goto out_err; |
| 8814 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8815 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8816 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 8817 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8818 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 8819 | attrbuf, nl80211_fam.maxattr, |
| 8820 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8821 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8822 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8823 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8824 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8825 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8826 | err = PTR_ERR(rdev); |
| 8827 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8828 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8829 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8830 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8831 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 8832 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8833 | } |
| 8834 | |
| 8835 | if (cb->args[1]) { |
| 8836 | data = nla_data((void *)cb->args[1]); |
| 8837 | data_len = nla_len((void *)cb->args[1]); |
| 8838 | } |
| 8839 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8840 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8841 | err = -EOPNOTSUPP; |
| 8842 | goto out_err; |
| 8843 | } |
| 8844 | |
| 8845 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8846 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8847 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8848 | NL80211_CMD_TESTMODE); |
| 8849 | struct nlattr *tmdata; |
| 8850 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8851 | if (!hdr) |
| 8852 | break; |
| 8853 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8854 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8855 | genlmsg_cancel(skb, hdr); |
| 8856 | break; |
| 8857 | } |
| 8858 | |
| 8859 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8860 | if (!tmdata) { |
| 8861 | genlmsg_cancel(skb, hdr); |
| 8862 | break; |
| 8863 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8864 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8865 | nla_nest_end(skb, tmdata); |
| 8866 | |
| 8867 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8868 | genlmsg_cancel(skb, hdr); |
| 8869 | break; |
| 8870 | } else if (err) { |
| 8871 | genlmsg_cancel(skb, hdr); |
| 8872 | goto out_err; |
| 8873 | } |
| 8874 | |
| 8875 | genlmsg_end(skb, hdr); |
| 8876 | } |
| 8877 | |
| 8878 | err = skb->len; |
| 8879 | /* see above */ |
| 8880 | cb->args[0] = phy_idx + 1; |
| 8881 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8882 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8883 | return err; |
| 8884 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8885 | #endif |
| 8886 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8887 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8890 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8891 | struct cfg80211_connect_params connect; |
| 8892 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8893 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8894 | int err; |
| 8895 | |
| 8896 | memset(&connect, 0, sizeof(connect)); |
| 8897 | |
| 8898 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8899 | return -EINVAL; |
| 8900 | |
| 8901 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8902 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8903 | return -EINVAL; |
| 8904 | |
| 8905 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8906 | connect.auth_type = |
| 8907 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8908 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8909 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8910 | return -EINVAL; |
| 8911 | } else |
| 8912 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8913 | |
| 8914 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8915 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 8916 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 8917 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8918 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 8919 | return -EINVAL; |
| 8920 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 8921 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8922 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8923 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8924 | if (err) |
| 8925 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8926 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8927 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8928 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8929 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8930 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8931 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8932 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8933 | connect.bg_scan_period = -1; |
| 8934 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8935 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8936 | connect.bg_scan_period = |
| 8937 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8938 | } |
| 8939 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8940 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8941 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8942 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8943 | connect.bssid_hint = |
| 8944 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8945 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8946 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8947 | |
| 8948 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8949 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8950 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8951 | } |
| 8952 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8953 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8954 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 8955 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 8956 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8957 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 8958 | return -EOPNOTSUPP; |
| 8959 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8960 | if (connect.mfp != NL80211_MFP_REQUIRED && |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 8961 | connect.mfp != NL80211_MFP_NO && |
| 8962 | connect.mfp != NL80211_MFP_OPTIONAL) |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8963 | return -EINVAL; |
| 8964 | } else { |
| 8965 | connect.mfp = NL80211_MFP_NO; |
| 8966 | } |
| 8967 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8968 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8969 | connect.prev_bssid = |
| 8970 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8971 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8972 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8973 | connect.channel = nl80211_get_valid_chan( |
| 8974 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8975 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8976 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8977 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8978 | connect.channel_hint = nl80211_get_valid_chan( |
| 8979 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8980 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8981 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8982 | } |
| 8983 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8984 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8985 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8986 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8987 | if (IS_ERR(connkeys)) |
| 8988 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8989 | } |
| 8990 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8991 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8992 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8993 | |
| 8994 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8995 | memcpy(&connect.ht_capa_mask, |
| 8996 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8997 | sizeof(connect.ht_capa_mask)); |
| 8998 | |
| 8999 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9000 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9001 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9002 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 9003 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9004 | memcpy(&connect.ht_capa, |
| 9005 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9006 | sizeof(connect.ht_capa)); |
| 9007 | } |
| 9008 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9009 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 9010 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 9011 | |
| 9012 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9013 | memcpy(&connect.vht_capa_mask, |
| 9014 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9015 | sizeof(connect.vht_capa_mask)); |
| 9016 | |
| 9017 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 9018 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9019 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9020 | return -EINVAL; |
| 9021 | } |
| 9022 | memcpy(&connect.vht_capa, |
| 9023 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9024 | sizeof(connect.vht_capa)); |
| 9025 | } |
| 9026 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9027 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9028 | if (!((rdev->wiphy.features & |
| 9029 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9030 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9031 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9032 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9033 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9034 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 9035 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9036 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 9037 | } |
| 9038 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9039 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9040 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 9041 | kzfree(connkeys); |
| 9042 | return -EOPNOTSUPP; |
| 9043 | } |
| 9044 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 9045 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 9046 | /* bss selection makes no sense if bssid is set */ |
| 9047 | if (connect.bssid) { |
| 9048 | kzfree(connkeys); |
| 9049 | return -EINVAL; |
| 9050 | } |
| 9051 | |
| 9052 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 9053 | wiphy, &connect.bss_select); |
| 9054 | if (err) { |
| 9055 | kzfree(connkeys); |
| 9056 | return err; |
| 9057 | } |
| 9058 | } |
| 9059 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9060 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 9061 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 9062 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 9063 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 9064 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 9065 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9066 | connect.fils_erp_username = |
| 9067 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9068 | connect.fils_erp_username_len = |
| 9069 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 9070 | connect.fils_erp_realm = |
| 9071 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9072 | connect.fils_erp_realm_len = |
| 9073 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 9074 | connect.fils_erp_next_seq_num = |
| 9075 | nla_get_u16( |
| 9076 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 9077 | connect.fils_erp_rrk = |
| 9078 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9079 | connect.fils_erp_rrk_len = |
| 9080 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 9081 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 9082 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 9083 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 9084 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 9085 | kzfree(connkeys); |
| 9086 | return -EINVAL; |
| 9087 | } |
| 9088 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9089 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9090 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 9091 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 9092 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9093 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 9094 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9095 | |
| 9096 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9097 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9098 | if (connect.bssid) |
| 9099 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9100 | connect.bssid, ETH_ALEN); |
| 9101 | else |
| 9102 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 9103 | 0, ETH_ALEN); |
| 9104 | } |
| 9105 | |
| 9106 | wdev_unlock(dev->ieee80211_ptr); |
| 9107 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9108 | return err; |
| 9109 | } |
| 9110 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 9111 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 9112 | struct genl_info *info) |
| 9113 | { |
| 9114 | struct cfg80211_connect_params connect = {}; |
| 9115 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9116 | struct net_device *dev = info->user_ptr[1]; |
| 9117 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9118 | u32 changed = 0; |
| 9119 | int ret; |
| 9120 | |
| 9121 | if (!rdev->ops->update_connect_params) |
| 9122 | return -EOPNOTSUPP; |
| 9123 | |
| 9124 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9125 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9126 | return -EINVAL; |
| 9127 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9128 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9129 | changed |= UPDATE_ASSOC_IES; |
| 9130 | } |
| 9131 | |
| 9132 | wdev_lock(dev->ieee80211_ptr); |
| 9133 | if (!wdev->current_bss) |
| 9134 | ret = -ENOLINK; |
| 9135 | else |
| 9136 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9137 | wdev_unlock(dev->ieee80211_ptr); |
| 9138 | |
| 9139 | return ret; |
| 9140 | } |
| 9141 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9142 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9143 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9145 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9146 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9147 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9148 | |
| 9149 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9150 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9151 | else |
| 9152 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9153 | |
| 9154 | if (reason == 0) |
| 9155 | return -EINVAL; |
| 9156 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9158 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9159 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9160 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9161 | wdev_lock(dev->ieee80211_ptr); |
| 9162 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9163 | wdev_unlock(dev->ieee80211_ptr); |
| 9164 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9165 | } |
| 9166 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9167 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9168 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9170 | struct net *net; |
| 9171 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9172 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9173 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9174 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9175 | |
| 9176 | net = get_net_ns_by_pid(pid); |
| 9177 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9178 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9179 | |
| 9180 | net = get_net_ns_by_fd(fd); |
| 9181 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9182 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9183 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9184 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9185 | if (IS_ERR(net)) |
| 9186 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9187 | |
| 9188 | err = 0; |
| 9189 | |
| 9190 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9191 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9192 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9193 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9194 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9195 | return err; |
| 9196 | } |
| 9197 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9198 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9199 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9201 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9202 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9203 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9204 | struct cfg80211_pmksa pmksa; |
| 9205 | |
| 9206 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9207 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9208 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9209 | return -EINVAL; |
| 9210 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9211 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9212 | |
| 9213 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9214 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9215 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9216 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9217 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9218 | info->attrs[NL80211_ATTR_PMK])) { |
| 9219 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9220 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9221 | pmksa.cache_id = |
| 9222 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9223 | } else { |
| 9224 | return -EINVAL; |
| 9225 | } |
| 9226 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9227 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9228 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9229 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9230 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9231 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9232 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9233 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9234 | |
| 9235 | switch (info->genlhdr->cmd) { |
| 9236 | case NL80211_CMD_SET_PMKSA: |
| 9237 | rdev_ops = rdev->ops->set_pmksa; |
| 9238 | break; |
| 9239 | case NL80211_CMD_DEL_PMKSA: |
| 9240 | rdev_ops = rdev->ops->del_pmksa; |
| 9241 | break; |
| 9242 | default: |
| 9243 | WARN_ON(1); |
| 9244 | break; |
| 9245 | } |
| 9246 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9247 | if (!rdev_ops) |
| 9248 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9250 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9251 | } |
| 9252 | |
| 9253 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9254 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9256 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9257 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9258 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9259 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9260 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9261 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9262 | if (!rdev->ops->flush_pmksa) |
| 9263 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9264 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9265 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9266 | } |
| 9267 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9268 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9269 | { |
| 9270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9271 | struct net_device *dev = info->user_ptr[1]; |
| 9272 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9273 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9274 | u16 status_code; |
| 9275 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9276 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9277 | |
| 9278 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9279 | !rdev->ops->tdls_mgmt) |
| 9280 | return -EOPNOTSUPP; |
| 9281 | |
| 9282 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9283 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9284 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9285 | !info->attrs[NL80211_ATTR_IE] || |
| 9286 | !info->attrs[NL80211_ATTR_MAC]) |
| 9287 | return -EINVAL; |
| 9288 | |
| 9289 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9290 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9291 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9292 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9293 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9294 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9295 | peer_capability = |
| 9296 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9297 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9298 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9299 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9300 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9301 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9302 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9303 | } |
| 9304 | |
| 9305 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9306 | { |
| 9307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9308 | struct net_device *dev = info->user_ptr[1]; |
| 9309 | enum nl80211_tdls_operation operation; |
| 9310 | u8 *peer; |
| 9311 | |
| 9312 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9313 | !rdev->ops->tdls_oper) |
| 9314 | return -EOPNOTSUPP; |
| 9315 | |
| 9316 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9317 | !info->attrs[NL80211_ATTR_MAC]) |
| 9318 | return -EINVAL; |
| 9319 | |
| 9320 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9321 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9322 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9323 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9324 | } |
| 9325 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9326 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9327 | struct genl_info *info) |
| 9328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9330 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9331 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9332 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9333 | struct sk_buff *msg; |
| 9334 | void *hdr; |
| 9335 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9336 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9337 | int err; |
| 9338 | |
| 9339 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9340 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9341 | return -EINVAL; |
| 9342 | |
| 9343 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9344 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9345 | if (!rdev->ops->remain_on_channel || |
| 9346 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9347 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9348 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9349 | /* |
| 9350 | * We should be on that channel for at least a minimum amount of |
| 9351 | * time (10ms) but no longer than the driver supports. |
| 9352 | */ |
| 9353 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9354 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9355 | return -EINVAL; |
| 9356 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9357 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9358 | if (err) |
| 9359 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9360 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9361 | wdev_lock(wdev); |
| 9362 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 9363 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 9364 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 9365 | &chandef); |
| 9366 | if (compat_chandef != &chandef) { |
| 9367 | wdev_unlock(wdev); |
| 9368 | return -EBUSY; |
| 9369 | } |
| 9370 | } |
| 9371 | wdev_unlock(wdev); |
| 9372 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9373 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9374 | if (!msg) |
| 9375 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9376 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9377 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9378 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9379 | if (!hdr) { |
| 9380 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9381 | goto free_msg; |
| 9382 | } |
| 9383 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9384 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9385 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9386 | |
| 9387 | if (err) |
| 9388 | goto free_msg; |
| 9389 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9390 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9391 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9392 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9393 | |
| 9394 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9395 | |
| 9396 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9397 | |
| 9398 | nla_put_failure: |
| 9399 | err = -ENOBUFS; |
| 9400 | free_msg: |
| 9401 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9402 | return err; |
| 9403 | } |
| 9404 | |
| 9405 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9406 | struct genl_info *info) |
| 9407 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9408 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9409 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9410 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9411 | |
| 9412 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9413 | return -EINVAL; |
| 9414 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9415 | if (!rdev->ops->cancel_remain_on_channel) |
| 9416 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9417 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9418 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9419 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9420 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9421 | } |
| 9422 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9423 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9424 | struct genl_info *info) |
| 9425 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9426 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9428 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9429 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9430 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9431 | if (!rdev->ops->set_bitrate_mask) |
| 9432 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9433 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9434 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9435 | if (err) |
| 9436 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9437 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9438 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9439 | } |
| 9440 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9441 | 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] | 9442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9444 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9445 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9446 | |
| 9447 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9448 | return -EINVAL; |
| 9449 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9450 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9451 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9452 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9453 | switch (wdev->iftype) { |
| 9454 | case NL80211_IFTYPE_STATION: |
| 9455 | case NL80211_IFTYPE_ADHOC: |
| 9456 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9457 | case NL80211_IFTYPE_AP: |
| 9458 | case NL80211_IFTYPE_AP_VLAN: |
| 9459 | case NL80211_IFTYPE_MESH_POINT: |
| 9460 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9461 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9462 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9463 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9464 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9465 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9466 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9467 | |
| 9468 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9469 | if (!rdev->ops->mgmt_tx) |
| 9470 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9471 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9472 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9473 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9474 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9475 | } |
| 9476 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9477 | 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] | 9478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9480 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9481 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9482 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9483 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9484 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9485 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9486 | struct cfg80211_mgmt_tx_params params = { |
| 9487 | .dont_wait_for_ack = |
| 9488 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9489 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9490 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9491 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9492 | return -EINVAL; |
| 9493 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9494 | if (!rdev->ops->mgmt_tx) |
| 9495 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9496 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9497 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9498 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9499 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9500 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9501 | case NL80211_IFTYPE_STATION: |
| 9502 | case NL80211_IFTYPE_ADHOC: |
| 9503 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9504 | case NL80211_IFTYPE_AP: |
| 9505 | case NL80211_IFTYPE_AP_VLAN: |
| 9506 | case NL80211_IFTYPE_MESH_POINT: |
| 9507 | case NL80211_IFTYPE_P2P_GO: |
| 9508 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9509 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9510 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9511 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9512 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9513 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9514 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9515 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9516 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9517 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9518 | |
| 9519 | /* |
| 9520 | * We should wait on the channel for at least a minimum amount |
| 9521 | * of time (10ms) but no longer than the driver supports. |
| 9522 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9523 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9524 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9525 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9526 | } |
| 9527 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9528 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9529 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9530 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9531 | return -EINVAL; |
| 9532 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9533 | 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] | 9534 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9535 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9536 | * the driver. The latter will use the current one |
| 9537 | */ |
| 9538 | chandef.chan = NULL; |
| 9539 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9540 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9541 | if (err) |
| 9542 | return err; |
| 9543 | } |
| 9544 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9545 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9546 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9547 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9548 | wdev_lock(wdev); |
| 9549 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 9550 | wdev_unlock(wdev); |
| 9551 | return -EBUSY; |
| 9552 | } |
| 9553 | wdev_unlock(wdev); |
| 9554 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9555 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9556 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9557 | |
| 9558 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9559 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9560 | int i; |
| 9561 | |
| 9562 | if (len % sizeof(u16)) |
| 9563 | return -EINVAL; |
| 9564 | |
| 9565 | params.n_csa_offsets = len / sizeof(u16); |
| 9566 | params.csa_offsets = |
| 9567 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9568 | |
| 9569 | /* check that all the offsets fit the frame */ |
| 9570 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9571 | if (params.csa_offsets[i] >= params.len) |
| 9572 | return -EINVAL; |
| 9573 | } |
| 9574 | } |
| 9575 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9576 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9577 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9578 | if (!msg) |
| 9579 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9580 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9581 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9582 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9583 | if (!hdr) { |
| 9584 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9585 | goto free_msg; |
| 9586 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9587 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9588 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9589 | params.chan = chandef.chan; |
| 9590 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9591 | if (err) |
| 9592 | goto free_msg; |
| 9593 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9594 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9595 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9596 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9597 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9598 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9599 | genlmsg_end(msg, hdr); |
| 9600 | return genlmsg_reply(msg, info); |
| 9601 | } |
| 9602 | |
| 9603 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9604 | |
| 9605 | nla_put_failure: |
| 9606 | err = -ENOBUFS; |
| 9607 | free_msg: |
| 9608 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9609 | return err; |
| 9610 | } |
| 9611 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9612 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9613 | { |
| 9614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9615 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9616 | u64 cookie; |
| 9617 | |
| 9618 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9619 | return -EINVAL; |
| 9620 | |
| 9621 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9622 | return -EOPNOTSUPP; |
| 9623 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9624 | switch (wdev->iftype) { |
| 9625 | case NL80211_IFTYPE_STATION: |
| 9626 | case NL80211_IFTYPE_ADHOC: |
| 9627 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9628 | case NL80211_IFTYPE_AP: |
| 9629 | case NL80211_IFTYPE_AP_VLAN: |
| 9630 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9631 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9632 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9633 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9634 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9635 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9636 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9637 | |
| 9638 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9639 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9640 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9641 | } |
| 9642 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9643 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9644 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9645 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 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 | u8 ps_state; |
| 9649 | bool state; |
| 9650 | int err; |
| 9651 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9652 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9653 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9654 | |
| 9655 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9656 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9657 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9658 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9659 | |
| 9660 | wdev = dev->ieee80211_ptr; |
| 9661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9662 | if (!rdev->ops->set_power_mgmt) |
| 9663 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9664 | |
| 9665 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9666 | |
| 9667 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9668 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9670 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9671 | if (!err) |
| 9672 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9673 | return err; |
| 9674 | } |
| 9675 | |
| 9676 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9677 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9679 | enum nl80211_ps_state ps_state; |
| 9680 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9681 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9682 | struct sk_buff *msg; |
| 9683 | void *hdr; |
| 9684 | int err; |
| 9685 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9686 | wdev = dev->ieee80211_ptr; |
| 9687 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9688 | if (!rdev->ops->set_power_mgmt) |
| 9689 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9690 | |
| 9691 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9692 | if (!msg) |
| 9693 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9694 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9695 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9696 | NL80211_CMD_GET_POWER_SAVE); |
| 9697 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9698 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9699 | goto free_msg; |
| 9700 | } |
| 9701 | |
| 9702 | if (wdev->ps) |
| 9703 | ps_state = NL80211_PS_ENABLED; |
| 9704 | else |
| 9705 | ps_state = NL80211_PS_DISABLED; |
| 9706 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9707 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9708 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9709 | |
| 9710 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9711 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9712 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9713 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9714 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9715 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9716 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9717 | return err; |
| 9718 | } |
| 9719 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9720 | static const struct nla_policy |
| 9721 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9722 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9723 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9724 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9725 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9726 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9727 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 9728 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9729 | }; |
| 9730 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9731 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9732 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9733 | { |
| 9734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9735 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9736 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9737 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9738 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9739 | return -EINVAL; |
| 9740 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9741 | if (!rdev->ops->set_cqm_txe_config) |
| 9742 | return -EOPNOTSUPP; |
| 9743 | |
| 9744 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9745 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9746 | return -EOPNOTSUPP; |
| 9747 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9748 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9749 | } |
| 9750 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9751 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 9752 | struct net_device *dev) |
| 9753 | { |
| 9754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9755 | s32 last, low, high; |
| 9756 | u32 hyst; |
| 9757 | int i, n; |
| 9758 | int err; |
| 9759 | |
| 9760 | /* RSSI reporting disabled? */ |
| 9761 | if (!wdev->cqm_config) |
| 9762 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 9763 | |
| 9764 | /* |
| 9765 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 9766 | * event has been received yet, we should receive an event after a |
| 9767 | * connection is established and enough beacons received to calculate |
| 9768 | * the average. |
| 9769 | */ |
| 9770 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 9771 | rdev->ops->get_station) { |
| 9772 | struct station_info sinfo; |
| 9773 | u8 *mac_addr; |
| 9774 | |
| 9775 | mac_addr = wdev->current_bss->pub.bssid; |
| 9776 | |
| 9777 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 9778 | if (err) |
| 9779 | return err; |
| 9780 | |
| 9781 | if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
| 9782 | wdev->cqm_config->last_rssi_event_value = |
| 9783 | (s8) sinfo.rx_beacon_signal_avg; |
| 9784 | } |
| 9785 | |
| 9786 | last = wdev->cqm_config->last_rssi_event_value; |
| 9787 | hyst = wdev->cqm_config->rssi_hyst; |
| 9788 | n = wdev->cqm_config->n_rssi_thresholds; |
| 9789 | |
| 9790 | for (i = 0; i < n; i++) |
| 9791 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 9792 | break; |
| 9793 | |
| 9794 | low = i > 0 ? |
| 9795 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; |
| 9796 | high = i < n ? |
| 9797 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; |
| 9798 | |
| 9799 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 9800 | } |
| 9801 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9802 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9803 | const s32 *thresholds, int n_thresholds, |
| 9804 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9805 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9807 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9808 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9809 | int i, err; |
| 9810 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9811 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9812 | /* Check all values negative and sorted */ |
| 9813 | for (i = 0; i < n_thresholds; i++) { |
| 9814 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 9815 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9816 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9817 | prev = thresholds[i]; |
| 9818 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9819 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9820 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9821 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9822 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9823 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9824 | wdev_lock(wdev); |
| 9825 | cfg80211_cqm_config_free(wdev); |
| 9826 | wdev_unlock(wdev); |
| 9827 | |
| 9828 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 9829 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 9830 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 9831 | |
| 9832 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 9833 | thresholds[0], hysteresis); |
| 9834 | } |
| 9835 | |
| 9836 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9837 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 9838 | return -EOPNOTSUPP; |
| 9839 | |
| 9840 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 9841 | n_thresholds = 0; |
| 9842 | |
| 9843 | wdev_lock(wdev); |
| 9844 | if (n_thresholds) { |
| 9845 | struct cfg80211_cqm_config *cqm_config; |
| 9846 | |
| 9847 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 9848 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 9849 | if (!cqm_config) { |
| 9850 | err = -ENOMEM; |
| 9851 | goto unlock; |
| 9852 | } |
| 9853 | |
| 9854 | cqm_config->rssi_hyst = hysteresis; |
| 9855 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 9856 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 9857 | n_thresholds * sizeof(s32)); |
| 9858 | |
| 9859 | wdev->cqm_config = cqm_config; |
| 9860 | } |
| 9861 | |
| 9862 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 9863 | |
| 9864 | unlock: |
| 9865 | wdev_unlock(wdev); |
| 9866 | |
| 9867 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9868 | } |
| 9869 | |
| 9870 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9871 | { |
| 9872 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9873 | struct nlattr *cqm; |
| 9874 | int err; |
| 9875 | |
| 9876 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9877 | if (!cqm) |
| 9878 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9879 | |
| 9880 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 9881 | nl80211_attr_cqm_policy, info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9882 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9883 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9884 | |
| 9885 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9886 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9887 | const s32 *thresholds = |
| 9888 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9889 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9890 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9891 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9892 | if (len % 4) |
| 9893 | return -EINVAL; |
| 9894 | |
| 9895 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 9896 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9900 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9901 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9902 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9903 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9904 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9905 | |
| 9906 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9907 | } |
| 9908 | |
| 9909 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9910 | } |
| 9911 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9912 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9913 | { |
| 9914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9915 | struct net_device *dev = info->user_ptr[1]; |
| 9916 | struct ocb_setup setup = {}; |
| 9917 | int err; |
| 9918 | |
| 9919 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9920 | if (err) |
| 9921 | return err; |
| 9922 | |
| 9923 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9924 | } |
| 9925 | |
| 9926 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9927 | { |
| 9928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9929 | struct net_device *dev = info->user_ptr[1]; |
| 9930 | |
| 9931 | return cfg80211_leave_ocb(rdev, dev); |
| 9932 | } |
| 9933 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9934 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9935 | { |
| 9936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9937 | struct net_device *dev = info->user_ptr[1]; |
| 9938 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9939 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9940 | int err; |
| 9941 | |
| 9942 | /* start with default */ |
| 9943 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9944 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9945 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9946 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9947 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9948 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9949 | if (err) |
| 9950 | return err; |
| 9951 | } |
| 9952 | |
| 9953 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9954 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9955 | return -EINVAL; |
| 9956 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9957 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9958 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9959 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9960 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9961 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9962 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9963 | return -EINVAL; |
| 9964 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9965 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9966 | setup.beacon_interval = |
| 9967 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9968 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9969 | err = cfg80211_validate_beacon_int(rdev, |
| 9970 | NL80211_IFTYPE_MESH_POINT, |
| 9971 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9972 | if (err) |
| 9973 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9974 | } |
| 9975 | |
| 9976 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9977 | setup.dtim_period = |
| 9978 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9979 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9980 | return -EINVAL; |
| 9981 | } |
| 9982 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9983 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9984 | /* parse additional setup parameters if given */ |
| 9985 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9986 | if (err) |
| 9987 | return err; |
| 9988 | } |
| 9989 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9990 | if (setup.user_mpm) |
| 9991 | cfg.auto_open_plinks = false; |
| 9992 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9993 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9994 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9995 | if (err) |
| 9996 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9997 | } else { |
| 9998 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9999 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 10000 | } |
| 10001 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 10002 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10003 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10004 | int n_rates = |
| 10005 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10006 | struct ieee80211_supported_band *sband; |
| 10007 | |
| 10008 | if (!setup.chandef.chan) |
| 10009 | return -EINVAL; |
| 10010 | |
| 10011 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 10012 | |
| 10013 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10014 | &setup.basic_rates); |
| 10015 | if (err) |
| 10016 | return err; |
| 10017 | } |
| 10018 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 10019 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 10020 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 10021 | if (err) |
| 10022 | return err; |
| 10023 | |
| 10024 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 10025 | &setup.beacon_rate); |
| 10026 | if (err) |
| 10027 | return err; |
| 10028 | } |
| 10029 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 10030 | setup.userspace_handles_dfs = |
| 10031 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10032 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 10033 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10034 | } |
| 10035 | |
| 10036 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 10037 | { |
| 10038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10039 | struct net_device *dev = info->user_ptr[1]; |
| 10040 | |
| 10041 | return cfg80211_leave_mesh(rdev, dev); |
| 10042 | } |
| 10043 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10044 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10045 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 10046 | struct cfg80211_registered_device *rdev) |
| 10047 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10048 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10049 | struct nlattr *nl_pats, *nl_pat; |
| 10050 | int i, pat_len; |
| 10051 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10052 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10053 | return 0; |
| 10054 | |
| 10055 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 10056 | if (!nl_pats) |
| 10057 | return -ENOBUFS; |
| 10058 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10059 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10060 | nl_pat = nla_nest_start(msg, i + 1); |
| 10061 | if (!nl_pat) |
| 10062 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10063 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10064 | 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] | 10065 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10066 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10067 | wowlan->patterns[i].pattern) || |
| 10068 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10069 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10070 | return -ENOBUFS; |
| 10071 | nla_nest_end(msg, nl_pat); |
| 10072 | } |
| 10073 | nla_nest_end(msg, nl_pats); |
| 10074 | |
| 10075 | return 0; |
| 10076 | } |
| 10077 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10078 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 10079 | struct cfg80211_wowlan_tcp *tcp) |
| 10080 | { |
| 10081 | struct nlattr *nl_tcp; |
| 10082 | |
| 10083 | if (!tcp) |
| 10084 | return 0; |
| 10085 | |
| 10086 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 10087 | if (!nl_tcp) |
| 10088 | return -ENOBUFS; |
| 10089 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 10090 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 10091 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10092 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 10093 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 10094 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 10095 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 10096 | tcp->payload_len, tcp->payload) || |
| 10097 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 10098 | tcp->data_interval) || |
| 10099 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 10100 | tcp->wake_len, tcp->wake_data) || |
| 10101 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 10102 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 10103 | return -ENOBUFS; |
| 10104 | |
| 10105 | if (tcp->payload_seq.len && |
| 10106 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 10107 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 10108 | return -ENOBUFS; |
| 10109 | |
| 10110 | if (tcp->payload_tok.len && |
| 10111 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 10112 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 10113 | &tcp->payload_tok)) |
| 10114 | return -ENOBUFS; |
| 10115 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 10116 | nla_nest_end(msg, nl_tcp); |
| 10117 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10118 | return 0; |
| 10119 | } |
| 10120 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10121 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10122 | struct cfg80211_sched_scan_request *req) |
| 10123 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10124 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10125 | int i; |
| 10126 | |
| 10127 | if (!req) |
| 10128 | return 0; |
| 10129 | |
| 10130 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10131 | if (!nd) |
| 10132 | return -ENOBUFS; |
| 10133 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10134 | if (req->n_scan_plans == 1 && |
| 10135 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10136 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10137 | return -ENOBUFS; |
| 10138 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10139 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10140 | return -ENOBUFS; |
| 10141 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10142 | if (req->relative_rssi_set) { |
| 10143 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10144 | |
| 10145 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10146 | req->relative_rssi)) |
| 10147 | return -ENOBUFS; |
| 10148 | |
| 10149 | rssi_adjust.band = req->rssi_adjust.band; |
| 10150 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10151 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10152 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10153 | return -ENOBUFS; |
| 10154 | } |
| 10155 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10156 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10157 | if (!freqs) |
| 10158 | return -ENOBUFS; |
| 10159 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10160 | for (i = 0; i < req->n_channels; i++) { |
| 10161 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10162 | return -ENOBUFS; |
| 10163 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10164 | |
| 10165 | nla_nest_end(msg, freqs); |
| 10166 | |
| 10167 | if (req->n_match_sets) { |
| 10168 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10169 | if (!matches) |
| 10170 | return -ENOBUFS; |
| 10171 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10172 | for (i = 0; i < req->n_match_sets; i++) { |
| 10173 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10174 | if (!match) |
| 10175 | return -ENOBUFS; |
| 10176 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10177 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10178 | req->match_sets[i].ssid.ssid_len, |
| 10179 | req->match_sets[i].ssid.ssid)) |
| 10180 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10181 | nla_nest_end(msg, match); |
| 10182 | } |
| 10183 | nla_nest_end(msg, matches); |
| 10184 | } |
| 10185 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10186 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10187 | if (!scan_plans) |
| 10188 | return -ENOBUFS; |
| 10189 | |
| 10190 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10191 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10192 | if (!scan_plan) |
| 10193 | return -ENOBUFS; |
| 10194 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10195 | if (!scan_plan || |
| 10196 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 10197 | req->scan_plans[i].interval) || |
| 10198 | (req->scan_plans[i].iterations && |
| 10199 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10200 | req->scan_plans[i].iterations))) |
| 10201 | return -ENOBUFS; |
| 10202 | nla_nest_end(msg, scan_plan); |
| 10203 | } |
| 10204 | nla_nest_end(msg, scan_plans); |
| 10205 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10206 | nla_nest_end(msg, nd); |
| 10207 | |
| 10208 | return 0; |
| 10209 | } |
| 10210 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10211 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10212 | { |
| 10213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10214 | struct sk_buff *msg; |
| 10215 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10216 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10217 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10218 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10219 | return -EOPNOTSUPP; |
| 10220 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10221 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10222 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10223 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10224 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10225 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10226 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10227 | } |
| 10228 | |
| 10229 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10230 | if (!msg) |
| 10231 | return -ENOMEM; |
| 10232 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10233 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10234 | NL80211_CMD_GET_WOWLAN); |
| 10235 | if (!hdr) |
| 10236 | goto nla_put_failure; |
| 10237 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10238 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10239 | struct nlattr *nl_wowlan; |
| 10240 | |
| 10241 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10242 | if (!nl_wowlan) |
| 10243 | goto nla_put_failure; |
| 10244 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10245 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10246 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10247 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10248 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10249 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10250 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10251 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10252 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10253 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10254 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10255 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10256 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10257 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10258 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10259 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10260 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10261 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10262 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10263 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10264 | if (nl80211_send_wowlan_tcp(msg, |
| 10265 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10266 | goto nla_put_failure; |
| 10267 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10268 | if (nl80211_send_wowlan_nd( |
| 10269 | msg, |
| 10270 | rdev->wiphy.wowlan_config->nd_config)) |
| 10271 | goto nla_put_failure; |
| 10272 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10273 | nla_nest_end(msg, nl_wowlan); |
| 10274 | } |
| 10275 | |
| 10276 | genlmsg_end(msg, hdr); |
| 10277 | return genlmsg_reply(msg, info); |
| 10278 | |
| 10279 | nla_put_failure: |
| 10280 | nlmsg_free(msg); |
| 10281 | return -ENOBUFS; |
| 10282 | } |
| 10283 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10284 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10285 | struct nlattr *attr, |
| 10286 | struct cfg80211_wowlan *trig) |
| 10287 | { |
| 10288 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10289 | struct cfg80211_wowlan_tcp *cfg; |
| 10290 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10291 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10292 | u32 size; |
| 10293 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10294 | int err, port; |
| 10295 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10296 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10297 | return -EINVAL; |
| 10298 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10299 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10300 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10301 | if (err) |
| 10302 | return err; |
| 10303 | |
| 10304 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10305 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10306 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10307 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10308 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10309 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10310 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10311 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10312 | return -EINVAL; |
| 10313 | |
| 10314 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10315 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10316 | return -EINVAL; |
| 10317 | |
| 10318 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10319 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10320 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10321 | return -EINVAL; |
| 10322 | |
| 10323 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10324 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10325 | return -EINVAL; |
| 10326 | |
| 10327 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10328 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10329 | return -EINVAL; |
| 10330 | |
| 10331 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10332 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10333 | |
| 10334 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10335 | tokens_size = tokln - sizeof(*tok); |
| 10336 | |
| 10337 | if (!tok->len || tokens_size % tok->len) |
| 10338 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10339 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10340 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10341 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10342 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10343 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10344 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10345 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10346 | return -EINVAL; |
| 10347 | if (tok->offset + tok->len > data_size) |
| 10348 | return -EINVAL; |
| 10349 | } |
| 10350 | |
| 10351 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10352 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10353 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10354 | return -EINVAL; |
| 10355 | if (seq->len == 0 || seq->len > 4) |
| 10356 | return -EINVAL; |
| 10357 | if (seq->len + seq->offset > data_size) |
| 10358 | return -EINVAL; |
| 10359 | } |
| 10360 | |
| 10361 | size = sizeof(*cfg); |
| 10362 | size += data_size; |
| 10363 | size += wake_size + wake_mask_size; |
| 10364 | size += tokens_size; |
| 10365 | |
| 10366 | cfg = kzalloc(size, GFP_KERNEL); |
| 10367 | if (!cfg) |
| 10368 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10369 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10370 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10371 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10372 | ETH_ALEN); |
| 10373 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10374 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10375 | else |
| 10376 | port = 0; |
| 10377 | #ifdef CONFIG_INET |
| 10378 | /* allocate a socket and port for it and use it */ |
| 10379 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10380 | IPPROTO_TCP, &cfg->sock, 1); |
| 10381 | if (err) { |
| 10382 | kfree(cfg); |
| 10383 | return err; |
| 10384 | } |
| 10385 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10386 | sock_release(cfg->sock); |
| 10387 | kfree(cfg); |
| 10388 | return -EADDRINUSE; |
| 10389 | } |
| 10390 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10391 | #else |
| 10392 | if (!port) { |
| 10393 | kfree(cfg); |
| 10394 | return -EINVAL; |
| 10395 | } |
| 10396 | cfg->src_port = port; |
| 10397 | #endif |
| 10398 | |
| 10399 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10400 | cfg->payload_len = data_size; |
| 10401 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10402 | memcpy((void *)cfg->payload, |
| 10403 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10404 | data_size); |
| 10405 | if (seq) |
| 10406 | cfg->payload_seq = *seq; |
| 10407 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10408 | cfg->wake_len = wake_size; |
| 10409 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10410 | memcpy((void *)cfg->wake_data, |
| 10411 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10412 | wake_size); |
| 10413 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10414 | data_size + wake_size; |
| 10415 | memcpy((void *)cfg->wake_mask, |
| 10416 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10417 | wake_mask_size); |
| 10418 | if (tok) { |
| 10419 | cfg->tokens_size = tokens_size; |
| 10420 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10421 | } |
| 10422 | |
| 10423 | trig->tcp = cfg; |
| 10424 | |
| 10425 | return 0; |
| 10426 | } |
| 10427 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10428 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10429 | const struct wiphy_wowlan_support *wowlan, |
| 10430 | struct nlattr *attr, |
| 10431 | struct cfg80211_wowlan *trig) |
| 10432 | { |
| 10433 | struct nlattr **tb; |
| 10434 | int err; |
| 10435 | |
| 10436 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10437 | if (!tb) |
| 10438 | return -ENOMEM; |
| 10439 | |
| 10440 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10441 | err = -EOPNOTSUPP; |
| 10442 | goto out; |
| 10443 | } |
| 10444 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10445 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
| 10446 | NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10447 | if (err) |
| 10448 | goto out; |
| 10449 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 10450 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 10451 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10452 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10453 | if (err) |
| 10454 | trig->nd_config = NULL; |
| 10455 | |
| 10456 | out: |
| 10457 | kfree(tb); |
| 10458 | return err; |
| 10459 | } |
| 10460 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10461 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10462 | { |
| 10463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10464 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10465 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10466 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10467 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10468 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10469 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10470 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10471 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10472 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10473 | return -EOPNOTSUPP; |
| 10474 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10475 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10476 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10477 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10478 | goto set_wakeup; |
| 10479 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10480 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10481 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10482 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10483 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10484 | if (err) |
| 10485 | return err; |
| 10486 | |
| 10487 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10488 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10489 | return -EINVAL; |
| 10490 | new_triggers.any = true; |
| 10491 | } |
| 10492 | |
| 10493 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10494 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10495 | return -EINVAL; |
| 10496 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10497 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10498 | } |
| 10499 | |
| 10500 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10501 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10502 | return -EINVAL; |
| 10503 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10504 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10505 | } |
| 10506 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10507 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10508 | return -EINVAL; |
| 10509 | |
| 10510 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10511 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10512 | return -EINVAL; |
| 10513 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10514 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10515 | } |
| 10516 | |
| 10517 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10518 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10519 | return -EINVAL; |
| 10520 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10521 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10522 | } |
| 10523 | |
| 10524 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10525 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10526 | return -EINVAL; |
| 10527 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10528 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10529 | } |
| 10530 | |
| 10531 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10532 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10533 | return -EINVAL; |
| 10534 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10535 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10536 | } |
| 10537 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10538 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10539 | struct nlattr *pat; |
| 10540 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10541 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10542 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10543 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10544 | regular = true; |
| 10545 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10546 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10547 | rem) |
| 10548 | n_patterns++; |
| 10549 | if (n_patterns > wowlan->n_patterns) |
| 10550 | return -EINVAL; |
| 10551 | |
| 10552 | new_triggers.patterns = kcalloc(n_patterns, |
| 10553 | sizeof(new_triggers.patterns[0]), |
| 10554 | GFP_KERNEL); |
| 10555 | if (!new_triggers.patterns) |
| 10556 | return -ENOMEM; |
| 10557 | |
| 10558 | new_triggers.n_patterns = n_patterns; |
| 10559 | i = 0; |
| 10560 | |
| 10561 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10562 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10563 | u8 *mask_pat; |
| 10564 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10565 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10566 | NULL, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10567 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10568 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10569 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10570 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10571 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10572 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10573 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10574 | goto error; |
| 10575 | if (pat_len > wowlan->pattern_max_len || |
| 10576 | pat_len < wowlan->pattern_min_len) |
| 10577 | goto error; |
| 10578 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10579 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10580 | pkt_offset = 0; |
| 10581 | else |
| 10582 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10583 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10584 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10585 | goto error; |
| 10586 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10587 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10588 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10589 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10590 | err = -ENOMEM; |
| 10591 | goto error; |
| 10592 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10593 | new_triggers.patterns[i].mask = mask_pat; |
| 10594 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10595 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10596 | mask_pat += mask_len; |
| 10597 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10598 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10599 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10600 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10601 | pat_len); |
| 10602 | i++; |
| 10603 | } |
| 10604 | } |
| 10605 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10606 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10607 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10608 | err = nl80211_parse_wowlan_tcp( |
| 10609 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10610 | &new_triggers); |
| 10611 | if (err) |
| 10612 | goto error; |
| 10613 | } |
| 10614 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10615 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10616 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10617 | err = nl80211_parse_wowlan_nd( |
| 10618 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10619 | &new_triggers); |
| 10620 | if (err) |
| 10621 | goto error; |
| 10622 | } |
| 10623 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10624 | /* The 'any' trigger means the device continues operating more or less |
| 10625 | * as in its normal operation mode and wakes up the host on most of the |
| 10626 | * normal interrupts (like packet RX, ...) |
| 10627 | * It therefore makes little sense to combine with the more constrained |
| 10628 | * wakeup trigger modes. |
| 10629 | */ |
| 10630 | if (new_triggers.any && regular) { |
| 10631 | err = -EINVAL; |
| 10632 | goto error; |
| 10633 | } |
| 10634 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10635 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10636 | if (!ntrig) { |
| 10637 | err = -ENOMEM; |
| 10638 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10639 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10640 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10641 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10642 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10643 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10644 | if (rdev->ops->set_wakeup && |
| 10645 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10646 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10647 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10648 | return 0; |
| 10649 | error: |
| 10650 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10651 | kfree(new_triggers.patterns[i].mask); |
| 10652 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10653 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10654 | sock_release(new_triggers.tcp->sock); |
| 10655 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10656 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10657 | return err; |
| 10658 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10659 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10660 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10661 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10662 | struct cfg80211_registered_device *rdev) |
| 10663 | { |
| 10664 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10665 | int i, j, pat_len; |
| 10666 | struct cfg80211_coalesce_rules *rule; |
| 10667 | |
| 10668 | if (!rdev->coalesce->n_rules) |
| 10669 | return 0; |
| 10670 | |
| 10671 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10672 | if (!nl_rules) |
| 10673 | return -ENOBUFS; |
| 10674 | |
| 10675 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10676 | nl_rule = nla_nest_start(msg, i + 1); |
| 10677 | if (!nl_rule) |
| 10678 | return -ENOBUFS; |
| 10679 | |
| 10680 | rule = &rdev->coalesce->rules[i]; |
| 10681 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10682 | rule->delay)) |
| 10683 | return -ENOBUFS; |
| 10684 | |
| 10685 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10686 | rule->condition)) |
| 10687 | return -ENOBUFS; |
| 10688 | |
| 10689 | nl_pats = nla_nest_start(msg, |
| 10690 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10691 | if (!nl_pats) |
| 10692 | return -ENOBUFS; |
| 10693 | |
| 10694 | for (j = 0; j < rule->n_patterns; j++) { |
| 10695 | nl_pat = nla_nest_start(msg, j + 1); |
| 10696 | if (!nl_pat) |
| 10697 | return -ENOBUFS; |
| 10698 | pat_len = rule->patterns[j].pattern_len; |
| 10699 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10700 | DIV_ROUND_UP(pat_len, 8), |
| 10701 | rule->patterns[j].mask) || |
| 10702 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10703 | rule->patterns[j].pattern) || |
| 10704 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10705 | rule->patterns[j].pkt_offset)) |
| 10706 | return -ENOBUFS; |
| 10707 | nla_nest_end(msg, nl_pat); |
| 10708 | } |
| 10709 | nla_nest_end(msg, nl_pats); |
| 10710 | nla_nest_end(msg, nl_rule); |
| 10711 | } |
| 10712 | nla_nest_end(msg, nl_rules); |
| 10713 | |
| 10714 | return 0; |
| 10715 | } |
| 10716 | |
| 10717 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10718 | { |
| 10719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10720 | struct sk_buff *msg; |
| 10721 | void *hdr; |
| 10722 | |
| 10723 | if (!rdev->wiphy.coalesce) |
| 10724 | return -EOPNOTSUPP; |
| 10725 | |
| 10726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10727 | if (!msg) |
| 10728 | return -ENOMEM; |
| 10729 | |
| 10730 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10731 | NL80211_CMD_GET_COALESCE); |
| 10732 | if (!hdr) |
| 10733 | goto nla_put_failure; |
| 10734 | |
| 10735 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10736 | goto nla_put_failure; |
| 10737 | |
| 10738 | genlmsg_end(msg, hdr); |
| 10739 | return genlmsg_reply(msg, info); |
| 10740 | |
| 10741 | nla_put_failure: |
| 10742 | nlmsg_free(msg); |
| 10743 | return -ENOBUFS; |
| 10744 | } |
| 10745 | |
| 10746 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10747 | { |
| 10748 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10749 | int i, j; |
| 10750 | struct cfg80211_coalesce_rules *rule; |
| 10751 | |
| 10752 | if (!coalesce) |
| 10753 | return; |
| 10754 | |
| 10755 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10756 | rule = &coalesce->rules[i]; |
| 10757 | for (j = 0; j < rule->n_patterns; j++) |
| 10758 | kfree(rule->patterns[j].mask); |
| 10759 | kfree(rule->patterns); |
| 10760 | } |
| 10761 | kfree(coalesce->rules); |
| 10762 | kfree(coalesce); |
| 10763 | rdev->coalesce = NULL; |
| 10764 | } |
| 10765 | |
| 10766 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10767 | struct nlattr *rule, |
| 10768 | struct cfg80211_coalesce_rules *new_rule) |
| 10769 | { |
| 10770 | int err, i; |
| 10771 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10772 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10773 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10774 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10775 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10776 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10777 | nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10778 | if (err) |
| 10779 | return err; |
| 10780 | |
| 10781 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10782 | new_rule->delay = |
| 10783 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10784 | if (new_rule->delay > coalesce->max_delay) |
| 10785 | return -EINVAL; |
| 10786 | |
| 10787 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10788 | new_rule->condition = |
| 10789 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10790 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10791 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10792 | return -EINVAL; |
| 10793 | |
| 10794 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10795 | return -EINVAL; |
| 10796 | |
| 10797 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10798 | rem) |
| 10799 | n_patterns++; |
| 10800 | if (n_patterns > coalesce->n_patterns) |
| 10801 | return -EINVAL; |
| 10802 | |
| 10803 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10804 | GFP_KERNEL); |
| 10805 | if (!new_rule->patterns) |
| 10806 | return -ENOMEM; |
| 10807 | |
| 10808 | new_rule->n_patterns = n_patterns; |
| 10809 | i = 0; |
| 10810 | |
| 10811 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10812 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10813 | u8 *mask_pat; |
| 10814 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 10815 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10816 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10817 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10818 | return -EINVAL; |
| 10819 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10820 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10821 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10822 | return -EINVAL; |
| 10823 | if (pat_len > coalesce->pattern_max_len || |
| 10824 | pat_len < coalesce->pattern_min_len) |
| 10825 | return -EINVAL; |
| 10826 | |
| 10827 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10828 | pkt_offset = 0; |
| 10829 | else |
| 10830 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10831 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10832 | return -EINVAL; |
| 10833 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10834 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10835 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10836 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10837 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10838 | |
| 10839 | new_rule->patterns[i].mask = mask_pat; |
| 10840 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10841 | mask_len); |
| 10842 | |
| 10843 | mask_pat += mask_len; |
| 10844 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10845 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10846 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10847 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10848 | i++; |
| 10849 | } |
| 10850 | |
| 10851 | return 0; |
| 10852 | } |
| 10853 | |
| 10854 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10855 | { |
| 10856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10857 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10858 | struct cfg80211_coalesce new_coalesce = {}; |
| 10859 | struct cfg80211_coalesce *n_coalesce; |
| 10860 | int err, rem_rule, n_rules = 0, i, j; |
| 10861 | struct nlattr *rule; |
| 10862 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10863 | |
| 10864 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10865 | return -EOPNOTSUPP; |
| 10866 | |
| 10867 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10868 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10869 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10870 | return 0; |
| 10871 | } |
| 10872 | |
| 10873 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10874 | rem_rule) |
| 10875 | n_rules++; |
| 10876 | if (n_rules > coalesce->n_rules) |
| 10877 | return -EINVAL; |
| 10878 | |
| 10879 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10880 | GFP_KERNEL); |
| 10881 | if (!new_coalesce.rules) |
| 10882 | return -ENOMEM; |
| 10883 | |
| 10884 | new_coalesce.n_rules = n_rules; |
| 10885 | i = 0; |
| 10886 | |
| 10887 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10888 | rem_rule) { |
| 10889 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10890 | &new_coalesce.rules[i]); |
| 10891 | if (err) |
| 10892 | goto error; |
| 10893 | |
| 10894 | i++; |
| 10895 | } |
| 10896 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10897 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10898 | if (err) |
| 10899 | goto error; |
| 10900 | |
| 10901 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10902 | if (!n_coalesce) { |
| 10903 | err = -ENOMEM; |
| 10904 | goto error; |
| 10905 | } |
| 10906 | cfg80211_rdev_free_coalesce(rdev); |
| 10907 | rdev->coalesce = n_coalesce; |
| 10908 | |
| 10909 | return 0; |
| 10910 | error: |
| 10911 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10912 | tmp_rule = &new_coalesce.rules[i]; |
| 10913 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10914 | kfree(tmp_rule->patterns[j].mask); |
| 10915 | kfree(tmp_rule->patterns); |
| 10916 | } |
| 10917 | kfree(new_coalesce.rules); |
| 10918 | |
| 10919 | return err; |
| 10920 | } |
| 10921 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10922 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10923 | { |
| 10924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10925 | struct net_device *dev = info->user_ptr[1]; |
| 10926 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10927 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10928 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10929 | int err; |
| 10930 | |
| 10931 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10932 | return -EINVAL; |
| 10933 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10934 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 10935 | info->attrs[NL80211_ATTR_REKEY_DATA], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 10936 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10937 | if (err) |
| 10938 | return err; |
| 10939 | |
| 10940 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10941 | return -ERANGE; |
| 10942 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10943 | return -ERANGE; |
| 10944 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10945 | return -ERANGE; |
| 10946 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10947 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10948 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10949 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10950 | |
| 10951 | wdev_lock(wdev); |
| 10952 | if (!wdev->current_bss) { |
| 10953 | err = -ENOTCONN; |
| 10954 | goto out; |
| 10955 | } |
| 10956 | |
| 10957 | if (!rdev->ops->set_rekey_data) { |
| 10958 | err = -EOPNOTSUPP; |
| 10959 | goto out; |
| 10960 | } |
| 10961 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10962 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10963 | out: |
| 10964 | wdev_unlock(wdev); |
| 10965 | return err; |
| 10966 | } |
| 10967 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10968 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10969 | struct genl_info *info) |
| 10970 | { |
| 10971 | struct net_device *dev = info->user_ptr[1]; |
| 10972 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10973 | |
| 10974 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10975 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10976 | return -EINVAL; |
| 10977 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10978 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10979 | return -EBUSY; |
| 10980 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10981 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10982 | return 0; |
| 10983 | } |
| 10984 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10985 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10986 | struct genl_info *info) |
| 10987 | { |
| 10988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10989 | struct net_device *dev = info->user_ptr[1]; |
| 10990 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10991 | struct sk_buff *msg; |
| 10992 | void *hdr; |
| 10993 | const u8 *addr; |
| 10994 | u64 cookie; |
| 10995 | int err; |
| 10996 | |
| 10997 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10998 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10999 | return -EOPNOTSUPP; |
| 11000 | |
| 11001 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11002 | return -EINVAL; |
| 11003 | |
| 11004 | if (!rdev->ops->probe_client) |
| 11005 | return -EOPNOTSUPP; |
| 11006 | |
| 11007 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11008 | if (!msg) |
| 11009 | return -ENOMEM; |
| 11010 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11011 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11012 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11013 | if (!hdr) { |
| 11014 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11015 | goto free_msg; |
| 11016 | } |
| 11017 | |
| 11018 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11019 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11020 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11021 | if (err) |
| 11022 | goto free_msg; |
| 11023 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11024 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11025 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11026 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11027 | |
| 11028 | genlmsg_end(msg, hdr); |
| 11029 | |
| 11030 | return genlmsg_reply(msg, info); |
| 11031 | |
| 11032 | nla_put_failure: |
| 11033 | err = -ENOBUFS; |
| 11034 | free_msg: |
| 11035 | nlmsg_free(msg); |
| 11036 | return err; |
| 11037 | } |
| 11038 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11039 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 11040 | { |
| 11041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11042 | struct cfg80211_beacon_registration *reg, *nreg; |
| 11043 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11044 | |
| 11045 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 11046 | return -EOPNOTSUPP; |
| 11047 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11048 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 11049 | if (!nreg) |
| 11050 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11051 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11052 | /* First, check if already registered. */ |
| 11053 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11054 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11055 | if (reg->nlportid == info->snd_portid) { |
| 11056 | rv = -EALREADY; |
| 11057 | goto out_err; |
| 11058 | } |
| 11059 | } |
| 11060 | /* Add it to the list */ |
| 11061 | nreg->nlportid = info->snd_portid; |
| 11062 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 11063 | |
| 11064 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11065 | |
| 11066 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11067 | out_err: |
| 11068 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11069 | kfree(nreg); |
| 11070 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11071 | } |
| 11072 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11073 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11074 | { |
| 11075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11076 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11077 | int err; |
| 11078 | |
| 11079 | if (!rdev->ops->start_p2p_device) |
| 11080 | return -EOPNOTSUPP; |
| 11081 | |
| 11082 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11083 | return -EOPNOTSUPP; |
| 11084 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11085 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11086 | return 0; |
| 11087 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 11088 | if (rfkill_blocked(rdev->rfkill)) |
| 11089 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11090 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 11091 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11092 | if (err) |
| 11093 | return err; |
| 11094 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11095 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11096 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11097 | |
| 11098 | return 0; |
| 11099 | } |
| 11100 | |
| 11101 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 11102 | { |
| 11103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11104 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11105 | |
| 11106 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 11107 | return -EOPNOTSUPP; |
| 11108 | |
| 11109 | if (!rdev->ops->stop_p2p_device) |
| 11110 | return -EOPNOTSUPP; |
| 11111 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 11112 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11113 | |
| 11114 | return 0; |
| 11115 | } |
| 11116 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11117 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11118 | { |
| 11119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11120 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11121 | struct cfg80211_nan_conf conf = {}; |
| 11122 | int err; |
| 11123 | |
| 11124 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11125 | return -EOPNOTSUPP; |
| 11126 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11127 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11128 | return -EEXIST; |
| 11129 | |
| 11130 | if (rfkill_blocked(rdev->rfkill)) |
| 11131 | return -ERFKILL; |
| 11132 | |
| 11133 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11134 | return -EINVAL; |
| 11135 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11136 | conf.master_pref = |
| 11137 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11138 | if (!conf.master_pref) |
| 11139 | return -EINVAL; |
| 11140 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11141 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11142 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11143 | |
| 11144 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11145 | return -EOPNOTSUPP; |
| 11146 | |
| 11147 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11148 | return -EINVAL; |
| 11149 | |
| 11150 | conf.bands = bands; |
| 11151 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11152 | |
| 11153 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11154 | if (err) |
| 11155 | return err; |
| 11156 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11157 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11158 | rdev->opencount++; |
| 11159 | |
| 11160 | return 0; |
| 11161 | } |
| 11162 | |
| 11163 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11164 | { |
| 11165 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11166 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11167 | |
| 11168 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11169 | return -EOPNOTSUPP; |
| 11170 | |
| 11171 | cfg80211_stop_nan(rdev, wdev); |
| 11172 | |
| 11173 | return 0; |
| 11174 | } |
| 11175 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11176 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11177 | { |
| 11178 | struct nlattr *attr; |
| 11179 | int len = 0, n_entries = 0, rem; |
| 11180 | |
| 11181 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11182 | len += nla_len(attr); |
| 11183 | n_entries++; |
| 11184 | } |
| 11185 | |
| 11186 | if (len >= U8_MAX) |
| 11187 | return -EINVAL; |
| 11188 | |
| 11189 | return n_entries; |
| 11190 | } |
| 11191 | |
| 11192 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11193 | struct cfg80211_nan_func *func, |
| 11194 | bool tx) |
| 11195 | { |
| 11196 | struct nlattr *attr; |
| 11197 | int n_entries, rem, i; |
| 11198 | struct cfg80211_nan_func_filter *filter; |
| 11199 | |
| 11200 | n_entries = validate_nan_filter(attr_filter); |
| 11201 | if (n_entries < 0) |
| 11202 | return n_entries; |
| 11203 | |
| 11204 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11205 | |
| 11206 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11207 | if (!filter) |
| 11208 | return -ENOMEM; |
| 11209 | |
| 11210 | i = 0; |
| 11211 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11212 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11213 | filter[i].len = nla_len(attr); |
| 11214 | i++; |
| 11215 | } |
| 11216 | if (tx) { |
| 11217 | func->num_tx_filters = n_entries; |
| 11218 | func->tx_filters = filter; |
| 11219 | } else { |
| 11220 | func->num_rx_filters = n_entries; |
| 11221 | func->rx_filters = filter; |
| 11222 | } |
| 11223 | |
| 11224 | return 0; |
| 11225 | } |
| 11226 | |
| 11227 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11228 | struct genl_info *info) |
| 11229 | { |
| 11230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11231 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11232 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11233 | struct cfg80211_nan_func *func; |
| 11234 | struct sk_buff *msg = NULL; |
| 11235 | void *hdr = NULL; |
| 11236 | int err = 0; |
| 11237 | |
| 11238 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11239 | return -EOPNOTSUPP; |
| 11240 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11241 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11242 | return -ENOTCONN; |
| 11243 | |
| 11244 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11245 | return -EINVAL; |
| 11246 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11247 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11248 | info->attrs[NL80211_ATTR_NAN_FUNC], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11249 | nl80211_nan_func_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11250 | if (err) |
| 11251 | return err; |
| 11252 | |
| 11253 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11254 | if (!func) |
| 11255 | return -ENOMEM; |
| 11256 | |
| 11257 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11258 | |
| 11259 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11260 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11261 | err = -EINVAL; |
| 11262 | goto out; |
| 11263 | } |
| 11264 | |
| 11265 | |
| 11266 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11267 | |
| 11268 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11269 | err = -EINVAL; |
| 11270 | goto out; |
| 11271 | } |
| 11272 | |
| 11273 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11274 | sizeof(func->service_id)); |
| 11275 | |
| 11276 | func->close_range = |
| 11277 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11278 | |
| 11279 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11280 | func->serv_spec_info_len = |
| 11281 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11282 | func->serv_spec_info = |
| 11283 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11284 | func->serv_spec_info_len, |
| 11285 | GFP_KERNEL); |
| 11286 | if (!func->serv_spec_info) { |
| 11287 | err = -ENOMEM; |
| 11288 | goto out; |
| 11289 | } |
| 11290 | } |
| 11291 | |
| 11292 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11293 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11294 | |
| 11295 | switch (func->type) { |
| 11296 | case NL80211_NAN_FUNC_PUBLISH: |
| 11297 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11298 | err = -EINVAL; |
| 11299 | goto out; |
| 11300 | } |
| 11301 | |
| 11302 | func->publish_type = |
| 11303 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11304 | func->publish_bcast = |
| 11305 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11306 | |
| 11307 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11308 | func->publish_bcast) { |
| 11309 | err = -EINVAL; |
| 11310 | goto out; |
| 11311 | } |
| 11312 | break; |
| 11313 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11314 | func->subscribe_active = |
| 11315 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11316 | break; |
| 11317 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11318 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 11319 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 11320 | err = -EINVAL; |
| 11321 | goto out; |
| 11322 | } |
| 11323 | |
| 11324 | func->followup_id = |
| 11325 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11326 | func->followup_reqid = |
| 11327 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11328 | memcpy(func->followup_dest.addr, |
| 11329 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11330 | sizeof(func->followup_dest.addr)); |
| 11331 | if (func->ttl) { |
| 11332 | err = -EINVAL; |
| 11333 | goto out; |
| 11334 | } |
| 11335 | break; |
| 11336 | default: |
| 11337 | err = -EINVAL; |
| 11338 | goto out; |
| 11339 | } |
| 11340 | |
| 11341 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11342 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11343 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11344 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11345 | tb[NL80211_NAN_FUNC_SRF], |
Johannes Berg | fe52145 | 2017-04-12 14:34:08 +0200 | [diff] [blame] | 11346 | nl80211_nan_srf_policy, info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11347 | if (err) |
| 11348 | goto out; |
| 11349 | |
| 11350 | func->srf_include = |
| 11351 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11352 | |
| 11353 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11354 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11355 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11356 | err = -EINVAL; |
| 11357 | goto out; |
| 11358 | } |
| 11359 | |
| 11360 | func->srf_bf_len = |
| 11361 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11362 | func->srf_bf = |
| 11363 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11364 | func->srf_bf_len, GFP_KERNEL); |
| 11365 | if (!func->srf_bf) { |
| 11366 | err = -ENOMEM; |
| 11367 | goto out; |
| 11368 | } |
| 11369 | |
| 11370 | func->srf_bf_idx = |
| 11371 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11372 | } else { |
| 11373 | struct nlattr *attr, *mac_attr = |
| 11374 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11375 | int n_entries, rem, i = 0; |
| 11376 | |
| 11377 | if (!mac_attr) { |
| 11378 | err = -EINVAL; |
| 11379 | goto out; |
| 11380 | } |
| 11381 | |
| 11382 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11383 | if (n_entries <= 0) { |
| 11384 | err = -EINVAL; |
| 11385 | goto out; |
| 11386 | } |
| 11387 | |
| 11388 | func->srf_num_macs = n_entries; |
| 11389 | func->srf_macs = |
| 11390 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11391 | GFP_KERNEL); |
| 11392 | if (!func->srf_macs) { |
| 11393 | err = -ENOMEM; |
| 11394 | goto out; |
| 11395 | } |
| 11396 | |
| 11397 | nla_for_each_nested(attr, mac_attr, rem) |
| 11398 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11399 | sizeof(*func->srf_macs)); |
| 11400 | } |
| 11401 | } |
| 11402 | |
| 11403 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11404 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11405 | func, true); |
| 11406 | if (err) |
| 11407 | goto out; |
| 11408 | } |
| 11409 | |
| 11410 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11411 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11412 | func, false); |
| 11413 | if (err) |
| 11414 | goto out; |
| 11415 | } |
| 11416 | |
| 11417 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11418 | if (!msg) { |
| 11419 | err = -ENOMEM; |
| 11420 | goto out; |
| 11421 | } |
| 11422 | |
| 11423 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11424 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11425 | /* This can't really happen - we just allocated 4KB */ |
| 11426 | if (WARN_ON(!hdr)) { |
| 11427 | err = -ENOMEM; |
| 11428 | goto out; |
| 11429 | } |
| 11430 | |
| 11431 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11432 | out: |
| 11433 | if (err < 0) { |
| 11434 | cfg80211_free_nan_func(func); |
| 11435 | nlmsg_free(msg); |
| 11436 | return err; |
| 11437 | } |
| 11438 | |
| 11439 | /* propagate the instance id and cookie to userspace */ |
| 11440 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11441 | NL80211_ATTR_PAD)) |
| 11442 | goto nla_put_failure; |
| 11443 | |
| 11444 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11445 | if (!func_attr) |
| 11446 | goto nla_put_failure; |
| 11447 | |
| 11448 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11449 | func->instance_id)) |
| 11450 | goto nla_put_failure; |
| 11451 | |
| 11452 | nla_nest_end(msg, func_attr); |
| 11453 | |
| 11454 | genlmsg_end(msg, hdr); |
| 11455 | return genlmsg_reply(msg, info); |
| 11456 | |
| 11457 | nla_put_failure: |
| 11458 | nlmsg_free(msg); |
| 11459 | return -ENOBUFS; |
| 11460 | } |
| 11461 | |
| 11462 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11463 | struct genl_info *info) |
| 11464 | { |
| 11465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11466 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11467 | u64 cookie; |
| 11468 | |
| 11469 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11470 | return -EOPNOTSUPP; |
| 11471 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11472 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11473 | return -ENOTCONN; |
| 11474 | |
| 11475 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11476 | return -EINVAL; |
| 11477 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11478 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11479 | |
| 11480 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11481 | |
| 11482 | return 0; |
| 11483 | } |
| 11484 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11485 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11486 | struct genl_info *info) |
| 11487 | { |
| 11488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11489 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11490 | struct cfg80211_nan_conf conf = {}; |
| 11491 | u32 changed = 0; |
| 11492 | |
| 11493 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11494 | return -EOPNOTSUPP; |
| 11495 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11496 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11497 | return -ENOTCONN; |
| 11498 | |
| 11499 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11500 | conf.master_pref = |
| 11501 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11502 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11503 | return -EINVAL; |
| 11504 | |
| 11505 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11506 | } |
| 11507 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11508 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11509 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11510 | |
| 11511 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11512 | return -EOPNOTSUPP; |
| 11513 | |
| 11514 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11515 | return -EINVAL; |
| 11516 | |
| 11517 | conf.bands = bands; |
| 11518 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11519 | } |
| 11520 | |
| 11521 | if (!changed) |
| 11522 | return -EINVAL; |
| 11523 | |
| 11524 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11525 | } |
| 11526 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11527 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11528 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11529 | { |
| 11530 | struct wiphy *wiphy = wdev->wiphy; |
| 11531 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11532 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11533 | struct sk_buff *msg; |
| 11534 | void *hdr; |
| 11535 | |
| 11536 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11537 | return; |
| 11538 | |
| 11539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11540 | if (!msg) |
| 11541 | return; |
| 11542 | |
| 11543 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11544 | if (!hdr) { |
| 11545 | nlmsg_free(msg); |
| 11546 | return; |
| 11547 | } |
| 11548 | |
| 11549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11550 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11551 | wdev->netdev->ifindex)) || |
| 11552 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11553 | NL80211_ATTR_PAD)) |
| 11554 | goto nla_put_failure; |
| 11555 | |
| 11556 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11557 | NL80211_ATTR_PAD) || |
| 11558 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11559 | goto nla_put_failure; |
| 11560 | |
| 11561 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11562 | if (!match_attr) |
| 11563 | goto nla_put_failure; |
| 11564 | |
| 11565 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11566 | if (!local_func_attr) |
| 11567 | goto nla_put_failure; |
| 11568 | |
| 11569 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11570 | goto nla_put_failure; |
| 11571 | |
| 11572 | nla_nest_end(msg, local_func_attr); |
| 11573 | |
| 11574 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11575 | if (!peer_func_attr) |
| 11576 | goto nla_put_failure; |
| 11577 | |
| 11578 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11579 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11580 | goto nla_put_failure; |
| 11581 | |
| 11582 | if (match->info && match->info_len && |
| 11583 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11584 | match->info)) |
| 11585 | goto nla_put_failure; |
| 11586 | |
| 11587 | nla_nest_end(msg, peer_func_attr); |
| 11588 | nla_nest_end(msg, match_attr); |
| 11589 | genlmsg_end(msg, hdr); |
| 11590 | |
| 11591 | if (!wdev->owner_nlportid) |
| 11592 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11593 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11594 | else |
| 11595 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11596 | wdev->owner_nlportid); |
| 11597 | |
| 11598 | return; |
| 11599 | |
| 11600 | nla_put_failure: |
| 11601 | nlmsg_free(msg); |
| 11602 | } |
| 11603 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11604 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11605 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11606 | u8 inst_id, |
| 11607 | enum nl80211_nan_func_term_reason reason, |
| 11608 | u64 cookie, gfp_t gfp) |
| 11609 | { |
| 11610 | struct wiphy *wiphy = wdev->wiphy; |
| 11611 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11612 | struct sk_buff *msg; |
| 11613 | struct nlattr *func_attr; |
| 11614 | void *hdr; |
| 11615 | |
| 11616 | if (WARN_ON(!inst_id)) |
| 11617 | return; |
| 11618 | |
| 11619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11620 | if (!msg) |
| 11621 | return; |
| 11622 | |
| 11623 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11624 | if (!hdr) { |
| 11625 | nlmsg_free(msg); |
| 11626 | return; |
| 11627 | } |
| 11628 | |
| 11629 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11630 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11631 | wdev->netdev->ifindex)) || |
| 11632 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11633 | NL80211_ATTR_PAD)) |
| 11634 | goto nla_put_failure; |
| 11635 | |
| 11636 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11637 | NL80211_ATTR_PAD)) |
| 11638 | goto nla_put_failure; |
| 11639 | |
| 11640 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11641 | if (!func_attr) |
| 11642 | goto nla_put_failure; |
| 11643 | |
| 11644 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11645 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11646 | goto nla_put_failure; |
| 11647 | |
| 11648 | nla_nest_end(msg, func_attr); |
| 11649 | genlmsg_end(msg, hdr); |
| 11650 | |
| 11651 | if (!wdev->owner_nlportid) |
| 11652 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11653 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11654 | else |
| 11655 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11656 | wdev->owner_nlportid); |
| 11657 | |
| 11658 | return; |
| 11659 | |
| 11660 | nla_put_failure: |
| 11661 | nlmsg_free(msg); |
| 11662 | } |
| 11663 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11664 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11665 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11666 | struct genl_info *info) |
| 11667 | { |
| 11668 | void *hdr; |
| 11669 | struct sk_buff *msg; |
| 11670 | |
| 11671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11672 | if (!msg) |
| 11673 | return -ENOMEM; |
| 11674 | |
| 11675 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11676 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11677 | if (!hdr) |
| 11678 | goto nla_put_failure; |
| 11679 | |
| 11680 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11681 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11682 | goto nla_put_failure; |
| 11683 | |
| 11684 | genlmsg_end(msg, hdr); |
| 11685 | return genlmsg_reply(msg, info); |
| 11686 | |
| 11687 | nla_put_failure: |
| 11688 | kfree_skb(msg); |
| 11689 | return -ENOBUFS; |
| 11690 | } |
| 11691 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11692 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11693 | { |
| 11694 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11695 | struct cfg80211_update_ft_ies_params ft_params; |
| 11696 | struct net_device *dev = info->user_ptr[1]; |
| 11697 | |
| 11698 | if (!rdev->ops->update_ft_ies) |
| 11699 | return -EOPNOTSUPP; |
| 11700 | |
| 11701 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11702 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11703 | return -EINVAL; |
| 11704 | |
| 11705 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11706 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11707 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11708 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11709 | |
| 11710 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11711 | } |
| 11712 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11713 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11714 | struct genl_info *info) |
| 11715 | { |
| 11716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11717 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11718 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11719 | u16 duration; |
| 11720 | int ret; |
| 11721 | |
| 11722 | if (!rdev->ops->crit_proto_start) |
| 11723 | return -EOPNOTSUPP; |
| 11724 | |
| 11725 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11726 | return -EINVAL; |
| 11727 | |
| 11728 | if (rdev->crit_proto_nlportid) |
| 11729 | return -EBUSY; |
| 11730 | |
| 11731 | /* determine protocol if provided */ |
| 11732 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11733 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11734 | |
| 11735 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11736 | return -EINVAL; |
| 11737 | |
| 11738 | /* timeout must be provided */ |
| 11739 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11740 | return -EINVAL; |
| 11741 | |
| 11742 | duration = |
| 11743 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11744 | |
| 11745 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11746 | return -ERANGE; |
| 11747 | |
| 11748 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11749 | if (!ret) |
| 11750 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11751 | |
| 11752 | return ret; |
| 11753 | } |
| 11754 | |
| 11755 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11756 | struct genl_info *info) |
| 11757 | { |
| 11758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11759 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11760 | |
| 11761 | if (!rdev->ops->crit_proto_stop) |
| 11762 | return -EOPNOTSUPP; |
| 11763 | |
| 11764 | if (rdev->crit_proto_nlportid) { |
| 11765 | rdev->crit_proto_nlportid = 0; |
| 11766 | rdev_crit_proto_stop(rdev, wdev); |
| 11767 | } |
| 11768 | return 0; |
| 11769 | } |
| 11770 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11771 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11772 | { |
| 11773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11774 | struct wireless_dev *wdev = |
| 11775 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11776 | int i, err; |
| 11777 | u32 vid, subcmd; |
| 11778 | |
| 11779 | if (!rdev->wiphy.vendor_commands) |
| 11780 | return -EOPNOTSUPP; |
| 11781 | |
| 11782 | if (IS_ERR(wdev)) { |
| 11783 | err = PTR_ERR(wdev); |
| 11784 | if (err != -EINVAL) |
| 11785 | return err; |
| 11786 | wdev = NULL; |
| 11787 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11788 | return -EINVAL; |
| 11789 | } |
| 11790 | |
| 11791 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11792 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11793 | return -EINVAL; |
| 11794 | |
| 11795 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11796 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11797 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11798 | const struct wiphy_vendor_command *vcmd; |
| 11799 | void *data = NULL; |
| 11800 | int len = 0; |
| 11801 | |
| 11802 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11803 | |
| 11804 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11805 | continue; |
| 11806 | |
| 11807 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11808 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11809 | if (!wdev) |
| 11810 | return -EINVAL; |
| 11811 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11812 | !wdev->netdev) |
| 11813 | return -EINVAL; |
| 11814 | |
| 11815 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11816 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11817 | return -ENETDOWN; |
| 11818 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11819 | |
| 11820 | if (!vcmd->doit) |
| 11821 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11822 | } else { |
| 11823 | wdev = NULL; |
| 11824 | } |
| 11825 | |
| 11826 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11827 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11828 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11829 | } |
| 11830 | |
| 11831 | rdev->cur_cmd_info = info; |
| 11832 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11833 | data, len); |
| 11834 | rdev->cur_cmd_info = NULL; |
| 11835 | return err; |
| 11836 | } |
| 11837 | |
| 11838 | return -EOPNOTSUPP; |
| 11839 | } |
| 11840 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11841 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11842 | struct netlink_callback *cb, |
| 11843 | struct cfg80211_registered_device **rdev, |
| 11844 | struct wireless_dev **wdev) |
| 11845 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11846 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11847 | u32 vid, subcmd; |
| 11848 | unsigned int i; |
| 11849 | int vcmd_idx = -1; |
| 11850 | int err; |
| 11851 | void *data = NULL; |
| 11852 | unsigned int data_len = 0; |
| 11853 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11854 | if (cb->args[0]) { |
| 11855 | /* subtract the 1 again here */ |
| 11856 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11857 | struct wireless_dev *tmp; |
| 11858 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11859 | if (!wiphy) |
| 11860 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11861 | *rdev = wiphy_to_rdev(wiphy); |
| 11862 | *wdev = NULL; |
| 11863 | |
| 11864 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11865 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11866 | if (tmp->identifier == cb->args[1] - 1) { |
| 11867 | *wdev = tmp; |
| 11868 | break; |
| 11869 | } |
| 11870 | } |
| 11871 | } |
| 11872 | |
| 11873 | /* keep rtnl locked in successful case */ |
| 11874 | return 0; |
| 11875 | } |
| 11876 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 11877 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
| 11878 | nl80211_fam.maxattr, nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11879 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11880 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11881 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11882 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11883 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11884 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11885 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11886 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11887 | if (IS_ERR(*wdev)) |
| 11888 | *wdev = NULL; |
| 11889 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11890 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11891 | if (IS_ERR(*rdev)) |
| 11892 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11893 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11894 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11895 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11896 | |
| 11897 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11898 | const struct wiphy_vendor_command *vcmd; |
| 11899 | |
| 11900 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11901 | |
| 11902 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11903 | continue; |
| 11904 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11905 | if (!vcmd->dumpit) |
| 11906 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11907 | |
| 11908 | vcmd_idx = i; |
| 11909 | break; |
| 11910 | } |
| 11911 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11912 | if (vcmd_idx < 0) |
| 11913 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11914 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11915 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11916 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11917 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11918 | } |
| 11919 | |
| 11920 | /* 0 is the first index - add 1 to parse only once */ |
| 11921 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11922 | /* add 1 to know if it was NULL */ |
| 11923 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11924 | cb->args[2] = vcmd_idx; |
| 11925 | cb->args[3] = (unsigned long)data; |
| 11926 | cb->args[4] = data_len; |
| 11927 | |
| 11928 | /* keep rtnl locked in successful case */ |
| 11929 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11930 | } |
| 11931 | |
| 11932 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11933 | struct netlink_callback *cb) |
| 11934 | { |
| 11935 | struct cfg80211_registered_device *rdev; |
| 11936 | struct wireless_dev *wdev; |
| 11937 | unsigned int vcmd_idx; |
| 11938 | const struct wiphy_vendor_command *vcmd; |
| 11939 | void *data; |
| 11940 | int data_len; |
| 11941 | int err; |
| 11942 | struct nlattr *vendor_data; |
| 11943 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11944 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11945 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11946 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11947 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11948 | |
| 11949 | vcmd_idx = cb->args[2]; |
| 11950 | data = (void *)cb->args[3]; |
| 11951 | data_len = cb->args[4]; |
| 11952 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11953 | |
| 11954 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11955 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11956 | if (!wdev) { |
| 11957 | err = -EINVAL; |
| 11958 | goto out; |
| 11959 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11960 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11961 | !wdev->netdev) { |
| 11962 | err = -EINVAL; |
| 11963 | goto out; |
| 11964 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11965 | |
| 11966 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11967 | if (!wdev_running(wdev)) { |
| 11968 | err = -ENETDOWN; |
| 11969 | goto out; |
| 11970 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11971 | } |
| 11972 | } |
| 11973 | |
| 11974 | while (1) { |
| 11975 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11976 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11977 | NL80211_CMD_VENDOR); |
| 11978 | if (!hdr) |
| 11979 | break; |
| 11980 | |
| 11981 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11982 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11983 | wdev_id(wdev), |
| 11984 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11985 | genlmsg_cancel(skb, hdr); |
| 11986 | break; |
| 11987 | } |
| 11988 | |
| 11989 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11990 | if (!vendor_data) { |
| 11991 | genlmsg_cancel(skb, hdr); |
| 11992 | break; |
| 11993 | } |
| 11994 | |
| 11995 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11996 | (unsigned long *)&cb->args[5]); |
| 11997 | nla_nest_end(skb, vendor_data); |
| 11998 | |
| 11999 | if (err == -ENOBUFS || err == -ENOENT) { |
| 12000 | genlmsg_cancel(skb, hdr); |
| 12001 | break; |
| 12002 | } else if (err) { |
| 12003 | genlmsg_cancel(skb, hdr); |
| 12004 | goto out; |
| 12005 | } |
| 12006 | |
| 12007 | genlmsg_end(skb, hdr); |
| 12008 | } |
| 12009 | |
| 12010 | err = skb->len; |
| 12011 | out: |
| 12012 | rtnl_unlock(); |
| 12013 | return err; |
| 12014 | } |
| 12015 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12016 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 12017 | enum nl80211_commands cmd, |
| 12018 | enum nl80211_attrs attr, |
| 12019 | int approxlen) |
| 12020 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12021 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12022 | |
| 12023 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 12024 | return NULL; |
| 12025 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 12026 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12027 | rdev->cur_cmd_info->snd_portid, |
| 12028 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 12029 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12030 | } |
| 12031 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 12032 | |
| 12033 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 12034 | { |
| 12035 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 12036 | void *hdr = ((void **)skb->cb)[1]; |
| 12037 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 12038 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 12039 | /* clear CB data for netlink core to own from now on */ |
| 12040 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 12041 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12042 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 12043 | kfree_skb(skb); |
| 12044 | return -EINVAL; |
| 12045 | } |
| 12046 | |
| 12047 | nla_nest_end(skb, data); |
| 12048 | genlmsg_end(skb, hdr); |
| 12049 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 12050 | } |
| 12051 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 12052 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12053 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 12054 | struct genl_info *info) |
| 12055 | { |
| 12056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12057 | struct cfg80211_qos_map *qos_map = NULL; |
| 12058 | struct net_device *dev = info->user_ptr[1]; |
| 12059 | u8 *pos, len, num_des, des_len, des; |
| 12060 | int ret; |
| 12061 | |
| 12062 | if (!rdev->ops->set_qos_map) |
| 12063 | return -EOPNOTSUPP; |
| 12064 | |
| 12065 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 12066 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12067 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 12068 | |
| 12069 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 12070 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 12071 | return -EINVAL; |
| 12072 | |
| 12073 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 12074 | if (!qos_map) |
| 12075 | return -ENOMEM; |
| 12076 | |
| 12077 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 12078 | if (num_des) { |
| 12079 | des_len = num_des * |
| 12080 | sizeof(struct cfg80211_dscp_exception); |
| 12081 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 12082 | qos_map->num_des = num_des; |
| 12083 | for (des = 0; des < num_des; des++) { |
| 12084 | if (qos_map->dscp_exception[des].up > 7) { |
| 12085 | kfree(qos_map); |
| 12086 | return -EINVAL; |
| 12087 | } |
| 12088 | } |
| 12089 | pos += des_len; |
| 12090 | } |
| 12091 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 12092 | } |
| 12093 | |
| 12094 | wdev_lock(dev->ieee80211_ptr); |
| 12095 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 12096 | if (!ret) |
| 12097 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 12098 | wdev_unlock(dev->ieee80211_ptr); |
| 12099 | |
| 12100 | kfree(qos_map); |
| 12101 | return ret; |
| 12102 | } |
| 12103 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12104 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12105 | { |
| 12106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12107 | struct net_device *dev = info->user_ptr[1]; |
| 12108 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12109 | const u8 *peer; |
| 12110 | u8 tsid, up; |
| 12111 | u16 admitted_time = 0; |
| 12112 | int err; |
| 12113 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12114 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12115 | return -EOPNOTSUPP; |
| 12116 | |
| 12117 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12118 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12119 | return -EINVAL; |
| 12120 | |
| 12121 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12122 | if (tsid >= IEEE80211_NUM_TIDS) |
| 12123 | return -EINVAL; |
| 12124 | |
| 12125 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 12126 | if (up >= IEEE80211_NUM_UPS) |
| 12127 | return -EINVAL; |
| 12128 | |
| 12129 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12130 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12131 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12132 | * need more attributes for that (e.g. BA session requirement); |
| 12133 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12134 | */ |
| 12135 | return -EINVAL; |
| 12136 | } |
| 12137 | |
| 12138 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12139 | |
| 12140 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12141 | admitted_time = |
| 12142 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12143 | if (!admitted_time) |
| 12144 | return -EINVAL; |
| 12145 | } |
| 12146 | |
| 12147 | wdev_lock(wdev); |
| 12148 | switch (wdev->iftype) { |
| 12149 | case NL80211_IFTYPE_STATION: |
| 12150 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12151 | if (wdev->current_bss) |
| 12152 | break; |
| 12153 | err = -ENOTCONN; |
| 12154 | goto out; |
| 12155 | default: |
| 12156 | err = -EOPNOTSUPP; |
| 12157 | goto out; |
| 12158 | } |
| 12159 | |
| 12160 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12161 | |
| 12162 | out: |
| 12163 | wdev_unlock(wdev); |
| 12164 | return err; |
| 12165 | } |
| 12166 | |
| 12167 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12168 | { |
| 12169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12170 | struct net_device *dev = info->user_ptr[1]; |
| 12171 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12172 | const u8 *peer; |
| 12173 | u8 tsid; |
| 12174 | int err; |
| 12175 | |
| 12176 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12177 | return -EINVAL; |
| 12178 | |
| 12179 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12180 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12181 | |
| 12182 | wdev_lock(wdev); |
| 12183 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12184 | wdev_unlock(wdev); |
| 12185 | |
| 12186 | return err; |
| 12187 | } |
| 12188 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12189 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12190 | struct genl_info *info) |
| 12191 | { |
| 12192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12193 | struct net_device *dev = info->user_ptr[1]; |
| 12194 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12195 | struct cfg80211_chan_def chandef = {}; |
| 12196 | const u8 *addr; |
| 12197 | u8 oper_class; |
| 12198 | int err; |
| 12199 | |
| 12200 | if (!rdev->ops->tdls_channel_switch || |
| 12201 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12202 | return -EOPNOTSUPP; |
| 12203 | |
| 12204 | switch (dev->ieee80211_ptr->iftype) { |
| 12205 | case NL80211_IFTYPE_STATION: |
| 12206 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12207 | break; |
| 12208 | default: |
| 12209 | return -EOPNOTSUPP; |
| 12210 | } |
| 12211 | |
| 12212 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12213 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12214 | return -EINVAL; |
| 12215 | |
| 12216 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12217 | if (err) |
| 12218 | return err; |
| 12219 | |
| 12220 | /* |
| 12221 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12222 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12223 | * specification is not defined for them. |
| 12224 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12225 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12226 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12227 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12228 | return -EINVAL; |
| 12229 | |
| 12230 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12231 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12232 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12233 | return -EINVAL; |
| 12234 | |
| 12235 | /* don't allow switching to DFS channels */ |
| 12236 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12237 | return -EINVAL; |
| 12238 | |
| 12239 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12240 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12241 | |
| 12242 | wdev_lock(wdev); |
| 12243 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12244 | wdev_unlock(wdev); |
| 12245 | |
| 12246 | return err; |
| 12247 | } |
| 12248 | |
| 12249 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12250 | struct genl_info *info) |
| 12251 | { |
| 12252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12253 | struct net_device *dev = info->user_ptr[1]; |
| 12254 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12255 | const u8 *addr; |
| 12256 | |
| 12257 | if (!rdev->ops->tdls_channel_switch || |
| 12258 | !rdev->ops->tdls_cancel_channel_switch || |
| 12259 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12260 | return -EOPNOTSUPP; |
| 12261 | |
| 12262 | switch (dev->ieee80211_ptr->iftype) { |
| 12263 | case NL80211_IFTYPE_STATION: |
| 12264 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12265 | break; |
| 12266 | default: |
| 12267 | return -EOPNOTSUPP; |
| 12268 | } |
| 12269 | |
| 12270 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12271 | return -EINVAL; |
| 12272 | |
| 12273 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12274 | |
| 12275 | wdev_lock(wdev); |
| 12276 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12277 | wdev_unlock(wdev); |
| 12278 | |
| 12279 | return 0; |
| 12280 | } |
| 12281 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12282 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12283 | struct genl_info *info) |
| 12284 | { |
| 12285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12286 | struct net_device *dev = info->user_ptr[1]; |
| 12287 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12288 | const struct nlattr *nla; |
| 12289 | bool enabled; |
| 12290 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12291 | if (!rdev->ops->set_multicast_to_unicast) |
| 12292 | return -EOPNOTSUPP; |
| 12293 | |
| 12294 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12295 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12296 | return -EOPNOTSUPP; |
| 12297 | |
| 12298 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12299 | enabled = nla_get_flag(nla); |
| 12300 | |
| 12301 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12302 | } |
| 12303 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 12304 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12305 | { |
| 12306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12307 | struct net_device *dev = info->user_ptr[1]; |
| 12308 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12309 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 12310 | int ret; |
| 12311 | |
| 12312 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12313 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12314 | return -EOPNOTSUPP; |
| 12315 | |
| 12316 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12317 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12318 | return -EOPNOTSUPP; |
| 12319 | |
| 12320 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 12321 | return -EINVAL; |
| 12322 | |
| 12323 | wdev_lock(wdev); |
| 12324 | if (!wdev->current_bss) { |
| 12325 | ret = -ENOTCONN; |
| 12326 | goto out; |
| 12327 | } |
| 12328 | |
| 12329 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12330 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 12331 | ret = -EINVAL; |
| 12332 | goto out; |
| 12333 | } |
| 12334 | |
| 12335 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 12336 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 12337 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 12338 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 12339 | ret = -EINVAL; |
| 12340 | goto out; |
| 12341 | } |
| 12342 | |
| 12343 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { |
| 12344 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12345 | |
| 12346 | if (r0_name_len != WLAN_PMK_NAME_LEN) { |
| 12347 | ret = -EINVAL; |
| 12348 | goto out; |
| 12349 | } |
| 12350 | |
| 12351 | pmk_conf.pmk_r0_name = |
| 12352 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| 12353 | } |
| 12354 | |
| 12355 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 12356 | out: |
| 12357 | wdev_unlock(wdev); |
| 12358 | return ret; |
| 12359 | } |
| 12360 | |
| 12361 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 12362 | { |
| 12363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12364 | struct net_device *dev = info->user_ptr[1]; |
| 12365 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12366 | const u8 *aa; |
| 12367 | int ret; |
| 12368 | |
| 12369 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 12370 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 12371 | return -EOPNOTSUPP; |
| 12372 | |
| 12373 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 12374 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 12375 | return -EOPNOTSUPP; |
| 12376 | |
| 12377 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12378 | return -EINVAL; |
| 12379 | |
| 12380 | wdev_lock(wdev); |
| 12381 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12382 | ret = rdev_del_pmk(rdev, dev, aa); |
| 12383 | wdev_unlock(wdev); |
| 12384 | |
| 12385 | return ret; |
| 12386 | } |
| 12387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12388 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12389 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12390 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12391 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 12392 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 12393 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12394 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12395 | /* 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] | 12396 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 12397 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12398 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12399 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12400 | 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] | 12401 | struct genl_info *info) |
| 12402 | { |
| 12403 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12404 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12405 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12406 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 12407 | |
| 12408 | if (rtnl) |
| 12409 | rtnl_lock(); |
| 12410 | |
| 12411 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 12412 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12413 | if (IS_ERR(rdev)) { |
| 12414 | if (rtnl) |
| 12415 | rtnl_unlock(); |
| 12416 | return PTR_ERR(rdev); |
| 12417 | } |
| 12418 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12419 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 12420 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12421 | ASSERT_RTNL(); |
| 12422 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12423 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 12424 | info->attrs); |
| 12425 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12426 | if (rtnl) |
| 12427 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12428 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12429 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12430 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12431 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12432 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12433 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12434 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 12435 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12436 | if (rtnl) |
| 12437 | rtnl_unlock(); |
| 12438 | return -EINVAL; |
| 12439 | } |
| 12440 | |
| 12441 | info->user_ptr[1] = dev; |
| 12442 | } else { |
| 12443 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12444 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12445 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12446 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 12447 | !wdev_running(wdev)) { |
| 12448 | if (rtnl) |
| 12449 | rtnl_unlock(); |
| 12450 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12451 | } |
| 12452 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12453 | if (dev) |
| 12454 | dev_hold(dev); |
| 12455 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12456 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12457 | } |
| 12458 | |
| 12459 | return 0; |
| 12460 | } |
| 12461 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12462 | 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] | 12463 | struct genl_info *info) |
| 12464 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12465 | if (info->user_ptr[1]) { |
| 12466 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 12467 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12468 | |
| 12469 | if (wdev->netdev) |
| 12470 | dev_put(wdev->netdev); |
| 12471 | } else { |
| 12472 | dev_put(info->user_ptr[1]); |
| 12473 | } |
| 12474 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12476 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 12477 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12478 | |
| 12479 | /* If needed, clear the netlink message payload from the SKB |
| 12480 | * as it might contain key data that shouldn't stick around on |
| 12481 | * the heap after the SKB is freed. The netlink message header |
| 12482 | * is still needed for further processing, so leave it intact. |
| 12483 | */ |
| 12484 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 12485 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 12486 | |
| 12487 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 12488 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12489 | } |
| 12490 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 12491 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12492 | { |
| 12493 | .cmd = NL80211_CMD_GET_WIPHY, |
| 12494 | .doit = nl80211_get_wiphy, |
| 12495 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12496 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12497 | .policy = nl80211_policy, |
| 12498 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12499 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12500 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12501 | }, |
| 12502 | { |
| 12503 | .cmd = NL80211_CMD_SET_WIPHY, |
| 12504 | .doit = nl80211_set_wiphy, |
| 12505 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12506 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12507 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12508 | }, |
| 12509 | { |
| 12510 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 12511 | .doit = nl80211_get_interface, |
| 12512 | .dumpit = nl80211_dump_interface, |
| 12513 | .policy = nl80211_policy, |
| 12514 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12515 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12516 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12517 | }, |
| 12518 | { |
| 12519 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 12520 | .doit = nl80211_set_interface, |
| 12521 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12522 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12523 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12524 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12525 | }, |
| 12526 | { |
| 12527 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 12528 | .doit = nl80211_new_interface, |
| 12529 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12530 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12531 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12532 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12533 | }, |
| 12534 | { |
| 12535 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 12536 | .doit = nl80211_del_interface, |
| 12537 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12538 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 12539 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12540 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12541 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12542 | { |
| 12543 | .cmd = NL80211_CMD_GET_KEY, |
| 12544 | .doit = nl80211_get_key, |
| 12545 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12546 | .flags = GENL_UNS_ADMIN_PERM, |
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 | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12549 | }, |
| 12550 | { |
| 12551 | .cmd = NL80211_CMD_SET_KEY, |
| 12552 | .doit = nl80211_set_key, |
| 12553 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12554 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12556 | NL80211_FLAG_NEED_RTNL | |
| 12557 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12558 | }, |
| 12559 | { |
| 12560 | .cmd = NL80211_CMD_NEW_KEY, |
| 12561 | .doit = nl80211_new_key, |
| 12562 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12563 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12564 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12565 | NL80211_FLAG_NEED_RTNL | |
| 12566 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12567 | }, |
| 12568 | { |
| 12569 | .cmd = NL80211_CMD_DEL_KEY, |
| 12570 | .doit = nl80211_del_key, |
| 12571 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12572 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12574 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12575 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12576 | { |
| 12577 | .cmd = NL80211_CMD_SET_BEACON, |
| 12578 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12579 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12580 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12582 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12583 | }, |
| 12584 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12585 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12586 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12587 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12588 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12590 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12591 | }, |
| 12592 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12593 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12594 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12595 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12596 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12597 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12598 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12599 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12600 | { |
| 12601 | .cmd = NL80211_CMD_GET_STATION, |
| 12602 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12603 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12604 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12605 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12606 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12607 | }, |
| 12608 | { |
| 12609 | .cmd = NL80211_CMD_SET_STATION, |
| 12610 | .doit = nl80211_set_station, |
| 12611 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12612 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12614 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12615 | }, |
| 12616 | { |
| 12617 | .cmd = NL80211_CMD_NEW_STATION, |
| 12618 | .doit = nl80211_new_station, |
| 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, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12623 | }, |
| 12624 | { |
| 12625 | .cmd = NL80211_CMD_DEL_STATION, |
| 12626 | .doit = nl80211_del_station, |
| 12627 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12628 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12631 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12632 | { |
| 12633 | .cmd = NL80211_CMD_GET_MPATH, |
| 12634 | .doit = nl80211_get_mpath, |
| 12635 | .dumpit = nl80211_dump_mpath, |
| 12636 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12637 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12638 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12639 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12640 | }, |
| 12641 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12642 | .cmd = NL80211_CMD_GET_MPP, |
| 12643 | .doit = nl80211_get_mpp, |
| 12644 | .dumpit = nl80211_dump_mpp, |
| 12645 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12646 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12648 | NL80211_FLAG_NEED_RTNL, |
| 12649 | }, |
| 12650 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12651 | .cmd = NL80211_CMD_SET_MPATH, |
| 12652 | .doit = nl80211_set_mpath, |
| 12653 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12654 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12656 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12657 | }, |
| 12658 | { |
| 12659 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12660 | .doit = nl80211_new_mpath, |
| 12661 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12662 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12664 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12665 | }, |
| 12666 | { |
| 12667 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12668 | .doit = nl80211_del_mpath, |
| 12669 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12670 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12672 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12673 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12674 | { |
| 12675 | .cmd = NL80211_CMD_SET_BSS, |
| 12676 | .doit = nl80211_set_bss, |
| 12677 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12678 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12680 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12681 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12682 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12683 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12684 | .doit = nl80211_get_reg_do, |
| 12685 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12686 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12687 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12688 | /* can be retrieved by unprivileged users */ |
| 12689 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12690 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12691 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12692 | .cmd = NL80211_CMD_SET_REG, |
| 12693 | .doit = nl80211_set_reg, |
| 12694 | .policy = nl80211_policy, |
| 12695 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12696 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12697 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12698 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12699 | { |
| 12700 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12701 | .doit = nl80211_req_set_reg, |
| 12702 | .policy = nl80211_policy, |
| 12703 | .flags = GENL_ADMIN_PERM, |
| 12704 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12705 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12706 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12707 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12708 | .policy = nl80211_policy, |
| 12709 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12710 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12711 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12712 | }, |
| 12713 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12714 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12715 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12716 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12717 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12718 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12719 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12720 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12721 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12722 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12723 | .doit = nl80211_trigger_scan, |
| 12724 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12725 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12726 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12728 | }, |
| 12729 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12730 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12731 | .doit = nl80211_abort_scan, |
| 12732 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12733 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12734 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12735 | NL80211_FLAG_NEED_RTNL, |
| 12736 | }, |
| 12737 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12738 | .cmd = NL80211_CMD_GET_SCAN, |
| 12739 | .policy = nl80211_policy, |
| 12740 | .dumpit = nl80211_dump_scan, |
| 12741 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12742 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12743 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12744 | .doit = nl80211_start_sched_scan, |
| 12745 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12746 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12748 | NL80211_FLAG_NEED_RTNL, |
| 12749 | }, |
| 12750 | { |
| 12751 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12752 | .doit = nl80211_stop_sched_scan, |
| 12753 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12754 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12755 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12756 | NL80211_FLAG_NEED_RTNL, |
| 12757 | }, |
| 12758 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12759 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12760 | .doit = nl80211_authenticate, |
| 12761 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12762 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12763 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12764 | NL80211_FLAG_NEED_RTNL | |
| 12765 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12766 | }, |
| 12767 | { |
| 12768 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12769 | .doit = nl80211_associate, |
| 12770 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12771 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12772 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12773 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12774 | }, |
| 12775 | { |
| 12776 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12777 | .doit = nl80211_deauthenticate, |
| 12778 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12779 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12780 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12781 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12782 | }, |
| 12783 | { |
| 12784 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12785 | .doit = nl80211_disassociate, |
| 12786 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12787 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12788 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12789 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12790 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12791 | { |
| 12792 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12793 | .doit = nl80211_join_ibss, |
| 12794 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12795 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12796 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12797 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12798 | }, |
| 12799 | { |
| 12800 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12801 | .doit = nl80211_leave_ibss, |
| 12802 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12803 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12805 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12806 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12807 | #ifdef CONFIG_NL80211_TESTMODE |
| 12808 | { |
| 12809 | .cmd = NL80211_CMD_TESTMODE, |
| 12810 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12811 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12812 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12813 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12814 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12815 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12816 | }, |
| 12817 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12818 | { |
| 12819 | .cmd = NL80211_CMD_CONNECT, |
| 12820 | .doit = nl80211_connect, |
| 12821 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12822 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12824 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12825 | }, |
| 12826 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12827 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12828 | .doit = nl80211_update_connect_params, |
| 12829 | .policy = nl80211_policy, |
| 12830 | .flags = GENL_ADMIN_PERM, |
| 12831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12832 | NL80211_FLAG_NEED_RTNL, |
| 12833 | }, |
| 12834 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12835 | .cmd = NL80211_CMD_DISCONNECT, |
| 12836 | .doit = nl80211_disconnect, |
| 12837 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12838 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12840 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12841 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12842 | { |
| 12843 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12844 | .doit = nl80211_wiphy_netns, |
| 12845 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12846 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12847 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12848 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12849 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12850 | { |
| 12851 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12852 | .policy = nl80211_policy, |
| 12853 | .dumpit = nl80211_dump_survey, |
| 12854 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12855 | { |
| 12856 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12857 | .doit = nl80211_setdel_pmksa, |
| 12858 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12859 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12860 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12861 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12862 | }, |
| 12863 | { |
| 12864 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12865 | .doit = nl80211_setdel_pmksa, |
| 12866 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12867 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12868 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12869 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12870 | }, |
| 12871 | { |
| 12872 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12873 | .doit = nl80211_flush_pmksa, |
| 12874 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12875 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12876 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12877 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12878 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12879 | { |
| 12880 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12881 | .doit = nl80211_remain_on_channel, |
| 12882 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12883 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12884 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12885 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12886 | }, |
| 12887 | { |
| 12888 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12889 | .doit = nl80211_cancel_remain_on_channel, |
| 12890 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12891 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12892 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12893 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12894 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12895 | { |
| 12896 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12897 | .doit = nl80211_set_tx_bitrate_mask, |
| 12898 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12899 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12900 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12901 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12902 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12903 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12904 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12905 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12906 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12907 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12908 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12909 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12910 | }, |
| 12911 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12912 | .cmd = NL80211_CMD_FRAME, |
| 12913 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12914 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12915 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12916 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12917 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12918 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12919 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12920 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12921 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12922 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12923 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12924 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12925 | NL80211_FLAG_NEED_RTNL, |
| 12926 | }, |
| 12927 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12928 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12929 | .doit = nl80211_set_power_save, |
| 12930 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12931 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12932 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12933 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12934 | }, |
| 12935 | { |
| 12936 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12937 | .doit = nl80211_get_power_save, |
| 12938 | .policy = nl80211_policy, |
| 12939 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12940 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12941 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12942 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12943 | { |
| 12944 | .cmd = NL80211_CMD_SET_CQM, |
| 12945 | .doit = nl80211_set_cqm, |
| 12946 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12947 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12948 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12949 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12950 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12951 | { |
| 12952 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12953 | .doit = nl80211_set_channel, |
| 12954 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12955 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12956 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12957 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12958 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12959 | { |
| 12960 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12961 | .doit = nl80211_set_wds_peer, |
| 12962 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12963 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12964 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12965 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12966 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12967 | { |
| 12968 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12969 | .doit = nl80211_join_mesh, |
| 12970 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12971 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12972 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12973 | NL80211_FLAG_NEED_RTNL, |
| 12974 | }, |
| 12975 | { |
| 12976 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12977 | .doit = nl80211_leave_mesh, |
| 12978 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12979 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12980 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12981 | NL80211_FLAG_NEED_RTNL, |
| 12982 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12983 | { |
| 12984 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12985 | .doit = nl80211_join_ocb, |
| 12986 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12987 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12988 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12989 | NL80211_FLAG_NEED_RTNL, |
| 12990 | }, |
| 12991 | { |
| 12992 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12993 | .doit = nl80211_leave_ocb, |
| 12994 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12995 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12996 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12997 | NL80211_FLAG_NEED_RTNL, |
| 12998 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12999 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13000 | { |
| 13001 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 13002 | .doit = nl80211_get_wowlan, |
| 13003 | .policy = nl80211_policy, |
| 13004 | /* can be retrieved by unprivileged users */ |
| 13005 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13006 | NL80211_FLAG_NEED_RTNL, |
| 13007 | }, |
| 13008 | { |
| 13009 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 13010 | .doit = nl80211_set_wowlan, |
| 13011 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13012 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 13013 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13014 | NL80211_FLAG_NEED_RTNL, |
| 13015 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 13016 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13017 | { |
| 13018 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 13019 | .doit = nl80211_set_rekey_data, |
| 13020 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13021 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 13023 | NL80211_FLAG_NEED_RTNL | |
| 13024 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13025 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13026 | { |
| 13027 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 13028 | .doit = nl80211_tdls_mgmt, |
| 13029 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13030 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13032 | NL80211_FLAG_NEED_RTNL, |
| 13033 | }, |
| 13034 | { |
| 13035 | .cmd = NL80211_CMD_TDLS_OPER, |
| 13036 | .doit = nl80211_tdls_oper, |
| 13037 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13038 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 13039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13040 | NL80211_FLAG_NEED_RTNL, |
| 13041 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13042 | { |
| 13043 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 13044 | .doit = nl80211_register_unexpected_frame, |
| 13045 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13046 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13047 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13048 | NL80211_FLAG_NEED_RTNL, |
| 13049 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13050 | { |
| 13051 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 13052 | .doit = nl80211_probe_client, |
| 13053 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13054 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 13055 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13056 | NL80211_FLAG_NEED_RTNL, |
| 13057 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13058 | { |
| 13059 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 13060 | .doit = nl80211_register_beacons, |
| 13061 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13062 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13063 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13064 | NL80211_FLAG_NEED_RTNL, |
| 13065 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13066 | { |
| 13067 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 13068 | .doit = nl80211_set_noack_map, |
| 13069 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13070 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 13071 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13072 | NL80211_FLAG_NEED_RTNL, |
| 13073 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13074 | { |
| 13075 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 13076 | .doit = nl80211_start_p2p_device, |
| 13077 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13078 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13079 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13080 | NL80211_FLAG_NEED_RTNL, |
| 13081 | }, |
| 13082 | { |
| 13083 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 13084 | .doit = nl80211_stop_p2p_device, |
| 13085 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13086 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13087 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13088 | NL80211_FLAG_NEED_RTNL, |
| 13089 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13090 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13091 | .cmd = NL80211_CMD_START_NAN, |
| 13092 | .doit = nl80211_start_nan, |
| 13093 | .policy = nl80211_policy, |
| 13094 | .flags = GENL_ADMIN_PERM, |
| 13095 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 13096 | NL80211_FLAG_NEED_RTNL, |
| 13097 | }, |
| 13098 | { |
| 13099 | .cmd = NL80211_CMD_STOP_NAN, |
| 13100 | .doit = nl80211_stop_nan, |
| 13101 | .policy = nl80211_policy, |
| 13102 | .flags = GENL_ADMIN_PERM, |
| 13103 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13104 | NL80211_FLAG_NEED_RTNL, |
| 13105 | }, |
| 13106 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13107 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 13108 | .doit = nl80211_nan_add_func, |
| 13109 | .policy = nl80211_policy, |
| 13110 | .flags = GENL_ADMIN_PERM, |
| 13111 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13112 | NL80211_FLAG_NEED_RTNL, |
| 13113 | }, |
| 13114 | { |
| 13115 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 13116 | .doit = nl80211_nan_del_func, |
| 13117 | .policy = nl80211_policy, |
| 13118 | .flags = GENL_ADMIN_PERM, |
| 13119 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13120 | NL80211_FLAG_NEED_RTNL, |
| 13121 | }, |
| 13122 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13123 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 13124 | .doit = nl80211_nan_change_config, |
| 13125 | .policy = nl80211_policy, |
| 13126 | .flags = GENL_ADMIN_PERM, |
| 13127 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13128 | NL80211_FLAG_NEED_RTNL, |
| 13129 | }, |
| 13130 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13131 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 13132 | .doit = nl80211_set_mcast_rate, |
| 13133 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13134 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 13135 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13136 | NL80211_FLAG_NEED_RTNL, |
| 13137 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13138 | { |
| 13139 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 13140 | .doit = nl80211_set_mac_acl, |
| 13141 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13142 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 13143 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13144 | NL80211_FLAG_NEED_RTNL, |
| 13145 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13146 | { |
| 13147 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 13148 | .doit = nl80211_start_radar_detection, |
| 13149 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13150 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13151 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13152 | NL80211_FLAG_NEED_RTNL, |
| 13153 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13154 | { |
| 13155 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 13156 | .doit = nl80211_get_protocol_features, |
| 13157 | .policy = nl80211_policy, |
| 13158 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13159 | { |
| 13160 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 13161 | .doit = nl80211_update_ft_ies, |
| 13162 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13163 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13164 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13165 | NL80211_FLAG_NEED_RTNL, |
| 13166 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13167 | { |
| 13168 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 13169 | .doit = nl80211_crit_protocol_start, |
| 13170 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13171 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13172 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13173 | NL80211_FLAG_NEED_RTNL, |
| 13174 | }, |
| 13175 | { |
| 13176 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 13177 | .doit = nl80211_crit_protocol_stop, |
| 13178 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13179 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13180 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 13181 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13182 | }, |
| 13183 | { |
| 13184 | .cmd = NL80211_CMD_GET_COALESCE, |
| 13185 | .doit = nl80211_get_coalesce, |
| 13186 | .policy = nl80211_policy, |
| 13187 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13188 | NL80211_FLAG_NEED_RTNL, |
| 13189 | }, |
| 13190 | { |
| 13191 | .cmd = NL80211_CMD_SET_COALESCE, |
| 13192 | .doit = nl80211_set_coalesce, |
| 13193 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13194 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13195 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13196 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13197 | }, |
| 13198 | { |
| 13199 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 13200 | .doit = nl80211_channel_switch, |
| 13201 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13202 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13203 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13204 | NL80211_FLAG_NEED_RTNL, |
| 13205 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13206 | { |
| 13207 | .cmd = NL80211_CMD_VENDOR, |
| 13208 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13209 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13210 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13211 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13212 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13213 | NL80211_FLAG_NEED_RTNL, |
| 13214 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13215 | { |
| 13216 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 13217 | .doit = nl80211_set_qos_map, |
| 13218 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13219 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13220 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13221 | NL80211_FLAG_NEED_RTNL, |
| 13222 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13223 | { |
| 13224 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 13225 | .doit = nl80211_add_tx_ts, |
| 13226 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13227 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13228 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13229 | NL80211_FLAG_NEED_RTNL, |
| 13230 | }, |
| 13231 | { |
| 13232 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 13233 | .doit = nl80211_del_tx_ts, |
| 13234 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13235 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13237 | NL80211_FLAG_NEED_RTNL, |
| 13238 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13239 | { |
| 13240 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 13241 | .doit = nl80211_tdls_channel_switch, |
| 13242 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13243 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13244 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13245 | NL80211_FLAG_NEED_RTNL, |
| 13246 | }, |
| 13247 | { |
| 13248 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 13249 | .doit = nl80211_tdls_cancel_channel_switch, |
| 13250 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13251 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13252 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13253 | NL80211_FLAG_NEED_RTNL, |
| 13254 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13255 | { |
| 13256 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 13257 | .doit = nl80211_set_multicast_to_unicast, |
| 13258 | .policy = nl80211_policy, |
| 13259 | .flags = GENL_UNS_ADMIN_PERM, |
| 13260 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13261 | NL80211_FLAG_NEED_RTNL, |
| 13262 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13263 | { |
| 13264 | .cmd = NL80211_CMD_SET_PMK, |
| 13265 | .doit = nl80211_set_pmk, |
| 13266 | .policy = nl80211_policy, |
| 13267 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13268 | NL80211_FLAG_NEED_RTNL, |
| 13269 | }, |
| 13270 | { |
| 13271 | .cmd = NL80211_CMD_DEL_PMK, |
| 13272 | .doit = nl80211_del_pmk, |
| 13273 | .policy = nl80211_policy, |
| 13274 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13275 | NL80211_FLAG_NEED_RTNL, |
| 13276 | }, |
| 13277 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13278 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13279 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 13280 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 13281 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 13282 | .hdrsize = 0, /* no private header */ |
| 13283 | .version = 1, /* no particular meaning now */ |
| 13284 | .maxattr = NL80211_ATTR_MAX, |
| 13285 | .netnsok = true, |
| 13286 | .pre_doit = nl80211_pre_doit, |
| 13287 | .post_doit = nl80211_post_doit, |
| 13288 | .module = THIS_MODULE, |
| 13289 | .ops = nl80211_ops, |
| 13290 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 13291 | .mcgrps = nl80211_mcgrps, |
| 13292 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 13293 | }; |
| 13294 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13295 | /* notification functions */ |
| 13296 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13297 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 13298 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13299 | { |
| 13300 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13301 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13302 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13303 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13304 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13305 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13306 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13307 | if (!msg) |
| 13308 | return; |
| 13309 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13310 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13311 | nlmsg_free(msg); |
| 13312 | return; |
| 13313 | } |
| 13314 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13315 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13316 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13317 | } |
| 13318 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13319 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13320 | struct wireless_dev *wdev, |
| 13321 | enum nl80211_commands cmd) |
| 13322 | { |
| 13323 | struct sk_buff *msg; |
| 13324 | |
| 13325 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13326 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13327 | |
| 13328 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13329 | if (!msg) |
| 13330 | return; |
| 13331 | |
| 13332 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13333 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13334 | nlmsg_free(msg); |
| 13335 | return; |
| 13336 | } |
| 13337 | |
| 13338 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13339 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13340 | } |
| 13341 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13342 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13343 | struct cfg80211_registered_device *rdev) |
| 13344 | { |
| 13345 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13346 | struct nlattr *nest; |
| 13347 | int i; |
| 13348 | |
| 13349 | if (WARN_ON(!req)) |
| 13350 | return 0; |
| 13351 | |
| 13352 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13353 | if (!nest) |
| 13354 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13355 | for (i = 0; i < req->n_ssids; i++) { |
| 13356 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13357 | goto nla_put_failure; |
| 13358 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13359 | nla_nest_end(msg, nest); |
| 13360 | |
| 13361 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13362 | if (!nest) |
| 13363 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13364 | for (i = 0; i < req->n_channels; i++) { |
| 13365 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13366 | goto nla_put_failure; |
| 13367 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13368 | nla_nest_end(msg, nest); |
| 13369 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13370 | if (req->ie && |
| 13371 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 13372 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13373 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13374 | if (req->flags && |
| 13375 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 13376 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 13377 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 13378 | if (req->info.scan_start_tsf && |
| 13379 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 13380 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 13381 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 13382 | req->info.tsf_bssid))) |
| 13383 | goto nla_put_failure; |
| 13384 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13385 | return 0; |
| 13386 | nla_put_failure: |
| 13387 | return -ENOBUFS; |
| 13388 | } |
| 13389 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13390 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13391 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13392 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13393 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13394 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13395 | { |
| 13396 | void *hdr; |
| 13397 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13398 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13399 | if (!hdr) |
| 13400 | return -1; |
| 13401 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13402 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13403 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13404 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13405 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13406 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13407 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13408 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13409 | /* ignore errors and send incomplete event anyway */ |
| 13410 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13411 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13412 | genlmsg_end(msg, hdr); |
| 13413 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13414 | |
| 13415 | nla_put_failure: |
| 13416 | genlmsg_cancel(msg, hdr); |
| 13417 | return -EMSGSIZE; |
| 13418 | } |
| 13419 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13420 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13421 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13422 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13423 | { |
| 13424 | void *hdr; |
| 13425 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13426 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13427 | if (!hdr) |
| 13428 | return -1; |
| 13429 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13430 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 13431 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 13432 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 13433 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 13434 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13435 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13436 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13437 | genlmsg_end(msg, hdr); |
| 13438 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13439 | |
| 13440 | nla_put_failure: |
| 13441 | genlmsg_cancel(msg, hdr); |
| 13442 | return -EMSGSIZE; |
| 13443 | } |
| 13444 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13445 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13446 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13447 | { |
| 13448 | struct sk_buff *msg; |
| 13449 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13450 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13451 | if (!msg) |
| 13452 | return; |
| 13453 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13454 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13455 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 13456 | nlmsg_free(msg); |
| 13457 | return; |
| 13458 | } |
| 13459 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13460 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13461 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13462 | } |
| 13463 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13464 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 13465 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13466 | { |
| 13467 | struct sk_buff *msg; |
| 13468 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13469 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13470 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13471 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13472 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13473 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13474 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 13475 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13476 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13477 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13478 | } |
| 13479 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13480 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13481 | } |
| 13482 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13483 | /* send message created by nl80211_build_scan_msg() */ |
| 13484 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 13485 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13486 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13487 | if (!msg) |
| 13488 | return; |
| 13489 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13490 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13491 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13492 | } |
| 13493 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13494 | 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] | 13495 | { |
| 13496 | struct sk_buff *msg; |
| 13497 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13498 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13499 | if (!msg) |
| 13500 | return; |
| 13501 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13502 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13503 | nlmsg_free(msg); |
| 13504 | return; |
| 13505 | } |
| 13506 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13507 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13508 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13509 | } |
| 13510 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13511 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 13512 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13513 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13514 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13515 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 13516 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13517 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13518 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 13519 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13520 | NL80211_REGDOM_TYPE_WORLD)) |
| 13521 | goto nla_put_failure; |
| 13522 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 13523 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13524 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 13525 | goto nla_put_failure; |
| 13526 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 13527 | request->intersect) { |
| 13528 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13529 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 13530 | goto nla_put_failure; |
| 13531 | } else { |
| 13532 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13533 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 13534 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 13535 | request->alpha2)) |
| 13536 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13537 | } |
| 13538 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13539 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 13540 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 13541 | |
| 13542 | if (wiphy && |
| 13543 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 13544 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 13545 | |
| 13546 | if (wiphy && |
| 13547 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 13548 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 13549 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13550 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13551 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13552 | return true; |
| 13553 | |
| 13554 | nla_put_failure: |
| 13555 | return false; |
| 13556 | } |
| 13557 | |
| 13558 | /* |
| 13559 | * This can happen on global regulatory changes or device specific settings |
| 13560 | * based on custom regulatory domains. |
| 13561 | */ |
| 13562 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13563 | struct regulatory_request *request) |
| 13564 | { |
| 13565 | struct sk_buff *msg; |
| 13566 | void *hdr; |
| 13567 | |
| 13568 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13569 | if (!msg) |
| 13570 | return; |
| 13571 | |
| 13572 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13573 | if (!hdr) { |
| 13574 | nlmsg_free(msg); |
| 13575 | return; |
| 13576 | } |
| 13577 | |
| 13578 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13579 | goto nla_put_failure; |
| 13580 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13581 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13582 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13583 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13584 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13585 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13586 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13587 | |
| 13588 | return; |
| 13589 | |
| 13590 | nla_put_failure: |
| 13591 | genlmsg_cancel(msg, hdr); |
| 13592 | nlmsg_free(msg); |
| 13593 | } |
| 13594 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13595 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13596 | struct net_device *netdev, |
| 13597 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13598 | enum nl80211_commands cmd, gfp_t gfp, |
| 13599 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13600 | { |
| 13601 | struct sk_buff *msg; |
| 13602 | void *hdr; |
| 13603 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13604 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13605 | if (!msg) |
| 13606 | return; |
| 13607 | |
| 13608 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13609 | if (!hdr) { |
| 13610 | nlmsg_free(msg); |
| 13611 | return; |
| 13612 | } |
| 13613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13616 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13617 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13618 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13619 | if (uapsd_queues >= 0) { |
| 13620 | struct nlattr *nla_wmm = |
| 13621 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13622 | if (!nla_wmm) |
| 13623 | goto nla_put_failure; |
| 13624 | |
| 13625 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13626 | uapsd_queues)) |
| 13627 | goto nla_put_failure; |
| 13628 | |
| 13629 | nla_nest_end(msg, nla_wmm); |
| 13630 | } |
| 13631 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13632 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13633 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13634 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13635 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13636 | return; |
| 13637 | |
| 13638 | nla_put_failure: |
| 13639 | genlmsg_cancel(msg, hdr); |
| 13640 | nlmsg_free(msg); |
| 13641 | } |
| 13642 | |
| 13643 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13644 | struct net_device *netdev, const u8 *buf, |
| 13645 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13646 | { |
| 13647 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13648 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13649 | } |
| 13650 | |
| 13651 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13652 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13653 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13654 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13655 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13656 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13657 | } |
| 13658 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13659 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13660 | struct net_device *netdev, const u8 *buf, |
| 13661 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13662 | { |
| 13663 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13664 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13665 | } |
| 13666 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13667 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13668 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13669 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13670 | { |
| 13671 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13672 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13673 | } |
| 13674 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13675 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13676 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13677 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13679 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13680 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13681 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13682 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13683 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13684 | if (WARN_ON(len < 2)) |
| 13685 | return; |
| 13686 | |
| 13687 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13688 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13689 | else |
| 13690 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13691 | |
| 13692 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13693 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13694 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13695 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13696 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13697 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13698 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13699 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13700 | { |
| 13701 | struct sk_buff *msg; |
| 13702 | void *hdr; |
| 13703 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13705 | if (!msg) |
| 13706 | return; |
| 13707 | |
| 13708 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13709 | if (!hdr) { |
| 13710 | nlmsg_free(msg); |
| 13711 | return; |
| 13712 | } |
| 13713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13716 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13718 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13719 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13720 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13721 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13722 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13723 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13724 | return; |
| 13725 | |
| 13726 | nla_put_failure: |
| 13727 | genlmsg_cancel(msg, hdr); |
| 13728 | nlmsg_free(msg); |
| 13729 | } |
| 13730 | |
| 13731 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13732 | struct net_device *netdev, const u8 *addr, |
| 13733 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13734 | { |
| 13735 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13736 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13737 | } |
| 13738 | |
| 13739 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13740 | struct net_device *netdev, const u8 *addr, |
| 13741 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13742 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13743 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13744 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13745 | } |
| 13746 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13747 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13748 | struct net_device *netdev, |
| 13749 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13750 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13751 | { |
| 13752 | struct sk_buff *msg; |
| 13753 | void *hdr; |
| 13754 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13755 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 13756 | cr->fils_kek_len + cr->pmk_len + |
| 13757 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13758 | if (!msg) |
| 13759 | return; |
| 13760 | |
| 13761 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13762 | if (!hdr) { |
| 13763 | nlmsg_free(msg); |
| 13764 | return; |
| 13765 | } |
| 13766 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13767 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13768 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13769 | (cr->bssid && |
| 13770 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13771 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13772 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13773 | cr->status) || |
| 13774 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13775 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13776 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 13777 | cr->timeout_reason))) || |
| 13778 | (cr->req_ie && |
| 13779 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 13780 | (cr->resp_ie && |
| 13781 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13782 | cr->resp_ie)) || |
| 13783 | (cr->update_erp_next_seq_num && |
| 13784 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 13785 | cr->fils_erp_next_seq_num)) || |
| 13786 | (cr->status == WLAN_STATUS_SUCCESS && |
| 13787 | ((cr->fils_kek && |
| 13788 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, |
| 13789 | cr->fils_kek)) || |
| 13790 | (cr->pmk && |
| 13791 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || |
| 13792 | (cr->pmkid && |
| 13793 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13794 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13795 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13796 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13797 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13798 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13799 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13800 | return; |
| 13801 | |
| 13802 | nla_put_failure: |
| 13803 | genlmsg_cancel(msg, hdr); |
| 13804 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13805 | } |
| 13806 | |
| 13807 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13808 | struct net_device *netdev, |
| 13809 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13810 | { |
| 13811 | struct sk_buff *msg; |
| 13812 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13813 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13814 | |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13815 | 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] | 13816 | if (!msg) |
| 13817 | return; |
| 13818 | |
| 13819 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13820 | if (!hdr) { |
| 13821 | nlmsg_free(msg); |
| 13822 | return; |
| 13823 | } |
| 13824 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13825 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13826 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13827 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13828 | (info->req_ie && |
| 13829 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 13830 | info->req_ie)) || |
| 13831 | (info->resp_ie && |
| 13832 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame^] | 13833 | info->resp_ie))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13834 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13835 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13836 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13837 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13838 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13839 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13840 | return; |
| 13841 | |
| 13842 | nla_put_failure: |
| 13843 | genlmsg_cancel(msg, hdr); |
| 13844 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13845 | } |
| 13846 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame^] | 13847 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 13848 | struct net_device *netdev, const u8 *bssid) |
| 13849 | { |
| 13850 | struct sk_buff *msg; |
| 13851 | void *hdr; |
| 13852 | |
| 13853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13854 | if (!msg) |
| 13855 | return; |
| 13856 | |
| 13857 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 13858 | if (!hdr) { |
| 13859 | nlmsg_free(msg); |
| 13860 | return; |
| 13861 | } |
| 13862 | |
| 13863 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13864 | goto nla_put_failure; |
| 13865 | |
| 13866 | genlmsg_end(msg, hdr); |
| 13867 | |
| 13868 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13869 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13870 | return; |
| 13871 | |
| 13872 | nla_put_failure: |
| 13873 | genlmsg_cancel(msg, hdr); |
| 13874 | nlmsg_free(msg); |
| 13875 | } |
| 13876 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13877 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13878 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13879 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13880 | { |
| 13881 | struct sk_buff *msg; |
| 13882 | void *hdr; |
| 13883 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13884 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13885 | if (!msg) |
| 13886 | return; |
| 13887 | |
| 13888 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13889 | if (!hdr) { |
| 13890 | nlmsg_free(msg); |
| 13891 | return; |
| 13892 | } |
| 13893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13895 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13896 | (from_ap && reason && |
| 13897 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13898 | (from_ap && |
| 13899 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13900 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13901 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13902 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13903 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13904 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13905 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13906 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13907 | return; |
| 13908 | |
| 13909 | nla_put_failure: |
| 13910 | genlmsg_cancel(msg, hdr); |
| 13911 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13912 | } |
| 13913 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13914 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13915 | struct net_device *netdev, const u8 *bssid, |
| 13916 | gfp_t gfp) |
| 13917 | { |
| 13918 | struct sk_buff *msg; |
| 13919 | void *hdr; |
| 13920 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13922 | if (!msg) |
| 13923 | return; |
| 13924 | |
| 13925 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13926 | if (!hdr) { |
| 13927 | nlmsg_free(msg); |
| 13928 | return; |
| 13929 | } |
| 13930 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13931 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13932 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13933 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13934 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13935 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13936 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13937 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13938 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13939 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13940 | return; |
| 13941 | |
| 13942 | nla_put_failure: |
| 13943 | genlmsg_cancel(msg, hdr); |
| 13944 | nlmsg_free(msg); |
| 13945 | } |
| 13946 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13947 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13948 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13949 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13950 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13951 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13952 | struct sk_buff *msg; |
| 13953 | void *hdr; |
| 13954 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13955 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13956 | return; |
| 13957 | |
| 13958 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13959 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13960 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13961 | if (!msg) |
| 13962 | return; |
| 13963 | |
| 13964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13965 | if (!hdr) { |
| 13966 | nlmsg_free(msg); |
| 13967 | return; |
| 13968 | } |
| 13969 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13970 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13971 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13972 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13973 | (ie_len && ie && |
| 13974 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13975 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13976 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13977 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13978 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13979 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13980 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13981 | return; |
| 13982 | |
| 13983 | nla_put_failure: |
| 13984 | genlmsg_cancel(msg, hdr); |
| 13985 | nlmsg_free(msg); |
| 13986 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13987 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13988 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13989 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13990 | struct net_device *netdev, const u8 *addr, |
| 13991 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13992 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13993 | { |
| 13994 | struct sk_buff *msg; |
| 13995 | void *hdr; |
| 13996 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13998 | if (!msg) |
| 13999 | return; |
| 14000 | |
| 14001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 14002 | if (!hdr) { |
| 14003 | nlmsg_free(msg); |
| 14004 | return; |
| 14005 | } |
| 14006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14009 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 14010 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 14011 | (key_id != -1 && |
| 14012 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 14013 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 14014 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14015 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14016 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14017 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14018 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14019 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 14020 | return; |
| 14021 | |
| 14022 | nla_put_failure: |
| 14023 | genlmsg_cancel(msg, hdr); |
| 14024 | nlmsg_free(msg); |
| 14025 | } |
| 14026 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14027 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 14028 | struct ieee80211_channel *channel_before, |
| 14029 | struct ieee80211_channel *channel_after) |
| 14030 | { |
| 14031 | struct sk_buff *msg; |
| 14032 | void *hdr; |
| 14033 | struct nlattr *nl_freq; |
| 14034 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 14035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14036 | if (!msg) |
| 14037 | return; |
| 14038 | |
| 14039 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 14040 | if (!hdr) { |
| 14041 | nlmsg_free(msg); |
| 14042 | return; |
| 14043 | } |
| 14044 | |
| 14045 | /* |
| 14046 | * Since we are applying the beacon hint to a wiphy we know its |
| 14047 | * wiphy_idx is valid |
| 14048 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14049 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 14050 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14051 | |
| 14052 | /* Before */ |
| 14053 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 14054 | if (!nl_freq) |
| 14055 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 14056 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14057 | goto nla_put_failure; |
| 14058 | nla_nest_end(msg, nl_freq); |
| 14059 | |
| 14060 | /* After */ |
| 14061 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 14062 | if (!nl_freq) |
| 14063 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 14064 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14065 | goto nla_put_failure; |
| 14066 | nla_nest_end(msg, nl_freq); |
| 14067 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14068 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14069 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14070 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14071 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14072 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14073 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 14074 | |
| 14075 | return; |
| 14076 | |
| 14077 | nla_put_failure: |
| 14078 | genlmsg_cancel(msg, hdr); |
| 14079 | nlmsg_free(msg); |
| 14080 | } |
| 14081 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14082 | static void nl80211_send_remain_on_chan_event( |
| 14083 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14084 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14085 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14086 | unsigned int duration, gfp_t gfp) |
| 14087 | { |
| 14088 | struct sk_buff *msg; |
| 14089 | void *hdr; |
| 14090 | |
| 14091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14092 | if (!msg) |
| 14093 | return; |
| 14094 | |
| 14095 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 14096 | if (!hdr) { |
| 14097 | nlmsg_free(msg); |
| 14098 | return; |
| 14099 | } |
| 14100 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14101 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14102 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14103 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14104 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14105 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14106 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14107 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 14108 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14109 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14110 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14111 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14113 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 14114 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 14115 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14116 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14117 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14118 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14119 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14120 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14121 | return; |
| 14122 | |
| 14123 | nla_put_failure: |
| 14124 | genlmsg_cancel(msg, hdr); |
| 14125 | nlmsg_free(msg); |
| 14126 | } |
| 14127 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14128 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 14129 | struct ieee80211_channel *chan, |
| 14130 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14131 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14132 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14133 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14134 | |
| 14135 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14136 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14137 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14138 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14139 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14140 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14141 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14142 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 14143 | struct ieee80211_channel *chan, |
| 14144 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14145 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14146 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14147 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14148 | |
| 14149 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14150 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 14151 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14152 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14153 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14154 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14155 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 14156 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14157 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14158 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14159 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14160 | struct sk_buff *msg; |
| 14161 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14162 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 14163 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14164 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14165 | if (!msg) |
| 14166 | return; |
| 14167 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14168 | 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] | 14169 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14170 | nlmsg_free(msg); |
| 14171 | return; |
| 14172 | } |
| 14173 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14174 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14175 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14176 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14177 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 14178 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14179 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 14180 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14181 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14182 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14183 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14184 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14185 | struct station_info empty_sinfo = {}; |
| 14186 | |
| 14187 | if (!sinfo) |
| 14188 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14189 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14190 | trace_cfg80211_del_sta(dev, mac_addr); |
| 14191 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14192 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14193 | if (!msg) |
| 14194 | return; |
| 14195 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14196 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 14197 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14198 | nlmsg_free(msg); |
| 14199 | return; |
| 14200 | } |
| 14201 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14203 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14204 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 14205 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 14206 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14207 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 14208 | enum nl80211_connect_failed_reason reason, |
| 14209 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14210 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14211 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14212 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14213 | struct sk_buff *msg; |
| 14214 | void *hdr; |
| 14215 | |
| 14216 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 14217 | if (!msg) |
| 14218 | return; |
| 14219 | |
| 14220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 14221 | if (!hdr) { |
| 14222 | nlmsg_free(msg); |
| 14223 | return; |
| 14224 | } |
| 14225 | |
| 14226 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14227 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 14228 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 14229 | goto nla_put_failure; |
| 14230 | |
| 14231 | genlmsg_end(msg, hdr); |
| 14232 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14233 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14234 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14235 | return; |
| 14236 | |
| 14237 | nla_put_failure: |
| 14238 | genlmsg_cancel(msg, hdr); |
| 14239 | nlmsg_free(msg); |
| 14240 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14241 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14242 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14243 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 14244 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14245 | { |
| 14246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14247 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14248 | struct sk_buff *msg; |
| 14249 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14250 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14251 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14252 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14253 | return false; |
| 14254 | |
| 14255 | msg = nlmsg_new(100, gfp); |
| 14256 | if (!msg) |
| 14257 | return true; |
| 14258 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14259 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14260 | if (!hdr) { |
| 14261 | nlmsg_free(msg); |
| 14262 | return true; |
| 14263 | } |
| 14264 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14265 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14266 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14267 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14268 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14269 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14270 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14271 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14272 | return true; |
| 14273 | |
| 14274 | nla_put_failure: |
| 14275 | genlmsg_cancel(msg, hdr); |
| 14276 | nlmsg_free(msg); |
| 14277 | return true; |
| 14278 | } |
| 14279 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14280 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 14281 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14282 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14283 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14284 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14285 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14286 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 14287 | |
| 14288 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14289 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 14290 | trace_cfg80211_return_bool(false); |
| 14291 | return false; |
| 14292 | } |
| 14293 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 14294 | addr, gfp); |
| 14295 | trace_cfg80211_return_bool(ret); |
| 14296 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14297 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14298 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 14299 | |
| 14300 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 14301 | const u8 *addr, gfp_t gfp) |
| 14302 | { |
| 14303 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14304 | bool ret; |
| 14305 | |
| 14306 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 14307 | |
| 14308 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14309 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 14310 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 14311 | trace_cfg80211_return_bool(false); |
| 14312 | return false; |
| 14313 | } |
| 14314 | ret = __nl80211_unexpected_frame(dev, |
| 14315 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14316 | addr, gfp); |
| 14317 | trace_cfg80211_return_bool(ret); |
| 14318 | return ret; |
| 14319 | } |
| 14320 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14321 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14322 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14323 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14324 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14325 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14326 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14327 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14328 | struct sk_buff *msg; |
| 14329 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14330 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14331 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14332 | if (!msg) |
| 14333 | return -ENOMEM; |
| 14334 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14336 | if (!hdr) { |
| 14337 | nlmsg_free(msg); |
| 14338 | return -ENOMEM; |
| 14339 | } |
| 14340 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14341 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14342 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14343 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14344 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14345 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14346 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14347 | (sig_dbm && |
| 14348 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14349 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14350 | (flags && |
| 14351 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14352 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14353 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14354 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14355 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14356 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14357 | |
| 14358 | nla_put_failure: |
| 14359 | genlmsg_cancel(msg, hdr); |
| 14360 | nlmsg_free(msg); |
| 14361 | return -ENOBUFS; |
| 14362 | } |
| 14363 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14364 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14365 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14366 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14367 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14368 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14369 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14370 | struct sk_buff *msg; |
| 14371 | void *hdr; |
| 14372 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14373 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 14374 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14375 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14376 | if (!msg) |
| 14377 | return; |
| 14378 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14379 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14380 | if (!hdr) { |
| 14381 | nlmsg_free(msg); |
| 14382 | return; |
| 14383 | } |
| 14384 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14385 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14386 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14387 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14388 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14389 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14390 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14391 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14392 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14393 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14394 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14395 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14396 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14397 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14398 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14399 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14400 | return; |
| 14401 | |
| 14402 | nla_put_failure: |
| 14403 | genlmsg_cancel(msg, hdr); |
| 14404 | nlmsg_free(msg); |
| 14405 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14406 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14407 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14408 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 14409 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14410 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14411 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14412 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14413 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14414 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14415 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14416 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14417 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14418 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14419 | cb = (void **)msg->cb; |
| 14420 | |
| 14421 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 14422 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14423 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14424 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14425 | } |
| 14426 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14427 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14428 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14429 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14430 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14431 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14432 | goto nla_put_failure; |
| 14433 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14434 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 14435 | if (!cb[1]) |
| 14436 | goto nla_put_failure; |
| 14437 | |
| 14438 | cb[2] = rdev; |
| 14439 | |
| 14440 | return msg; |
| 14441 | nla_put_failure: |
| 14442 | nlmsg_free(msg); |
| 14443 | return NULL; |
| 14444 | } |
| 14445 | |
| 14446 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 14447 | { |
| 14448 | void **cb = (void **)msg->cb; |
| 14449 | struct cfg80211_registered_device *rdev = cb[2]; |
| 14450 | |
| 14451 | nla_nest_end(msg, cb[1]); |
| 14452 | genlmsg_end(msg, cb[0]); |
| 14453 | |
| 14454 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 14455 | |
| 14456 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14457 | NL80211_MCGRP_MLME, gfp); |
| 14458 | } |
| 14459 | |
| 14460 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 14461 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14462 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14463 | { |
| 14464 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14465 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14467 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14468 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14469 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14470 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 14471 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 14472 | return; |
| 14473 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14474 | if (wdev->cqm_config) { |
| 14475 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 14476 | |
| 14477 | cfg80211_cqm_rssi_update(rdev, dev); |
| 14478 | |
| 14479 | if (rssi_level == 0) |
| 14480 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 14481 | } |
| 14482 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14483 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14484 | if (!msg) |
| 14485 | return; |
| 14486 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14487 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 14488 | rssi_event)) |
| 14489 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14490 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14491 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 14492 | rssi_level)) |
| 14493 | goto nla_put_failure; |
| 14494 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14495 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14496 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14497 | return; |
| 14498 | |
| 14499 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14500 | nlmsg_free(msg); |
| 14501 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14502 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14503 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14504 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 14505 | const u8 *peer, u32 num_packets, |
| 14506 | u32 rate, u32 intvl, gfp_t gfp) |
| 14507 | { |
| 14508 | struct sk_buff *msg; |
| 14509 | |
| 14510 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14511 | if (!msg) |
| 14512 | return; |
| 14513 | |
| 14514 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 14515 | goto nla_put_failure; |
| 14516 | |
| 14517 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 14518 | goto nla_put_failure; |
| 14519 | |
| 14520 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 14521 | goto nla_put_failure; |
| 14522 | |
| 14523 | cfg80211_send_cqm(msg, gfp); |
| 14524 | return; |
| 14525 | |
| 14526 | nla_put_failure: |
| 14527 | nlmsg_free(msg); |
| 14528 | } |
| 14529 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 14530 | |
| 14531 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 14532 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 14533 | { |
| 14534 | struct sk_buff *msg; |
| 14535 | |
| 14536 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 14537 | |
| 14538 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14539 | if (!msg) |
| 14540 | return; |
| 14541 | |
| 14542 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 14543 | goto nla_put_failure; |
| 14544 | |
| 14545 | cfg80211_send_cqm(msg, gfp); |
| 14546 | return; |
| 14547 | |
| 14548 | nla_put_failure: |
| 14549 | nlmsg_free(msg); |
| 14550 | } |
| 14551 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 14552 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14553 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 14554 | { |
| 14555 | struct sk_buff *msg; |
| 14556 | |
| 14557 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14558 | if (!msg) |
| 14559 | return; |
| 14560 | |
| 14561 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 14562 | goto nla_put_failure; |
| 14563 | |
| 14564 | cfg80211_send_cqm(msg, gfp); |
| 14565 | return; |
| 14566 | |
| 14567 | nla_put_failure: |
| 14568 | nlmsg_free(msg); |
| 14569 | } |
| 14570 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 14571 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14572 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 14573 | struct net_device *netdev, const u8 *bssid, |
| 14574 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14575 | { |
| 14576 | struct sk_buff *msg; |
| 14577 | struct nlattr *rekey_attr; |
| 14578 | void *hdr; |
| 14579 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14581 | if (!msg) |
| 14582 | return; |
| 14583 | |
| 14584 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 14585 | if (!hdr) { |
| 14586 | nlmsg_free(msg); |
| 14587 | return; |
| 14588 | } |
| 14589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14590 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14591 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14592 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14593 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14594 | |
| 14595 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 14596 | if (!rekey_attr) |
| 14597 | goto nla_put_failure; |
| 14598 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14599 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 14600 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 14601 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14602 | |
| 14603 | nla_nest_end(msg, rekey_attr); |
| 14604 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14605 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14606 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14607 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14608 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14609 | return; |
| 14610 | |
| 14611 | nla_put_failure: |
| 14612 | genlmsg_cancel(msg, hdr); |
| 14613 | nlmsg_free(msg); |
| 14614 | } |
| 14615 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14616 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 14617 | const u8 *replay_ctr, gfp_t gfp) |
| 14618 | { |
| 14619 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14620 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14622 | |
| 14623 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14624 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14625 | } |
| 14626 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14627 | |
| 14628 | static void |
| 14629 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14630 | struct net_device *netdev, int index, |
| 14631 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14632 | { |
| 14633 | struct sk_buff *msg; |
| 14634 | struct nlattr *attr; |
| 14635 | void *hdr; |
| 14636 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14638 | if (!msg) |
| 14639 | return; |
| 14640 | |
| 14641 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14642 | if (!hdr) { |
| 14643 | nlmsg_free(msg); |
| 14644 | return; |
| 14645 | } |
| 14646 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14647 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14648 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14649 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14650 | |
| 14651 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14652 | if (!attr) |
| 14653 | goto nla_put_failure; |
| 14654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14655 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14656 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14657 | (preauth && |
| 14658 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14659 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14660 | |
| 14661 | nla_nest_end(msg, attr); |
| 14662 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14663 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14664 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14665 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14666 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14667 | return; |
| 14668 | |
| 14669 | nla_put_failure: |
| 14670 | genlmsg_cancel(msg, hdr); |
| 14671 | nlmsg_free(msg); |
| 14672 | } |
| 14673 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14674 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14675 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14676 | { |
| 14677 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14678 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14680 | |
| 14681 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14682 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14683 | } |
| 14684 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14685 | |
| 14686 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14687 | struct net_device *netdev, |
| 14688 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14689 | gfp_t gfp, |
| 14690 | enum nl80211_commands notif, |
| 14691 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14692 | { |
| 14693 | struct sk_buff *msg; |
| 14694 | void *hdr; |
| 14695 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14697 | if (!msg) |
| 14698 | return; |
| 14699 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14700 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14701 | if (!hdr) { |
| 14702 | nlmsg_free(msg); |
| 14703 | return; |
| 14704 | } |
| 14705 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14706 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14707 | goto nla_put_failure; |
| 14708 | |
| 14709 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14710 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14711 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14712 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14713 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14714 | goto nla_put_failure; |
| 14715 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14716 | genlmsg_end(msg, hdr); |
| 14717 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14718 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14719 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14720 | return; |
| 14721 | |
| 14722 | nla_put_failure: |
| 14723 | genlmsg_cancel(msg, hdr); |
| 14724 | nlmsg_free(msg); |
| 14725 | } |
| 14726 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14727 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14728 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14729 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14730 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14731 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14732 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14733 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14734 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14735 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14736 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14737 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14738 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14739 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14740 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14741 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14742 | } |
| 14743 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14744 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14745 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14746 | struct cfg80211_chan_def *chandef, |
| 14747 | u8 count) |
| 14748 | { |
| 14749 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14750 | struct wiphy *wiphy = wdev->wiphy; |
| 14751 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14752 | |
| 14753 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14754 | |
| 14755 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14756 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14757 | } |
| 14758 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14759 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14760 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14761 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14762 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14763 | enum nl80211_radar_event event, |
| 14764 | struct net_device *netdev, gfp_t gfp) |
| 14765 | { |
| 14766 | struct sk_buff *msg; |
| 14767 | void *hdr; |
| 14768 | |
| 14769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14770 | if (!msg) |
| 14771 | return; |
| 14772 | |
| 14773 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14774 | if (!hdr) { |
| 14775 | nlmsg_free(msg); |
| 14776 | return; |
| 14777 | } |
| 14778 | |
| 14779 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14780 | goto nla_put_failure; |
| 14781 | |
| 14782 | /* NOP and radar events don't need a netdev parameter */ |
| 14783 | if (netdev) { |
| 14784 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14785 | |
| 14786 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14787 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14788 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14789 | goto nla_put_failure; |
| 14790 | } |
| 14791 | |
| 14792 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14793 | goto nla_put_failure; |
| 14794 | |
| 14795 | if (nl80211_send_chandef(msg, chandef)) |
| 14796 | goto nla_put_failure; |
| 14797 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14798 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14799 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14800 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14801 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14802 | return; |
| 14803 | |
| 14804 | nla_put_failure: |
| 14805 | genlmsg_cancel(msg, hdr); |
| 14806 | nlmsg_free(msg); |
| 14807 | } |
| 14808 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14809 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14810 | u64 cookie, bool acked, gfp_t gfp) |
| 14811 | { |
| 14812 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14813 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14814 | struct sk_buff *msg; |
| 14815 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14816 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14817 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14818 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14819 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14820 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14821 | if (!msg) |
| 14822 | return; |
| 14823 | |
| 14824 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14825 | if (!hdr) { |
| 14826 | nlmsg_free(msg); |
| 14827 | return; |
| 14828 | } |
| 14829 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14830 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14831 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14832 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14833 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14834 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14835 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14836 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14837 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14838 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14839 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14840 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14841 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14842 | return; |
| 14843 | |
| 14844 | nla_put_failure: |
| 14845 | genlmsg_cancel(msg, hdr); |
| 14846 | nlmsg_free(msg); |
| 14847 | } |
| 14848 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14849 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14850 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14851 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14852 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14853 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14854 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14855 | struct sk_buff *msg; |
| 14856 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14857 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14858 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14859 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14860 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14861 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14862 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14863 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14864 | if (!msg) { |
| 14865 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14866 | return; |
| 14867 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14868 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14869 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14870 | if (!hdr) |
| 14871 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14872 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14873 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14874 | (freq && |
| 14875 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14876 | (sig_dbm && |
| 14877 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14878 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14879 | goto nla_put_failure; |
| 14880 | |
| 14881 | genlmsg_end(msg, hdr); |
| 14882 | |
| 14883 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14884 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14885 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14886 | return; |
| 14887 | |
| 14888 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14889 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14890 | if (hdr) |
| 14891 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14892 | nlmsg_free(msg); |
| 14893 | } |
| 14894 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14895 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14896 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14897 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14898 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14899 | { |
| 14900 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14901 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14902 | int i, j; |
| 14903 | |
| 14904 | nl_results = nla_nest_start( |
| 14905 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14906 | if (!nl_results) |
| 14907 | return -EMSGSIZE; |
| 14908 | |
| 14909 | for (i = 0; i < nd->n_matches; i++) { |
| 14910 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14911 | |
| 14912 | nl_match = nla_nest_start(msg, i); |
| 14913 | if (!nl_match) |
| 14914 | break; |
| 14915 | |
| 14916 | /* The SSID attribute is optional in nl80211, but for |
| 14917 | * simplicity reasons it's always present in the |
| 14918 | * cfg80211 structure. If a driver can't pass the |
| 14919 | * SSID, that needs to be changed. A zero length SSID |
| 14920 | * is still a valid SSID (wildcard), so it cannot be |
| 14921 | * used for this purpose. |
| 14922 | */ |
| 14923 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14924 | match->ssid.ssid)) { |
| 14925 | nla_nest_cancel(msg, nl_match); |
| 14926 | goto out; |
| 14927 | } |
| 14928 | |
| 14929 | if (match->n_channels) { |
| 14930 | nl_freqs = nla_nest_start( |
| 14931 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14932 | if (!nl_freqs) { |
| 14933 | nla_nest_cancel(msg, nl_match); |
| 14934 | goto out; |
| 14935 | } |
| 14936 | |
| 14937 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14938 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14939 | nla_nest_cancel(msg, nl_freqs); |
| 14940 | nla_nest_cancel(msg, nl_match); |
| 14941 | goto out; |
| 14942 | } |
| 14943 | } |
| 14944 | |
| 14945 | nla_nest_end(msg, nl_freqs); |
| 14946 | } |
| 14947 | |
| 14948 | nla_nest_end(msg, nl_match); |
| 14949 | } |
| 14950 | |
| 14951 | out: |
| 14952 | nla_nest_end(msg, nl_results); |
| 14953 | return 0; |
| 14954 | } |
| 14955 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14956 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14957 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14958 | gfp_t gfp) |
| 14959 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14960 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14961 | struct sk_buff *msg; |
| 14962 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14963 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14964 | |
| 14965 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14966 | |
| 14967 | if (wakeup) |
| 14968 | size += wakeup->packet_present_len; |
| 14969 | |
| 14970 | msg = nlmsg_new(size, gfp); |
| 14971 | if (!msg) |
| 14972 | return; |
| 14973 | |
| 14974 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14975 | if (!hdr) |
| 14976 | goto free_msg; |
| 14977 | |
| 14978 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14979 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14980 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14981 | goto free_msg; |
| 14982 | |
| 14983 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14984 | wdev->netdev->ifindex)) |
| 14985 | goto free_msg; |
| 14986 | |
| 14987 | if (wakeup) { |
| 14988 | struct nlattr *reasons; |
| 14989 | |
| 14990 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14991 | if (!reasons) |
| 14992 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14993 | |
| 14994 | if (wakeup->disconnect && |
| 14995 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14996 | goto free_msg; |
| 14997 | if (wakeup->magic_pkt && |
| 14998 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14999 | goto free_msg; |
| 15000 | if (wakeup->gtk_rekey_failure && |
| 15001 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 15002 | goto free_msg; |
| 15003 | if (wakeup->eap_identity_req && |
| 15004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 15005 | goto free_msg; |
| 15006 | if (wakeup->four_way_handshake && |
| 15007 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 15008 | goto free_msg; |
| 15009 | if (wakeup->rfkill_release && |
| 15010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 15011 | goto free_msg; |
| 15012 | |
| 15013 | if (wakeup->pattern_idx >= 0 && |
| 15014 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 15015 | wakeup->pattern_idx)) |
| 15016 | goto free_msg; |
| 15017 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15018 | if (wakeup->tcp_match && |
| 15019 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 15020 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15021 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15022 | if (wakeup->tcp_connlost && |
| 15023 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 15024 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15025 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15026 | if (wakeup->tcp_nomoretokens && |
| 15027 | nla_put_flag(msg, |
| 15028 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 15029 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 15030 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15031 | if (wakeup->packet) { |
| 15032 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 15033 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 15034 | |
| 15035 | if (!wakeup->packet_80211) { |
| 15036 | pkt_attr = |
| 15037 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 15038 | len_attr = |
| 15039 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 15040 | } |
| 15041 | |
| 15042 | if (wakeup->packet_len && |
| 15043 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 15044 | goto free_msg; |
| 15045 | |
| 15046 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 15047 | wakeup->packet)) |
| 15048 | goto free_msg; |
| 15049 | } |
| 15050 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 15051 | if (wakeup->net_detect && |
| 15052 | cfg80211_net_detect_results(msg, wakeup)) |
| 15053 | goto free_msg; |
| 15054 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15055 | nla_nest_end(msg, reasons); |
| 15056 | } |
| 15057 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15058 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15059 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15060 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15061 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 15062 | return; |
| 15063 | |
| 15064 | free_msg: |
| 15065 | nlmsg_free(msg); |
| 15066 | } |
| 15067 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 15068 | #endif |
| 15069 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15070 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 15071 | enum nl80211_tdls_operation oper, |
| 15072 | u16 reason_code, gfp_t gfp) |
| 15073 | { |
| 15074 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15075 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15076 | struct sk_buff *msg; |
| 15077 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15078 | |
| 15079 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 15080 | reason_code); |
| 15081 | |
| 15082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15083 | if (!msg) |
| 15084 | return; |
| 15085 | |
| 15086 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 15087 | if (!hdr) { |
| 15088 | nlmsg_free(msg); |
| 15089 | return; |
| 15090 | } |
| 15091 | |
| 15092 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15093 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15094 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 15095 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 15096 | (reason_code > 0 && |
| 15097 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 15098 | goto nla_put_failure; |
| 15099 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15100 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15101 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15102 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15103 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 15104 | return; |
| 15105 | |
| 15106 | nla_put_failure: |
| 15107 | genlmsg_cancel(msg, hdr); |
| 15108 | nlmsg_free(msg); |
| 15109 | } |
| 15110 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 15111 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15112 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 15113 | unsigned long state, |
| 15114 | void *_notify) |
| 15115 | { |
| 15116 | struct netlink_notify *notify = _notify; |
| 15117 | struct cfg80211_registered_device *rdev; |
| 15118 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15119 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15120 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 15121 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15122 | return NOTIFY_DONE; |
| 15123 | |
| 15124 | rcu_read_lock(); |
| 15125 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15126 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15127 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 15128 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15129 | list_for_each_entry_rcu(sched_scan_req, |
| 15130 | &rdev->sched_scan_req_list, |
| 15131 | list) { |
| 15132 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 15133 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15134 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 15135 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 15136 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15137 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 15138 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15139 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15140 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15141 | if (wdev->owner_nlportid == notify->portid) { |
| 15142 | wdev->nl_owner_dead = true; |
| 15143 | schedule_work(&rdev->destroy_work); |
| 15144 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 15145 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 15146 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 15147 | } |
| 15148 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 15149 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 15150 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 15151 | list) { |
| 15152 | if (reg->nlportid == notify->portid) { |
| 15153 | list_del(®->list); |
| 15154 | kfree(reg); |
| 15155 | break; |
| 15156 | } |
| 15157 | } |
| 15158 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15159 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15160 | |
| 15161 | rcu_read_unlock(); |
| 15162 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 15163 | /* |
| 15164 | * It is possible that the user space process that is controlling the |
| 15165 | * indoor setting disappeared, so notify the regulatory core. |
| 15166 | */ |
| 15167 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 15168 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15169 | } |
| 15170 | |
| 15171 | static struct notifier_block nl80211_netlink_notifier = { |
| 15172 | .notifier_call = nl80211_netlink_notify, |
| 15173 | }; |
| 15174 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15175 | void cfg80211_ft_event(struct net_device *netdev, |
| 15176 | struct cfg80211_ft_event_params *ft_event) |
| 15177 | { |
| 15178 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15179 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15180 | struct sk_buff *msg; |
| 15181 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15182 | |
| 15183 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 15184 | |
| 15185 | if (!ft_event->target_ap) |
| 15186 | return; |
| 15187 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15188 | msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15189 | if (!msg) |
| 15190 | return; |
| 15191 | |
| 15192 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15193 | if (!hdr) |
| 15194 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15195 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15196 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15197 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15198 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 15199 | goto out; |
| 15200 | |
| 15201 | if (ft_event->ies && |
| 15202 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 15203 | goto out; |
| 15204 | if (ft_event->ric_ies && |
| 15205 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 15206 | ft_event->ric_ies)) |
| 15207 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15208 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 15209 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15210 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15211 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15212 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15213 | return; |
| 15214 | out: |
| 15215 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15216 | } |
| 15217 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 15218 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15219 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 15220 | { |
| 15221 | struct cfg80211_registered_device *rdev; |
| 15222 | struct sk_buff *msg; |
| 15223 | void *hdr; |
| 15224 | u32 nlportid; |
| 15225 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15226 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15227 | if (!rdev->crit_proto_nlportid) |
| 15228 | return; |
| 15229 | |
| 15230 | nlportid = rdev->crit_proto_nlportid; |
| 15231 | rdev->crit_proto_nlportid = 0; |
| 15232 | |
| 15233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15234 | if (!msg) |
| 15235 | return; |
| 15236 | |
| 15237 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 15238 | if (!hdr) |
| 15239 | goto nla_put_failure; |
| 15240 | |
| 15241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15242 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15243 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15244 | goto nla_put_failure; |
| 15245 | |
| 15246 | genlmsg_end(msg, hdr); |
| 15247 | |
| 15248 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15249 | return; |
| 15250 | |
| 15251 | nla_put_failure: |
| 15252 | if (hdr) |
| 15253 | genlmsg_cancel(msg, hdr); |
| 15254 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15255 | } |
| 15256 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 15257 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15258 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 15259 | { |
| 15260 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15261 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15262 | struct sk_buff *msg; |
| 15263 | void *hdr; |
| 15264 | |
| 15265 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15266 | if (!msg) |
| 15267 | return; |
| 15268 | |
| 15269 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 15270 | if (!hdr) |
| 15271 | goto out; |
| 15272 | |
| 15273 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15274 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15275 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15276 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15277 | goto out; |
| 15278 | |
| 15279 | genlmsg_end(msg, hdr); |
| 15280 | |
| 15281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 15282 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15283 | return; |
| 15284 | out: |
| 15285 | nlmsg_free(msg); |
| 15286 | } |
| 15287 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15288 | /* initialisation/exit functions */ |
| 15289 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15290 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15291 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 15292 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15293 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15294 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15295 | if (err) |
| 15296 | return err; |
| 15297 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15298 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 15299 | if (err) |
| 15300 | goto err_out; |
| 15301 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15302 | return 0; |
| 15303 | err_out: |
| 15304 | genl_unregister_family(&nl80211_fam); |
| 15305 | return err; |
| 15306 | } |
| 15307 | |
| 15308 | void nl80211_exit(void) |
| 15309 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15310 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15311 | genl_unregister_family(&nl80211_fam); |
| 15312 | } |