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 |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 6 | * Copyright 2015-2016 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> |
Dan Williams | 0781a50 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 19 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 20 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include <net/genetlink.h> |
| 23 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 24 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 25 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 26 | #include "core.h" |
| 27 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 28 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 29 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 30 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 31 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 32 | struct genl_info *info, |
| 33 | struct cfg80211_crypto_settings *settings, |
| 34 | int cipher_limit); |
| 35 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 36 | 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] | 37 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 38 | 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] | 39 | struct genl_info *info); |
| 40 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | /* the netlink family */ |
| 42 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 43 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 44 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 45 | .hdrsize = 0, /* no private header */ |
| 46 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 48 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 49 | .pre_doit = nl80211_pre_doit, |
| 50 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 53 | /* multicast groups */ |
| 54 | enum nl80211_multicast_groups { |
| 55 | NL80211_MCGRP_CONFIG, |
| 56 | NL80211_MCGRP_SCAN, |
| 57 | NL80211_MCGRP_REGULATORY, |
| 58 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 59 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 60 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 61 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 62 | }; |
| 63 | |
| 64 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 65 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 66 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 67 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 68 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 69 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 70 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 71 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 72 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 73 | #endif |
| 74 | }; |
| 75 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 76 | /* returns ERR_PTR values */ |
| 77 | static struct wireless_dev * |
| 78 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 79 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 80 | struct cfg80211_registered_device *rdev; |
| 81 | struct wireless_dev *result = NULL; |
| 82 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 83 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 84 | u64 wdev_id; |
| 85 | int wiphy_idx = -1; |
| 86 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 88 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 89 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 90 | if (!have_ifidx && !have_wdev_id) |
| 91 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 92 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 93 | if (have_ifidx) |
| 94 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 95 | if (have_wdev_id) { |
| 96 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 97 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 100 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 101 | struct wireless_dev *wdev; |
| 102 | |
| 103 | if (wiphy_net(&rdev->wiphy) != netns) |
| 104 | continue; |
| 105 | |
| 106 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 107 | continue; |
| 108 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 109 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 110 | if (have_ifidx && wdev->netdev && |
| 111 | wdev->netdev->ifindex == ifidx) { |
| 112 | result = wdev; |
| 113 | break; |
| 114 | } |
| 115 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 116 | result = wdev; |
| 117 | break; |
| 118 | } |
| 119 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 120 | |
| 121 | if (result) |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | if (result) |
| 126 | return result; |
| 127 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 128 | } |
| 129 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 130 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 131 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 133 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 134 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 135 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 136 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 137 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 138 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 139 | !attrs[NL80211_ATTR_IFINDEX] && |
| 140 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 141 | return ERR_PTR(-EINVAL); |
| 142 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 143 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 144 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 146 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 147 | if (attrs[NL80211_ATTR_WDEV]) { |
| 148 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 149 | struct wireless_dev *wdev; |
| 150 | bool found = false; |
| 151 | |
| 152 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 153 | if (tmp) { |
| 154 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 155 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | if (wdev->identifier != (u32)wdev_id) |
| 157 | continue; |
| 158 | found = true; |
| 159 | break; |
| 160 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 161 | |
| 162 | if (!found) |
| 163 | tmp = NULL; |
| 164 | |
| 165 | if (rdev && tmp != rdev) |
| 166 | return ERR_PTR(-EINVAL); |
| 167 | rdev = tmp; |
| 168 | } |
| 169 | } |
| 170 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 171 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 172 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 173 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 174 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 175 | if (netdev) { |
| 176 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 177 | tmp = wiphy_to_rdev( |
| 178 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 179 | else |
| 180 | tmp = NULL; |
| 181 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 182 | /* not wireless device -- return error */ |
| 183 | if (!tmp) |
| 184 | return ERR_PTR(-EINVAL); |
| 185 | |
| 186 | /* mismatch -- return error */ |
| 187 | if (rdev && tmp != rdev) |
| 188 | return ERR_PTR(-EINVAL); |
| 189 | |
| 190 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 194 | if (!rdev) |
| 195 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 196 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 197 | if (netns != wiphy_net(&rdev->wiphy)) |
| 198 | return ERR_PTR(-ENODEV); |
| 199 | |
| 200 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /* |
| 204 | * This function returns a pointer to the driver |
| 205 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 206 | * |
| 207 | * The result of this can be a PTR_ERR and hence must |
| 208 | * be checked with IS_ERR() for errors. |
| 209 | */ |
| 210 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 211 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 212 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 213 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 214 | } |
| 215 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 216 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 217 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 219 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 220 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 221 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 222 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 224 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 225 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 228 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 230 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 231 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 235 | |
| 236 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 238 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 240 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 241 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 242 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 244 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 245 | .len = WLAN_MAX_KEY_LEN }, |
| 246 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 247 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 248 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 249 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 251 | |
| 252 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 253 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 254 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 255 | .len = IEEE80211_MAX_DATA_LEN }, |
| 256 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 257 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 258 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 259 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 260 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 261 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 262 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 264 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 265 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 267 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 269 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 270 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 271 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 272 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 274 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 275 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 276 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 277 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 278 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 279 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 280 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 281 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 282 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 284 | |
| 285 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 286 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 287 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 288 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 289 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 290 | |
| 291 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 292 | .len = IEEE80211_MAX_SSID_LEN }, |
| 293 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 294 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 295 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 298 | [NL80211_ATTR_STA_FLAGS2] = { |
| 299 | .len = sizeof(struct nl80211_sta_flag_update), |
| 300 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 302 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 303 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 305 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 306 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 308 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Srinivas Dasari | 7e9e963 | 2017-07-07 01:43:39 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 310 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 311 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 314 | .len = IEEE80211_MAX_DATA_LEN }, |
| 315 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 319 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 320 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 321 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 323 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 324 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 326 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 327 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 329 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 331 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
| 336 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 337 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 338 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 340 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 341 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 343 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 344 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 347 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 349 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 350 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 351 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 352 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 353 | .len = NL80211_HT_CAPABILITY_LEN |
| 354 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 355 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 356 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 357 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 358 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 359 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 360 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 361 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 364 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Srinivas Dasari | b68aa7d | 2017-07-07 01:43:41 +0300 | [diff] [blame] | 365 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 366 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 367 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 368 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 369 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 370 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 371 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 372 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 373 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 374 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 375 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 376 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 377 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 378 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 379 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 380 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 381 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 382 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 383 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 384 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 385 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 386 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 387 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 388 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 389 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 390 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 391 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 392 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 394 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 395 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 396 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 398 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 399 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 400 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 401 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 402 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 403 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 404 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 405 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 406 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 407 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 408 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 409 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 410 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 411 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 412 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 413 | }, |
| 414 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 415 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
| 416 | [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 417 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | c9a6362 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 418 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 419 | .len = FILS_MAX_KEK_LEN }, |
| 420 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, |
Michael Braun | d757efc | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 421 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Vamsi Krishna | 4581639 | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 422 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
vamsi krishna | f4f1a54 | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 423 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 424 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 425 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 426 | }, |
Purushottam Kushwaha | df93506 | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 427 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 428 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 429 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 430 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 431 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 432 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 433 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 434 | .len = FILS_ERP_MAX_RRK_LEN }, |
| 435 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, |
| 436 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 437 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 438 | }; |
| 439 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 440 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 441 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 442 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 443 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 444 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 445 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 446 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 447 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 448 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 449 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 450 | }; |
| 451 | |
| 452 | /* policy for the key default flags */ |
| 453 | static const struct nla_policy |
| 454 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 455 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 456 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 457 | }; |
| 458 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 459 | /* policy for WoWLAN attributes */ |
| 460 | static const struct nla_policy |
| 461 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 462 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 463 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 464 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 465 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 466 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 467 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 468 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 469 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 470 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 471 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 472 | }; |
| 473 | |
| 474 | static const struct nla_policy |
| 475 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 476 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 477 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 478 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 479 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 480 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 481 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 482 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 483 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 484 | }, |
| 485 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 486 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 487 | }, |
| 488 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 489 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 490 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 491 | }; |
| 492 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 493 | /* policy for coalesce rule attributes */ |
| 494 | static const struct nla_policy |
| 495 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 496 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 497 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 498 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 499 | }; |
| 500 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 501 | /* policy for GTK rekey offload attributes */ |
| 502 | static const struct nla_policy |
| 503 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 504 | [NL80211_REKEY_DATA_KEK] = { .type = NLA_BINARY, |
| 505 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 506 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 507 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 508 | }; |
| 509 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 510 | static const struct nla_policy |
| 511 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 512 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 513 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 514 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 515 | }; |
| 516 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 517 | static const struct nla_policy |
| 518 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 519 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 520 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 521 | }; |
| 522 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 523 | static const struct nla_policy |
| 524 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 525 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 526 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 527 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 528 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 529 | }, |
| 530 | }; |
| 531 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 532 | /* policy for NAN function attributes */ |
| 533 | static const struct nla_policy |
| 534 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 535 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
Srinivas Dasari | 6a90f81 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 536 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 537 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 538 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 539 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 540 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 541 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 542 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 543 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 544 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 545 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 546 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 547 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 548 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 549 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 550 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 551 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 552 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 553 | }; |
| 554 | |
| 555 | /* policy for Service Response Filter attributes */ |
| 556 | static const struct nla_policy |
| 557 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 558 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 559 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 560 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 561 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 562 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 563 | }; |
| 564 | |
Peng Xu | 4ec90fd | 2017-10-10 13:56:53 -0700 | [diff] [blame] | 565 | /* policy for packet pattern attributes */ |
| 566 | static const struct nla_policy |
| 567 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 568 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 569 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 570 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 571 | }; |
| 572 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 573 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 574 | struct netlink_callback *cb, |
| 575 | struct cfg80211_registered_device **rdev, |
| 576 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 577 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 578 | int err; |
| 579 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 580 | if (!cb->args[0]) { |
| 581 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 582 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 583 | nl80211_policy); |
| 584 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 585 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 586 | |
| 587 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 588 | nl80211_fam.attrbuf); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 589 | if (IS_ERR(*wdev)) |
| 590 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 591 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 592 | /* 0 is the first index - add 1 to parse only once */ |
| 593 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 594 | cb->args[1] = (*wdev)->identifier; |
| 595 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 596 | /* subtract the 1 again here */ |
| 597 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 598 | struct wireless_dev *tmp; |
| 599 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 600 | if (!wiphy) |
| 601 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 602 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 603 | *wdev = NULL; |
| 604 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 605 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 606 | if (tmp->identifier == cb->args[1]) { |
| 607 | *wdev = tmp; |
| 608 | break; |
| 609 | } |
| 610 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 611 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 612 | if (!*wdev) |
| 613 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 616 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 617 | } |
| 618 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 619 | /* IE validation */ |
| 620 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 621 | { |
| 622 | const u8 *pos; |
| 623 | int len; |
| 624 | |
| 625 | if (!attr) |
| 626 | return true; |
| 627 | |
| 628 | pos = nla_data(attr); |
| 629 | len = nla_len(attr); |
| 630 | |
| 631 | while (len) { |
| 632 | u8 elemlen; |
| 633 | |
| 634 | if (len < 2) |
| 635 | return false; |
| 636 | len -= 2; |
| 637 | |
| 638 | elemlen = pos[1]; |
| 639 | if (elemlen > len) |
| 640 | return false; |
| 641 | |
| 642 | len -= elemlen; |
| 643 | pos += 2 + elemlen; |
| 644 | } |
| 645 | |
| 646 | return true; |
| 647 | } |
| 648 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 650 | 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] | 651 | int flags, u8 cmd) |
| 652 | { |
| 653 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 654 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 655 | } |
| 656 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 657 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 658 | struct ieee80211_channel *chan, |
| 659 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 660 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 661 | /* Some channels must be completely excluded from the |
| 662 | * list to protect old user-space tools from breaking |
| 663 | */ |
| 664 | if (!large && chan->flags & |
| 665 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 666 | return 0; |
| 667 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 668 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 669 | chan->center_freq)) |
| 670 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 671 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 672 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 673 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 674 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 675 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 676 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 677 | goto nla_put_failure; |
| 678 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 679 | goto nla_put_failure; |
| 680 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 681 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 682 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 683 | goto nla_put_failure; |
| 684 | if (large) { |
| 685 | u32 time; |
| 686 | |
| 687 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 688 | |
| 689 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 690 | chan->dfs_state)) |
| 691 | goto nla_put_failure; |
| 692 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 693 | time)) |
| 694 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 695 | if (nla_put_u32(msg, |
| 696 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 697 | chan->dfs_cac_ms)) |
| 698 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 699 | } |
| 700 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 701 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 702 | if (large) { |
| 703 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 704 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 705 | goto nla_put_failure; |
| 706 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 707 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 708 | goto nla_put_failure; |
| 709 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 710 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 711 | goto nla_put_failure; |
| 712 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 713 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 714 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 715 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 716 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 717 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 718 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 719 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 720 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 721 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 722 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 723 | goto nla_put_failure; |
| 724 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 725 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 726 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 727 | } |
| 728 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 729 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 730 | DBM_TO_MBM(chan->max_power))) |
| 731 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 732 | |
| 733 | return 0; |
| 734 | |
| 735 | nla_put_failure: |
| 736 | return -ENOBUFS; |
| 737 | } |
| 738 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 739 | /* netlink command implementations */ |
| 740 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 741 | struct key_parse { |
| 742 | struct key_params p; |
| 743 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 744 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 745 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 746 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 747 | }; |
| 748 | |
| 749 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 750 | { |
| 751 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 752 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 753 | nl80211_key_policy); |
| 754 | if (err) |
| 755 | return err; |
| 756 | |
| 757 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 758 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 759 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 760 | if (k->def) { |
| 761 | k->def_uni = true; |
| 762 | k->def_multi = true; |
| 763 | } |
| 764 | if (k->defmgmt) |
| 765 | k->def_multi = true; |
| 766 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 767 | if (tb[NL80211_KEY_IDX]) |
| 768 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 769 | |
| 770 | if (tb[NL80211_KEY_DATA]) { |
| 771 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 772 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 773 | } |
| 774 | |
| 775 | if (tb[NL80211_KEY_SEQ]) { |
| 776 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 777 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 778 | } |
| 779 | |
| 780 | if (tb[NL80211_KEY_CIPHER]) |
| 781 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 782 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 783 | if (tb[NL80211_KEY_TYPE]) { |
| 784 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 785 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 789 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 790 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 791 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 792 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 793 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 794 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 795 | if (err) |
| 796 | return err; |
| 797 | |
| 798 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 799 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 800 | } |
| 801 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 806 | { |
| 807 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 808 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 809 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 810 | } |
| 811 | |
| 812 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 813 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 814 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 815 | } |
| 816 | |
| 817 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 818 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 819 | |
| 820 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 821 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 822 | |
| 823 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 824 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 825 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 826 | if (k->def) { |
| 827 | k->def_uni = true; |
| 828 | k->def_multi = true; |
| 829 | } |
| 830 | if (k->defmgmt) |
| 831 | k->def_multi = true; |
| 832 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 833 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 834 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 835 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 839 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 840 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 841 | int err = nla_parse_nested( |
| 842 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 843 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 844 | nl80211_key_default_policy); |
| 845 | if (err) |
| 846 | return err; |
| 847 | |
| 848 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 849 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 850 | } |
| 851 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 856 | { |
| 857 | int err; |
| 858 | |
| 859 | memset(k, 0, sizeof(*k)); |
| 860 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 861 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 862 | |
| 863 | if (info->attrs[NL80211_ATTR_KEY]) |
| 864 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 865 | else |
| 866 | err = nl80211_parse_key_old(info, k); |
| 867 | |
| 868 | if (err) |
| 869 | return err; |
| 870 | |
| 871 | if (k->def && k->defmgmt) |
| 872 | return -EINVAL; |
| 873 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 874 | if (k->defmgmt) { |
| 875 | if (k->def_uni || !k->def_multi) |
| 876 | return -EINVAL; |
| 877 | } |
| 878 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 879 | if (k->idx != -1) { |
| 880 | if (k->defmgmt) { |
| 881 | if (k->idx < 4 || k->idx > 5) |
| 882 | return -EINVAL; |
| 883 | } else if (k->def) { |
| 884 | if (k->idx < 0 || k->idx > 3) |
| 885 | return -EINVAL; |
| 886 | } else { |
| 887 | if (k->idx < 0 || k->idx > 5) |
| 888 | return -EINVAL; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | return 0; |
| 893 | } |
| 894 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 895 | static struct cfg80211_cached_keys * |
| 896 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 897 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 898 | { |
| 899 | struct key_parse parse; |
| 900 | struct nlattr *key; |
| 901 | struct cfg80211_cached_keys *result; |
| 902 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 903 | bool have_key = false; |
| 904 | |
| 905 | nla_for_each_nested(key, keys, rem) { |
| 906 | have_key = true; |
| 907 | break; |
| 908 | } |
| 909 | |
| 910 | if (!have_key) |
| 911 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 912 | |
| 913 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 914 | if (!result) |
| 915 | return ERR_PTR(-ENOMEM); |
| 916 | |
| 917 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 918 | |
| 919 | nla_for_each_nested(key, keys, rem) { |
| 920 | memset(&parse, 0, sizeof(parse)); |
| 921 | parse.idx = -1; |
| 922 | |
| 923 | err = nl80211_parse_key_new(key, &parse); |
| 924 | if (err) |
| 925 | goto error; |
| 926 | err = -EINVAL; |
| 927 | if (!parse.p.key) |
| 928 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 929 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 930 | goto error; |
| 931 | if (parse.def) { |
| 932 | if (def) |
| 933 | goto error; |
| 934 | def = 1; |
| 935 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 936 | if (!parse.def_uni || !parse.def_multi) |
| 937 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 938 | } else if (parse.defmgmt) |
| 939 | goto error; |
| 940 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 941 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 942 | if (err) |
| 943 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 944 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 945 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 946 | err = -EINVAL; |
| 947 | goto error; |
| 948 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 949 | result->params[parse.idx].cipher = parse.p.cipher; |
| 950 | result->params[parse.idx].key_len = parse.p.key_len; |
| 951 | result->params[parse.idx].key = result->data[parse.idx]; |
| 952 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 953 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 954 | /* must be WEP key if we got here */ |
| 955 | if (no_ht) |
| 956 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 957 | } |
| 958 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 959 | if (result->def < 0) { |
| 960 | err = -EINVAL; |
| 961 | goto error; |
| 962 | } |
| 963 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 964 | return result; |
| 965 | error: |
| 966 | kfree(result); |
| 967 | return ERR_PTR(err); |
| 968 | } |
| 969 | |
| 970 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 971 | { |
| 972 | ASSERT_WDEV_LOCK(wdev); |
| 973 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 974 | switch (wdev->iftype) { |
| 975 | case NL80211_IFTYPE_AP: |
| 976 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 977 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 978 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 979 | break; |
| 980 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 981 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 982 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 983 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 984 | return -ENOLINK; |
| 985 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 986 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 987 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 988 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 989 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 990 | case NL80211_IFTYPE_P2P_DEVICE: |
| 991 | case NL80211_IFTYPE_WDS: |
| 992 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 993 | return -EINVAL; |
| 994 | } |
| 995 | |
| 996 | return 0; |
| 997 | } |
| 998 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 999 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 1000 | struct nlattr *tb) |
| 1001 | { |
| 1002 | struct ieee80211_channel *chan; |
| 1003 | |
| 1004 | if (tb == NULL) |
| 1005 | return NULL; |
| 1006 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1007 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1008 | return NULL; |
| 1009 | return chan; |
| 1010 | } |
| 1011 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1012 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1013 | { |
| 1014 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 1015 | int i; |
| 1016 | |
| 1017 | if (!nl_modes) |
| 1018 | goto nla_put_failure; |
| 1019 | |
| 1020 | i = 0; |
| 1021 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1022 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1023 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1024 | ifmodes >>= 1; |
| 1025 | i++; |
| 1026 | } |
| 1027 | |
| 1028 | nla_nest_end(msg, nl_modes); |
| 1029 | return 0; |
| 1030 | |
| 1031 | nla_put_failure: |
| 1032 | return -ENOBUFS; |
| 1033 | } |
| 1034 | |
| 1035 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1036 | struct sk_buff *msg, |
| 1037 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1038 | { |
| 1039 | struct nlattr *nl_combis; |
| 1040 | int i, j; |
| 1041 | |
| 1042 | nl_combis = nla_nest_start(msg, |
| 1043 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1044 | if (!nl_combis) |
| 1045 | goto nla_put_failure; |
| 1046 | |
| 1047 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1048 | const struct ieee80211_iface_combination *c; |
| 1049 | struct nlattr *nl_combi, *nl_limits; |
| 1050 | |
| 1051 | c = &wiphy->iface_combinations[i]; |
| 1052 | |
| 1053 | nl_combi = nla_nest_start(msg, i + 1); |
| 1054 | if (!nl_combi) |
| 1055 | goto nla_put_failure; |
| 1056 | |
| 1057 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1058 | if (!nl_limits) |
| 1059 | goto nla_put_failure; |
| 1060 | |
| 1061 | for (j = 0; j < c->n_limits; j++) { |
| 1062 | struct nlattr *nl_limit; |
| 1063 | |
| 1064 | nl_limit = nla_nest_start(msg, j + 1); |
| 1065 | if (!nl_limit) |
| 1066 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1067 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1068 | c->limits[j].max)) |
| 1069 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1070 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1071 | c->limits[j].types)) |
| 1072 | goto nla_put_failure; |
| 1073 | nla_nest_end(msg, nl_limit); |
| 1074 | } |
| 1075 | |
| 1076 | nla_nest_end(msg, nl_limits); |
| 1077 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1078 | if (c->beacon_int_infra_match && |
| 1079 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1080 | goto nla_put_failure; |
| 1081 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1082 | c->num_different_channels) || |
| 1083 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1084 | c->max_interfaces)) |
| 1085 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1086 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1087 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1088 | c->radar_detect_widths) || |
| 1089 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1090 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1091 | goto nla_put_failure; |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1092 | if (c->beacon_int_min_gcd && |
| 1093 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1094 | c->beacon_int_min_gcd)) |
| 1095 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1096 | |
| 1097 | nla_nest_end(msg, nl_combi); |
| 1098 | } |
| 1099 | |
| 1100 | nla_nest_end(msg, nl_combis); |
| 1101 | |
| 1102 | return 0; |
| 1103 | nla_put_failure: |
| 1104 | return -ENOBUFS; |
| 1105 | } |
| 1106 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1107 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1108 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1109 | struct sk_buff *msg) |
| 1110 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1111 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1112 | struct nlattr *nl_tcp; |
| 1113 | |
| 1114 | if (!tcp) |
| 1115 | return 0; |
| 1116 | |
| 1117 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1118 | if (!nl_tcp) |
| 1119 | return -ENOBUFS; |
| 1120 | |
| 1121 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1122 | tcp->data_payload_max)) |
| 1123 | return -ENOBUFS; |
| 1124 | |
| 1125 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1126 | tcp->data_payload_max)) |
| 1127 | return -ENOBUFS; |
| 1128 | |
| 1129 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1130 | return -ENOBUFS; |
| 1131 | |
| 1132 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1133 | sizeof(*tcp->tok), tcp->tok)) |
| 1134 | return -ENOBUFS; |
| 1135 | |
| 1136 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1137 | tcp->data_interval_max)) |
| 1138 | return -ENOBUFS; |
| 1139 | |
| 1140 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1141 | tcp->wake_payload_max)) |
| 1142 | return -ENOBUFS; |
| 1143 | |
| 1144 | nla_nest_end(msg, nl_tcp); |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1148 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1149 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1150 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1151 | { |
| 1152 | struct nlattr *nl_wowlan; |
| 1153 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1154 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1155 | return 0; |
| 1156 | |
| 1157 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1158 | if (!nl_wowlan) |
| 1159 | return -ENOBUFS; |
| 1160 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1161 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1162 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1163 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1164 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1165 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1166 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1167 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1169 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1170 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1171 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1172 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1173 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1174 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1175 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1176 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1177 | return -ENOBUFS; |
| 1178 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1179 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1180 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1181 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1182 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1183 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1184 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1185 | }; |
| 1186 | |
| 1187 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1188 | sizeof(pat), &pat)) |
| 1189 | return -ENOBUFS; |
| 1190 | } |
| 1191 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1192 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1193 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1194 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1195 | return -ENOBUFS; |
| 1196 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1197 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1198 | return -ENOBUFS; |
| 1199 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1200 | nla_nest_end(msg, nl_wowlan); |
| 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | #endif |
| 1205 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1206 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1207 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1208 | { |
| 1209 | struct nl80211_coalesce_rule_support rule; |
| 1210 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1211 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1212 | return 0; |
| 1213 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1214 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1215 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1216 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1217 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1218 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1219 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1220 | |
| 1221 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1222 | return -ENOBUFS; |
| 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1227 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1228 | struct ieee80211_supported_band *sband) |
| 1229 | { |
| 1230 | struct nlattr *nl_rates, *nl_rate; |
| 1231 | struct ieee80211_rate *rate; |
| 1232 | int i; |
| 1233 | |
| 1234 | /* add HT info */ |
| 1235 | if (sband->ht_cap.ht_supported && |
| 1236 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1237 | sizeof(sband->ht_cap.mcs), |
| 1238 | &sband->ht_cap.mcs) || |
| 1239 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1240 | sband->ht_cap.cap) || |
| 1241 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1242 | sband->ht_cap.ampdu_factor) || |
| 1243 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1244 | sband->ht_cap.ampdu_density))) |
| 1245 | return -ENOBUFS; |
| 1246 | |
| 1247 | /* add VHT info */ |
| 1248 | if (sband->vht_cap.vht_supported && |
| 1249 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1250 | sizeof(sband->vht_cap.vht_mcs), |
| 1251 | &sband->vht_cap.vht_mcs) || |
| 1252 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1253 | sband->vht_cap.cap))) |
| 1254 | return -ENOBUFS; |
| 1255 | |
| 1256 | /* add bitrates */ |
| 1257 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1258 | if (!nl_rates) |
| 1259 | return -ENOBUFS; |
| 1260 | |
| 1261 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1262 | nl_rate = nla_nest_start(msg, i); |
| 1263 | if (!nl_rate) |
| 1264 | return -ENOBUFS; |
| 1265 | |
| 1266 | rate = &sband->bitrates[i]; |
| 1267 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1268 | rate->bitrate)) |
| 1269 | return -ENOBUFS; |
| 1270 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1271 | nla_put_flag(msg, |
| 1272 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1273 | return -ENOBUFS; |
| 1274 | |
| 1275 | nla_nest_end(msg, nl_rate); |
| 1276 | } |
| 1277 | |
| 1278 | nla_nest_end(msg, nl_rates); |
| 1279 | |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | static int |
| 1284 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1285 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1286 | { |
| 1287 | u16 stypes; |
| 1288 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1289 | enum nl80211_iftype ift; |
| 1290 | int i; |
| 1291 | |
| 1292 | if (!mgmt_stypes) |
| 1293 | return 0; |
| 1294 | |
| 1295 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1296 | if (!nl_ifs) |
| 1297 | return -ENOBUFS; |
| 1298 | |
| 1299 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1300 | nl_ftypes = nla_nest_start(msg, ift); |
| 1301 | if (!nl_ftypes) |
| 1302 | return -ENOBUFS; |
| 1303 | i = 0; |
| 1304 | stypes = mgmt_stypes[ift].tx; |
| 1305 | while (stypes) { |
| 1306 | if ((stypes & 1) && |
| 1307 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1308 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1309 | return -ENOBUFS; |
| 1310 | stypes >>= 1; |
| 1311 | i++; |
| 1312 | } |
| 1313 | nla_nest_end(msg, nl_ftypes); |
| 1314 | } |
| 1315 | |
| 1316 | nla_nest_end(msg, nl_ifs); |
| 1317 | |
| 1318 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1319 | if (!nl_ifs) |
| 1320 | return -ENOBUFS; |
| 1321 | |
| 1322 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1323 | nl_ftypes = nla_nest_start(msg, ift); |
| 1324 | if (!nl_ftypes) |
| 1325 | return -ENOBUFS; |
| 1326 | i = 0; |
| 1327 | stypes = mgmt_stypes[ift].rx; |
| 1328 | while (stypes) { |
| 1329 | if ((stypes & 1) && |
| 1330 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1331 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1332 | return -ENOBUFS; |
| 1333 | stypes >>= 1; |
| 1334 | i++; |
| 1335 | } |
| 1336 | nla_nest_end(msg, nl_ftypes); |
| 1337 | } |
| 1338 | nla_nest_end(msg, nl_ifs); |
| 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1343 | struct nl80211_dump_wiphy_state { |
| 1344 | s64 filter_wiphy; |
| 1345 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1346 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1347 | bool split; |
| 1348 | }; |
| 1349 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1350 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1351 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1352 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1353 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1354 | { |
| 1355 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1356 | struct nlattr *nl_bands, *nl_band; |
| 1357 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1358 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1359 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1360 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1361 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1362 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1363 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1364 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1365 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1366 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1367 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | return -ENOBUFS; |
| 1369 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1370 | if (WARN_ON(!state)) |
| 1371 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1372 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1375 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1376 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1378 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1379 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1380 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1381 | goto finish; |
| 1382 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1383 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | case 0: |
| 1385 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1386 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1387 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1388 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1389 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1390 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1392 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1394 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1396 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1397 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1398 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1400 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1401 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1402 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1403 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1404 | rdev->wiphy.max_match_sets) || |
| 1405 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1406 | rdev->wiphy.max_sched_scan_plans) || |
| 1407 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1408 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1409 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1410 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1411 | goto nla_put_failure; |
| 1412 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1413 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1414 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1415 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1416 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1417 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1418 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1419 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1421 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1422 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1423 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1424 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1425 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1427 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1428 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1430 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1431 | state->split_start++; |
| 1432 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | break; |
| 1434 | case 1: |
| 1435 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1436 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1437 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1438 | goto nla_put_failure; |
| 1439 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1441 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1442 | goto nla_put_failure; |
| 1443 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1444 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1445 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1446 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1447 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1449 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1451 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1453 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1454 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1455 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1456 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1458 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1459 | if ((rdev->wiphy.available_antennas_tx || |
| 1460 | rdev->wiphy.available_antennas_rx) && |
| 1461 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | u32 tx_ant = 0, rx_ant = 0; |
| 1463 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1464 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1465 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | if (!res) { |
| 1467 | if (nla_put_u32(msg, |
| 1468 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1469 | tx_ant) || |
| 1470 | nla_put_u32(msg, |
| 1471 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1472 | rx_ant)) |
| 1473 | goto nla_put_failure; |
| 1474 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1477 | state->split_start++; |
| 1478 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | break; |
| 1480 | case 2: |
| 1481 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1482 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1484 | state->split_start++; |
| 1485 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | break; |
| 1487 | case 3: |
| 1488 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1489 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1490 | goto nla_put_failure; |
| 1491 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1492 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1493 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | struct ieee80211_supported_band *sband; |
| 1495 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | |
| 1498 | if (!sband) |
| 1499 | continue; |
| 1500 | |
| 1501 | nl_band = nla_nest_start(msg, band); |
| 1502 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1503 | goto nla_put_failure; |
| 1504 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1505 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | case 0: |
| 1507 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1508 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1509 | state->chan_start++; |
| 1510 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | break; |
| 1512 | default: |
| 1513 | /* add frequencies */ |
| 1514 | nl_freqs = nla_nest_start( |
| 1515 | msg, NL80211_BAND_ATTR_FREQS); |
| 1516 | if (!nl_freqs) |
| 1517 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1518 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1519 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1520 | i < sband->n_channels; |
| 1521 | i++) { |
| 1522 | nl_freq = nla_nest_start(msg, i); |
| 1523 | if (!nl_freq) |
| 1524 | goto nla_put_failure; |
| 1525 | |
| 1526 | chan = &sband->channels[i]; |
| 1527 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1528 | if (nl80211_msg_put_channel( |
| 1529 | msg, chan, |
| 1530 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | goto nla_put_failure; |
| 1532 | |
| 1533 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1534 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | break; |
| 1536 | } |
| 1537 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1538 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1540 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | nla_nest_end(msg, nl_freqs); |
| 1542 | } |
| 1543 | |
| 1544 | nla_nest_end(msg, nl_band); |
| 1545 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1546 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1547 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1548 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | band--; |
| 1550 | break; |
| 1551 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1552 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1553 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1554 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1555 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1556 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1557 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1558 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1559 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | if (state->band_start == 0 && state->chan_start == 0) |
| 1562 | state->split_start++; |
| 1563 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | break; |
| 1565 | case 4: |
| 1566 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1567 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1568 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | |
| 1570 | i = 0; |
| 1571 | #define CMD(op, n) \ |
| 1572 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1573 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | i++; \ |
| 1575 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1576 | goto nla_put_failure; \ |
| 1577 | } \ |
| 1578 | } while (0) |
| 1579 | |
| 1580 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1581 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1582 | CMD(add_key, NEW_KEY); |
| 1583 | CMD(start_ap, START_AP); |
| 1584 | CMD(add_station, NEW_STATION); |
| 1585 | CMD(add_mpath, NEW_MPATH); |
| 1586 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1587 | CMD(change_bss, SET_BSS); |
| 1588 | CMD(auth, AUTHENTICATE); |
| 1589 | CMD(assoc, ASSOCIATE); |
| 1590 | CMD(deauth, DEAUTHENTICATE); |
| 1591 | CMD(disassoc, DISASSOCIATE); |
| 1592 | CMD(join_ibss, JOIN_IBSS); |
| 1593 | CMD(join_mesh, JOIN_MESH); |
| 1594 | CMD(set_pmksa, SET_PMKSA); |
| 1595 | CMD(del_pmksa, DEL_PMKSA); |
| 1596 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1597 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1598 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1599 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1600 | CMD(mgmt_tx, FRAME); |
| 1601 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1602 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | i++; |
| 1604 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1605 | goto nla_put_failure; |
| 1606 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1608 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1609 | i++; |
| 1610 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1611 | goto nla_put_failure; |
| 1612 | } |
| 1613 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1614 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1615 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1616 | CMD(tdls_oper, TDLS_OPER); |
| 1617 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1618 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1620 | CMD(probe_client, PROBE_CLIENT); |
| 1621 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1622 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | i++; |
| 1624 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1625 | goto nla_put_failure; |
| 1626 | } |
| 1627 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1628 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1629 | #ifdef CONFIG_NL80211_TESTMODE |
| 1630 | CMD(testmode_cmd, TESTMODE); |
| 1631 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1632 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1633 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1634 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1635 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1636 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1637 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1638 | if (rdev->wiphy.features & |
| 1639 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1640 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | d757efc | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1641 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 30da4e8 | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1642 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1643 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1644 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1645 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1646 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1647 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | i++; |
| 1649 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1650 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1651 | } |
| 1652 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1653 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1654 | i++; |
| 1655 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1656 | goto nla_put_failure; |
| 1657 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1658 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1660 | state->split_start++; |
| 1661 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1662 | break; |
| 1663 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1664 | if (rdev->ops->remain_on_channel && |
| 1665 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | nla_put_u32(msg, |
| 1667 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1668 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1669 | goto nla_put_failure; |
| 1670 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1672 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1673 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1674 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1675 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1676 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1677 | state->split_start++; |
| 1678 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1679 | break; |
| 1680 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1681 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1682 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1684 | state->split_start++; |
| 1685 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1686 | break; |
| 1687 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1688 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1689 | #endif |
| 1690 | case 7: |
| 1691 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1692 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1693 | goto nla_put_failure; |
| 1694 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1695 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1696 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1697 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1698 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1699 | state->split_start++; |
| 1700 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1701 | break; |
| 1702 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1704 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1705 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1706 | goto nla_put_failure; |
| 1707 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1708 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1709 | /* |
| 1710 | * We can only add the per-channel limit information if the |
| 1711 | * dump is split, otherwise it makes it too big. Therefore |
| 1712 | * only advertise it in that case. |
| 1713 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1714 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1715 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1716 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1717 | goto nla_put_failure; |
| 1718 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1720 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1721 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1722 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1723 | goto nla_put_failure; |
| 1724 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1725 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1726 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1727 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1728 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1729 | goto nla_put_failure; |
| 1730 | |
| 1731 | /* |
| 1732 | * Any information below this point is only available to |
| 1733 | * applications that can deal with it being split. This |
| 1734 | * helps ensure that newly added capabilities don't break |
| 1735 | * older tools by overrunning their buffers. |
| 1736 | * |
| 1737 | * We still increment split_start so that in the split |
| 1738 | * case we'll continue with more data in the next round, |
| 1739 | * but break unconditionally so unsplit data stops here. |
| 1740 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1741 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1742 | break; |
| 1743 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1744 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1745 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1746 | rdev->wiphy.extended_capabilities_len, |
| 1747 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1748 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1749 | rdev->wiphy.extended_capabilities_len, |
| 1750 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1751 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1752 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1753 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1754 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1755 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1756 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1757 | goto nla_put_failure; |
| 1758 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1759 | state->split_start++; |
| 1760 | break; |
| 1761 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1762 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1763 | goto nla_put_failure; |
| 1764 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1765 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1766 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1767 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1768 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1769 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1770 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1771 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1772 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1773 | goto nla_put_failure; |
| 1774 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1775 | state->split_start++; |
| 1776 | break; |
| 1777 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1778 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1779 | const struct nl80211_vendor_cmd_info *info; |
| 1780 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1781 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1782 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1783 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1784 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1785 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1786 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1787 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1788 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1789 | goto nla_put_failure; |
| 1790 | } |
| 1791 | nla_nest_end(msg, nested); |
| 1792 | } |
| 1793 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1794 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1795 | const struct nl80211_vendor_cmd_info *info; |
| 1796 | struct nlattr *nested; |
| 1797 | |
| 1798 | nested = nla_nest_start(msg, |
| 1799 | NL80211_ATTR_VENDOR_EVENTS); |
| 1800 | if (!nested) |
| 1801 | goto nla_put_failure; |
| 1802 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1803 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1804 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1805 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1806 | goto nla_put_failure; |
| 1807 | } |
| 1808 | nla_nest_end(msg, nested); |
| 1809 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1810 | state->split_start++; |
| 1811 | break; |
| 1812 | case 12: |
| 1813 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1814 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1815 | rdev->wiphy.max_num_csa_counters)) |
| 1816 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1817 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1818 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1819 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1820 | goto nla_put_failure; |
| 1821 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1822 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1823 | sizeof(rdev->wiphy.ext_features), |
| 1824 | rdev->wiphy.ext_features)) |
| 1825 | goto nla_put_failure; |
| 1826 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1827 | if (rdev->wiphy.bss_select_support) { |
| 1828 | struct nlattr *nested; |
| 1829 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1830 | |
| 1831 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1832 | if (!nested) |
| 1833 | goto nla_put_failure; |
| 1834 | |
| 1835 | i = 0; |
| 1836 | while (bss_select_support) { |
| 1837 | if ((bss_select_support & 1) && |
| 1838 | nla_put_flag(msg, i)) |
| 1839 | goto nla_put_failure; |
| 1840 | i++; |
| 1841 | bss_select_support >>= 1; |
| 1842 | } |
| 1843 | nla_nest_end(msg, nested); |
| 1844 | } |
| 1845 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1846 | state->split_start++; |
| 1847 | break; |
| 1848 | case 13: |
| 1849 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1850 | rdev->wiphy.iftype_ext_capab) { |
| 1851 | struct nlattr *nested_ext_capab, *nested; |
| 1852 | |
| 1853 | nested = nla_nest_start(msg, |
| 1854 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1855 | if (!nested) |
| 1856 | goto nla_put_failure; |
| 1857 | |
| 1858 | for (i = state->capa_start; |
| 1859 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1860 | const struct wiphy_iftype_ext_capab *capab; |
| 1861 | |
| 1862 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1863 | |
| 1864 | nested_ext_capab = nla_nest_start(msg, i); |
| 1865 | if (!nested_ext_capab || |
| 1866 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1867 | capab->iftype) || |
| 1868 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1869 | capab->extended_capabilities_len, |
| 1870 | capab->extended_capabilities) || |
| 1871 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1872 | capab->extended_capabilities_len, |
| 1873 | capab->extended_capabilities_mask)) |
| 1874 | goto nla_put_failure; |
| 1875 | |
| 1876 | nla_nest_end(msg, nested_ext_capab); |
| 1877 | if (state->split) |
| 1878 | break; |
| 1879 | } |
| 1880 | nla_nest_end(msg, nested); |
| 1881 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1882 | state->capa_start = i + 1; |
| 1883 | break; |
| 1884 | } |
| 1885 | } |
| 1886 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1887 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1888 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1889 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1890 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1891 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1892 | genlmsg_end(msg, hdr); |
| 1893 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1894 | |
| 1895 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1896 | genlmsg_cancel(msg, hdr); |
| 1897 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1898 | } |
| 1899 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1900 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1901 | struct netlink_callback *cb, |
| 1902 | struct nl80211_dump_wiphy_state *state) |
| 1903 | { |
| 1904 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1905 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1906 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1907 | /* ignore parse errors for backward compatibility */ |
| 1908 | if (ret) |
| 1909 | return 0; |
| 1910 | |
| 1911 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1912 | if (tb[NL80211_ATTR_WIPHY]) |
| 1913 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1914 | if (tb[NL80211_ATTR_WDEV]) |
| 1915 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1916 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1917 | struct net_device *netdev; |
| 1918 | struct cfg80211_registered_device *rdev; |
| 1919 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1920 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1921 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1922 | if (!netdev) |
| 1923 | return -ENODEV; |
| 1924 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1925 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1926 | netdev->ieee80211_ptr->wiphy); |
| 1927 | state->filter_wiphy = rdev->wiphy_idx; |
| 1928 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1934 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1935 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1936 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1937 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1938 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1939 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1940 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1941 | if (!state) { |
| 1942 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1943 | if (!state) { |
| 1944 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1945 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1946 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1947 | state->filter_wiphy = -1; |
| 1948 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1949 | if (ret) { |
| 1950 | kfree(state); |
| 1951 | rtnl_unlock(); |
| 1952 | return ret; |
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 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1957 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1958 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1959 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1960 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1961 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1962 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1963 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1964 | continue; |
| 1965 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1966 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1967 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1968 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1969 | NETLINK_CB(cb->skb).portid, |
| 1970 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1971 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1972 | if (ret < 0) { |
| 1973 | /* |
| 1974 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1975 | * or EMSGSIZE returned), this SKB is still |
| 1976 | * empty (so it's not too big because another |
| 1977 | * wiphy dataset is already in the skb) and |
| 1978 | * we've not tried to adjust the dump allocation |
| 1979 | * yet ... then adjust the alloc size to be |
| 1980 | * bigger, and return 1 but with the empty skb. |
| 1981 | * This results in an empty message being RX'ed |
| 1982 | * in userspace, but that is ignored. |
| 1983 | * |
| 1984 | * We can then retry with the larger buffer. |
| 1985 | */ |
| 1986 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1987 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1988 | cb->min_dump_alloc < 4096) { |
| 1989 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1990 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1991 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1992 | return 1; |
| 1993 | } |
| 1994 | idx--; |
| 1995 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1996 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1997 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1998 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1999 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2000 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2001 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2002 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2003 | |
| 2004 | return skb->len; |
| 2005 | } |
| 2006 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2007 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2008 | { |
| 2009 | kfree((void *)cb->args[0]); |
| 2010 | return 0; |
| 2011 | } |
| 2012 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2013 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2014 | { |
| 2015 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2017 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2018 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2019 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2020 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2021 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2022 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2023 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2024 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2025 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2026 | nlmsg_free(msg); |
| 2027 | return -ENOBUFS; |
| 2028 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2029 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2030 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2031 | } |
| 2032 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2033 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2034 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2035 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2036 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2037 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2038 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2039 | }; |
| 2040 | |
| 2041 | static int parse_txq_params(struct nlattr *tb[], |
| 2042 | struct ieee80211_txq_params *txq_params) |
| 2043 | { |
Dan Williams | 0781a50 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2044 | u8 ac; |
| 2045 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2046 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2047 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2048 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2049 | return -EINVAL; |
| 2050 | |
Dan Williams | 0781a50 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2051 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2052 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2053 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2054 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2055 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2056 | |
Dan Williams | 0781a50 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2057 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2058 | return -EINVAL; |
Dan Williams | 0781a50 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2059 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2060 | return 0; |
| 2061 | } |
| 2062 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2063 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2064 | { |
| 2065 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2066 | * You can only set the channel explicitly for WDS interfaces, |
| 2067 | * all others have their channel managed via their respective |
| 2068 | * "establish a connection" command (connect, join, ...) |
| 2069 | * |
| 2070 | * For AP/GO and mesh mode, the channel can be set with the |
| 2071 | * channel userspace API, but is only stored and passed to the |
| 2072 | * low-level driver when the AP starts or the mesh is joined. |
| 2073 | * This is for backward compatibility, userspace can also give |
| 2074 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2075 | * |
| 2076 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2077 | * whatever else is going on, so they have their own special |
| 2078 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2079 | */ |
| 2080 | return !wdev || |
| 2081 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2083 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2084 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2085 | } |
| 2086 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2087 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2088 | struct genl_info *info, |
| 2089 | struct cfg80211_chan_def *chandef) |
| 2090 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2091 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2092 | |
| 2093 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2094 | return -EINVAL; |
| 2095 | |
| 2096 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2097 | |
| 2098 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2099 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2100 | chandef->center_freq1 = control_freq; |
| 2101 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2102 | |
| 2103 | /* Primary channel not allowed */ |
| 2104 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2105 | return -EINVAL; |
| 2106 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2107 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2108 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2109 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2110 | chantype = nla_get_u32( |
| 2111 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2112 | |
| 2113 | switch (chantype) { |
| 2114 | case NL80211_CHAN_NO_HT: |
| 2115 | case NL80211_CHAN_HT20: |
| 2116 | case NL80211_CHAN_HT40PLUS: |
| 2117 | case NL80211_CHAN_HT40MINUS: |
| 2118 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2119 | chantype); |
| 2120 | break; |
| 2121 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2122 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2123 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2124 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2125 | chandef->width = |
| 2126 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2127 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2128 | chandef->center_freq1 = |
| 2129 | nla_get_u32( |
| 2130 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2131 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2132 | chandef->center_freq2 = |
| 2133 | nla_get_u32( |
| 2134 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2135 | } |
| 2136 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2137 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | return -EINVAL; |
| 2139 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2140 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2141 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2142 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2143 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2144 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2145 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2146 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2147 | return -EINVAL; |
| 2148 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2149 | return 0; |
| 2150 | } |
| 2151 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2152 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2153 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2154 | struct genl_info *info) |
| 2155 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2156 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2157 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2158 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2159 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2160 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2161 | if (dev) |
| 2162 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2163 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2164 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2165 | if (wdev) |
| 2166 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2167 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2168 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2169 | if (result) |
| 2170 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2171 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2172 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2173 | case NL80211_IFTYPE_AP: |
| 2174 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2175 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2176 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2177 | result = -EINVAL; |
| 2178 | break; |
| 2179 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2180 | if (wdev->beacon_interval) { |
| 2181 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2182 | !(rdev->wiphy.features & |
| 2183 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2184 | result = -EBUSY; |
| 2185 | break; |
| 2186 | } |
| 2187 | |
| 2188 | /* Only allow dynamic channel width changes */ |
| 2189 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2190 | result = -EBUSY; |
| 2191 | break; |
| 2192 | } |
| 2193 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2194 | if (result) |
| 2195 | break; |
| 2196 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2197 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2198 | result = 0; |
| 2199 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2200 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2201 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2202 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2203 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2204 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2205 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2206 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2207 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2208 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2209 | |
| 2210 | return result; |
| 2211 | } |
| 2212 | |
| 2213 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2214 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2216 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2217 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2218 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2219 | } |
| 2220 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2221 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2222 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2224 | struct net_device *dev = info->user_ptr[1]; |
| 2225 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2226 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2227 | |
| 2228 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2229 | return -EINVAL; |
| 2230 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2231 | if (netif_running(dev)) |
| 2232 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2233 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2234 | if (!rdev->ops->set_wds_peer) |
| 2235 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2236 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2237 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2238 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2239 | |
| 2240 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2241 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2242 | } |
| 2243 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2244 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2245 | { |
| 2246 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2247 | struct net_device *netdev = NULL; |
| 2248 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2249 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2250 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2251 | u32 changed; |
| 2252 | u8 retry_short = 0, retry_long = 0; |
| 2253 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2254 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2255 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2256 | ASSERT_RTNL(); |
| 2257 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2258 | /* |
| 2259 | * Try to find the wiphy and netdev. Normally this |
| 2260 | * function shouldn't need the netdev, but this is |
| 2261 | * done for backward compatibility -- previously |
| 2262 | * setting the channel was done per wiphy, but now |
| 2263 | * it is per netdev. Previous userland like hostapd |
| 2264 | * also passed a netdev to set_wiphy, so that it is |
| 2265 | * possible to let that go to the right netdev! |
| 2266 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2267 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2268 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2269 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2270 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2271 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2272 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2273 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2274 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2275 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2278 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2279 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2280 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2281 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2282 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2283 | wdev = NULL; |
| 2284 | netdev = NULL; |
| 2285 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2286 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2287 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2288 | |
| 2289 | /* |
| 2290 | * end workaround code, by now the rdev is available |
| 2291 | * and locked, and wdev may or may not be NULL. |
| 2292 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2293 | |
| 2294 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2295 | result = cfg80211_dev_rename( |
| 2296 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2297 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2298 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2299 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2301 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2302 | struct ieee80211_txq_params txq_params; |
| 2303 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2304 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2305 | if (!rdev->ops->set_txq_params) |
| 2306 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2307 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2308 | if (!netdev) |
| 2309 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2310 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2311 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2312 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2313 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2314 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2315 | if (!netif_running(netdev)) |
| 2316 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2317 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2318 | nla_for_each_nested(nl_txq_params, |
| 2319 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2320 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2321 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2322 | nla_data(nl_txq_params), |
| 2323 | nla_len(nl_txq_params), |
| 2324 | txq_params_policy); |
| 2325 | if (result) |
| 2326 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2327 | result = parse_txq_params(tb, &txq_params); |
| 2328 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2330 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2331 | result = rdev_set_txq_params(rdev, netdev, |
| 2332 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2333 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2334 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2335 | } |
| 2336 | } |
| 2337 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2338 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2339 | result = __nl80211_set_channel( |
| 2340 | rdev, |
| 2341 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2342 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2343 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2344 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2345 | } |
| 2346 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2347 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2348 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2349 | enum nl80211_tx_power_setting type; |
| 2350 | int idx, mbm = 0; |
| 2351 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2352 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2353 | txp_wdev = NULL; |
| 2354 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2355 | if (!rdev->ops->set_tx_power) |
| 2356 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2357 | |
| 2358 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2359 | type = nla_get_u32(info->attrs[idx]); |
| 2360 | |
| 2361 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2362 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2363 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2364 | |
| 2365 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2366 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2367 | mbm = nla_get_u32(info->attrs[idx]); |
| 2368 | } |
| 2369 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2370 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2371 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2372 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2373 | } |
| 2374 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2375 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2376 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2377 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2378 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2379 | if ((!rdev->wiphy.available_antennas_tx && |
| 2380 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2381 | !rdev->ops->set_antenna) |
| 2382 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2383 | |
| 2384 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2385 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2386 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2387 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2388 | * available antenna masks, except for the "all" mask */ |
| 2389 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2390 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2391 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2392 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2393 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2394 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2395 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2396 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2397 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2398 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2399 | } |
| 2400 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2401 | changed = 0; |
| 2402 | |
| 2403 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2404 | retry_short = nla_get_u8( |
| 2405 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2406 | if (retry_short == 0) |
| 2407 | return -EINVAL; |
| 2408 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2409 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2410 | } |
| 2411 | |
| 2412 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2413 | retry_long = nla_get_u8( |
| 2414 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2415 | if (retry_long == 0) |
| 2416 | return -EINVAL; |
| 2417 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2418 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2419 | } |
| 2420 | |
| 2421 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2422 | frag_threshold = nla_get_u32( |
| 2423 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2424 | if (frag_threshold < 256) |
| 2425 | return -EINVAL; |
| 2426 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2427 | if (frag_threshold != (u32) -1) { |
| 2428 | /* |
| 2429 | * Fragments (apart from the last one) are required to |
| 2430 | * have even length. Make the fragmentation code |
| 2431 | * simpler by stripping LSB should someone try to use |
| 2432 | * odd threshold value. |
| 2433 | */ |
| 2434 | frag_threshold &= ~0x1; |
| 2435 | } |
| 2436 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2437 | } |
| 2438 | |
| 2439 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2440 | rts_threshold = nla_get_u32( |
| 2441 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2442 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2443 | } |
| 2444 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2445 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2446 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2447 | return -EINVAL; |
| 2448 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2449 | coverage_class = nla_get_u8( |
| 2450 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2451 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2452 | } |
| 2453 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2454 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2455 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2456 | return -EOPNOTSUPP; |
| 2457 | |
| 2458 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2459 | } |
| 2460 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2461 | if (changed) { |
| 2462 | u8 old_retry_short, old_retry_long; |
| 2463 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2464 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2465 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2466 | if (!rdev->ops->set_wiphy_params) |
| 2467 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2468 | |
| 2469 | old_retry_short = rdev->wiphy.retry_short; |
| 2470 | old_retry_long = rdev->wiphy.retry_long; |
| 2471 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2472 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2473 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2474 | |
| 2475 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2476 | rdev->wiphy.retry_short = retry_short; |
| 2477 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2478 | rdev->wiphy.retry_long = retry_long; |
| 2479 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2480 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2481 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2482 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2483 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2484 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2485 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2486 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2487 | if (result) { |
| 2488 | rdev->wiphy.retry_short = old_retry_short; |
| 2489 | rdev->wiphy.retry_long = old_retry_long; |
| 2490 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2491 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2492 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2493 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2494 | } |
| 2495 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2496 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2497 | } |
| 2498 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2499 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2500 | { |
| 2501 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2502 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2503 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2504 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2505 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2506 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2507 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2508 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2509 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2510 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2511 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2512 | chandef->chan->center_freq)) |
| 2513 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2514 | switch (chandef->width) { |
| 2515 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2516 | case NL80211_CHAN_WIDTH_20: |
| 2517 | case NL80211_CHAN_WIDTH_40: |
| 2518 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2519 | cfg80211_get_chandef_type(chandef))) |
| 2520 | return -ENOBUFS; |
| 2521 | break; |
| 2522 | default: |
| 2523 | break; |
| 2524 | } |
| 2525 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2526 | return -ENOBUFS; |
| 2527 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2528 | return -ENOBUFS; |
| 2529 | if (chandef->center_freq2 && |
| 2530 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2531 | return -ENOBUFS; |
| 2532 | return 0; |
| 2533 | } |
| 2534 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2535 | 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] | 2536 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2537 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2538 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2539 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2540 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2541 | void *hdr; |
| 2542 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2543 | if (removal) |
| 2544 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2545 | |
| 2546 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2547 | if (!hdr) |
| 2548 | return -1; |
| 2549 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2550 | if (dev && |
| 2551 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2552 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2553 | goto nla_put_failure; |
| 2554 | |
| 2555 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2556 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2557 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2558 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2559 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2560 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2561 | rdev->devlist_generation ^ |
| 2562 | (cfg80211_rdev_list_generation << 2))) |
| 2563 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2564 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2565 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2566 | int ret; |
| 2567 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2568 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2569 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2570 | if (ret == 0) { |
| 2571 | if (nl80211_send_chandef(msg, &chandef)) |
| 2572 | goto nla_put_failure; |
| 2573 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2576 | if (rdev->ops->get_tx_power) { |
| 2577 | int dbm, ret; |
| 2578 | |
| 2579 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2580 | if (ret == 0 && |
| 2581 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2582 | DBM_TO_MBM(dbm))) |
| 2583 | goto nla_put_failure; |
| 2584 | } |
| 2585 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2586 | if (wdev->ssid_len) { |
| 2587 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2588 | goto nla_put_failure; |
| 2589 | } |
| 2590 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2591 | genlmsg_end(msg, hdr); |
| 2592 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2593 | |
| 2594 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2595 | genlmsg_cancel(msg, hdr); |
| 2596 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2600 | { |
| 2601 | int wp_idx = 0; |
| 2602 | int if_idx = 0; |
| 2603 | int wp_start = cb->args[0]; |
| 2604 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2605 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2606 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2607 | struct wireless_dev *wdev; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2608 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2609 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2610 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2611 | if (!cb->args[2]) { |
| 2612 | struct nl80211_dump_wiphy_state state = { |
| 2613 | .filter_wiphy = -1, |
| 2614 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2615 | |
| 2616 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2617 | if (ret) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2618 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2619 | |
| 2620 | filter_wiphy = state.filter_wiphy; |
| 2621 | |
| 2622 | /* |
| 2623 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2624 | * value needed to determine that parsing is necessary. |
| 2625 | */ |
| 2626 | if (filter_wiphy >= 0) |
| 2627 | cb->args[2] = filter_wiphy + 1; |
| 2628 | else |
| 2629 | cb->args[2] = -1; |
| 2630 | } else if (cb->args[2] > 0) { |
| 2631 | filter_wiphy = cb->args[2] - 1; |
| 2632 | } |
| 2633 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2634 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2635 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2636 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2637 | if (wp_idx < wp_start) { |
| 2638 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2639 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2640 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2641 | |
| 2642 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2643 | continue; |
| 2644 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2645 | if_idx = 0; |
| 2646 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2647 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2648 | if (if_idx < if_start) { |
| 2649 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2650 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2651 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2652 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2653 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2654 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2655 | goto out; |
| 2656 | } |
| 2657 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2658 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2659 | |
| 2660 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2661 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2662 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2663 | cb->args[0] = wp_idx; |
| 2664 | cb->args[1] = if_idx; |
| 2665 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2666 | ret = skb->len; |
| 2667 | out_unlock: |
| 2668 | rtnl_unlock(); |
| 2669 | |
| 2670 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2674 | { |
| 2675 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2677 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2678 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2680 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2681 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2682 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2683 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2684 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2685 | nlmsg_free(msg); |
| 2686 | return -ENOBUFS; |
| 2687 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2688 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2689 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2690 | } |
| 2691 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2692 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2693 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2694 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2695 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2696 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2697 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2698 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2699 | }; |
| 2700 | |
| 2701 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2702 | { |
| 2703 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2704 | int flag; |
| 2705 | |
| 2706 | *mntrflags = 0; |
| 2707 | |
| 2708 | if (!nla) |
| 2709 | return -EINVAL; |
| 2710 | |
| 2711 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2712 | nla, mntr_flags_policy)) |
| 2713 | return -EINVAL; |
| 2714 | |
| 2715 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2716 | if (flags[flag]) |
| 2717 | *mntrflags |= (1<<flag); |
| 2718 | |
| 2719 | return 0; |
| 2720 | } |
| 2721 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2722 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2723 | struct net_device *netdev, u8 use_4addr, |
| 2724 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2725 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2726 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2727 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2728 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2729 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2730 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2731 | |
| 2732 | switch (iftype) { |
| 2733 | case NL80211_IFTYPE_AP_VLAN: |
| 2734 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2735 | return 0; |
| 2736 | break; |
| 2737 | case NL80211_IFTYPE_STATION: |
| 2738 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2739 | return 0; |
| 2740 | break; |
| 2741 | default: |
| 2742 | break; |
| 2743 | } |
| 2744 | |
| 2745 | return -EOPNOTSUPP; |
| 2746 | } |
| 2747 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2748 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2749 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2750 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2751 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2752 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2753 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2754 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2755 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2756 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2757 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2758 | memset(¶ms, 0, sizeof(params)); |
| 2759 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2760 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2761 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2762 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2763 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2764 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2765 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2766 | if (ntype > NL80211_IFTYPE_MAX) |
| 2767 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2770 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2771 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2773 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2774 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2775 | if (netif_running(dev)) |
| 2776 | return -EBUSY; |
| 2777 | |
| 2778 | wdev_lock(wdev); |
| 2779 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2780 | IEEE80211_MAX_MESH_ID_LEN); |
| 2781 | wdev->mesh_id_up_len = |
| 2782 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2783 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2784 | wdev->mesh_id_up_len); |
| 2785 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2786 | } |
| 2787 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2788 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2789 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2790 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2791 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2792 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2793 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2794 | } else { |
| 2795 | params.use_4addr = -1; |
| 2796 | } |
| 2797 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2798 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2799 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2800 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2801 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2802 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2803 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2804 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2805 | |
| 2806 | flags = &_flags; |
| 2807 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2808 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2809 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2810 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2811 | const u8 *mumimo_groups; |
| 2812 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2813 | |
| 2814 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2815 | return -EOPNOTSUPP; |
| 2816 | |
| 2817 | mumimo_groups = |
| 2818 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2819 | |
| 2820 | /* bits 0 and 63 are reserved and must be zero */ |
| 2821 | if ((mumimo_groups[0] & BIT(7)) || |
| 2822 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2823 | return -EINVAL; |
| 2824 | |
| 2825 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2826 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2827 | change = true; |
| 2828 | } |
| 2829 | |
| 2830 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2831 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2832 | |
| 2833 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2834 | return -EOPNOTSUPP; |
| 2835 | |
| 2836 | nla_memcpy(params.macaddr, |
| 2837 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2838 | ETH_ALEN); |
| 2839 | change = true; |
| 2840 | } |
| 2841 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2842 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2843 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2844 | return -EOPNOTSUPP; |
| 2845 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2846 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2847 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2848 | else |
| 2849 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2850 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2851 | if (!err && params.use_4addr != -1) |
| 2852 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2853 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2854 | return err; |
| 2855 | } |
| 2856 | |
| 2857 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2858 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2860 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2861 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2862 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2863 | int err; |
| 2864 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2865 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2866 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2867 | /* to avoid failing a new interface creation due to pending removal */ |
| 2868 | cfg80211_destroy_ifaces(rdev); |
| 2869 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2870 | memset(¶ms, 0, sizeof(params)); |
| 2871 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2872 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2873 | return -EINVAL; |
| 2874 | |
| 2875 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2876 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2877 | if (type > NL80211_IFTYPE_MAX) |
| 2878 | return -EINVAL; |
| 2879 | } |
| 2880 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2881 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2882 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2883 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2884 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2885 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2886 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2887 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2888 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2889 | ETH_ALEN); |
| 2890 | if (!is_valid_ether_addr(params.macaddr)) |
| 2891 | return -EADDRNOTAVAIL; |
| 2892 | } |
| 2893 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2894 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2895 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2896 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2897 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2898 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2899 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2900 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2901 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2902 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2903 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2904 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2905 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2906 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2907 | return -EOPNOTSUPP; |
| 2908 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2910 | if (!msg) |
| 2911 | return -ENOMEM; |
| 2912 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2913 | wdev = rdev_add_virtual_intf(rdev, |
| 2914 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2915 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2916 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2917 | if (WARN_ON(!wdev)) { |
| 2918 | nlmsg_free(msg); |
| 2919 | return -EPROTO; |
| 2920 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2921 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2922 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2923 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2924 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2925 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2926 | wdev->owner_nlportid = info->snd_portid; |
| 2927 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2928 | switch (type) { |
| 2929 | case NL80211_IFTYPE_MESH_POINT: |
| 2930 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2931 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2932 | wdev_lock(wdev); |
| 2933 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2934 | IEEE80211_MAX_MESH_ID_LEN); |
| 2935 | wdev->mesh_id_up_len = |
| 2936 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2937 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2938 | wdev->mesh_id_up_len); |
| 2939 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2940 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2941 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2942 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2943 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2944 | * 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] | 2945 | * through the netdev notifier and must be added here |
| 2946 | */ |
| 2947 | mutex_init(&wdev->mtx); |
| 2948 | INIT_LIST_HEAD(&wdev->event_list); |
| 2949 | spin_lock_init(&wdev->event_lock); |
| 2950 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2951 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2952 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2953 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2954 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2955 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2956 | break; |
| 2957 | default: |
| 2958 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2959 | } |
| 2960 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2961 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2962 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2963 | nlmsg_free(msg); |
| 2964 | return -ENOBUFS; |
| 2965 | } |
| 2966 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2967 | /* |
| 2968 | * For wdevs which have no associated netdev object (e.g. of type |
| 2969 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2970 | * For all other types, the event will be generated from the |
| 2971 | * netdev notifier |
| 2972 | */ |
| 2973 | if (!wdev->netdev) |
| 2974 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2975 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2976 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2980 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2982 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2983 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2984 | if (!rdev->ops->del_virtual_intf) |
| 2985 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2986 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2987 | /* |
| 2988 | * If we remove a wireless device without a netdev then clear |
| 2989 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2990 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2991 | * since the wdev has been freed, unlike with a netdev where |
| 2992 | * we need the dev_put() for the netdev to really be freed. |
| 2993 | */ |
| 2994 | if (!wdev->netdev) |
| 2995 | info->user_ptr[1] = NULL; |
| 2996 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 2997 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2998 | } |
| 2999 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3000 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3001 | { |
| 3002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3003 | struct net_device *dev = info->user_ptr[1]; |
| 3004 | u16 noack_map; |
| 3005 | |
| 3006 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3007 | return -EINVAL; |
| 3008 | |
| 3009 | if (!rdev->ops->set_noack_map) |
| 3010 | return -EOPNOTSUPP; |
| 3011 | |
| 3012 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3013 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3014 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3015 | } |
| 3016 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3017 | struct get_key_cookie { |
| 3018 | struct sk_buff *msg; |
| 3019 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3020 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3021 | }; |
| 3022 | |
| 3023 | static void get_key_callback(void *c, struct key_params *params) |
| 3024 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3025 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3026 | struct get_key_cookie *cookie = c; |
| 3027 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3028 | if ((params->key && |
| 3029 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3030 | params->key_len, params->key)) || |
| 3031 | (params->seq && |
| 3032 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3033 | params->seq_len, params->seq)) || |
| 3034 | (params->cipher && |
| 3035 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3036 | params->cipher))) |
| 3037 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3039 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3040 | if (!key) |
| 3041 | goto nla_put_failure; |
| 3042 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3043 | if ((params->key && |
| 3044 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3045 | params->key_len, params->key)) || |
| 3046 | (params->seq && |
| 3047 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3048 | params->seq_len, params->seq)) || |
| 3049 | (params->cipher && |
| 3050 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3051 | params->cipher))) |
| 3052 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3053 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3054 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3055 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3056 | |
| 3057 | nla_nest_end(cookie->msg, key); |
| 3058 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3059 | return; |
| 3060 | nla_put_failure: |
| 3061 | cookie->error = 1; |
| 3062 | } |
| 3063 | |
| 3064 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3065 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3066 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3067 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3068 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3069 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3070 | const u8 *mac_addr = NULL; |
| 3071 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3072 | struct get_key_cookie cookie = { |
| 3073 | .error = 0, |
| 3074 | }; |
| 3075 | void *hdr; |
| 3076 | struct sk_buff *msg; |
| 3077 | |
| 3078 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3079 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3080 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3081 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3082 | return -EINVAL; |
| 3083 | |
| 3084 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3085 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3086 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3087 | pairwise = !!mac_addr; |
| 3088 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3089 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3090 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3091 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3092 | return -EINVAL; |
| 3093 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3094 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3095 | return -EINVAL; |
| 3096 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3097 | } |
| 3098 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3099 | if (!rdev->ops->get_key) |
| 3100 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3101 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3102 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3103 | return -ENOENT; |
| 3104 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3106 | if (!msg) |
| 3107 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3108 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3109 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3110 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3111 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3112 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3113 | |
| 3114 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3115 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3116 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3117 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3118 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3119 | goto nla_put_failure; |
| 3120 | if (mac_addr && |
| 3121 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3122 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3123 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3124 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3125 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3126 | |
| 3127 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3128 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3129 | |
| 3130 | if (cookie.error) |
| 3131 | goto nla_put_failure; |
| 3132 | |
| 3133 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3134 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3135 | |
| 3136 | nla_put_failure: |
| 3137 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3138 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3139 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3140 | return err; |
| 3141 | } |
| 3142 | |
| 3143 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3144 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3146 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3147 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3148 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3149 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3150 | err = nl80211_parse_key(info, &key); |
| 3151 | if (err) |
| 3152 | return err; |
| 3153 | |
| 3154 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3155 | return -EINVAL; |
| 3156 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3157 | /* only support setting default key */ |
| 3158 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3159 | return -EINVAL; |
| 3160 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3161 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3162 | |
| 3163 | if (key.def) { |
| 3164 | if (!rdev->ops->set_default_key) { |
| 3165 | err = -EOPNOTSUPP; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | |
| 3169 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3170 | if (err) |
| 3171 | goto out; |
| 3172 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3173 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3174 | key.def_uni, key.def_multi); |
| 3175 | |
| 3176 | if (err) |
| 3177 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3178 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3179 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3180 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3181 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3182 | } else { |
| 3183 | if (key.def_uni || !key.def_multi) { |
| 3184 | err = -EINVAL; |
| 3185 | goto out; |
| 3186 | } |
| 3187 | |
| 3188 | if (!rdev->ops->set_default_mgmt_key) { |
| 3189 | err = -EOPNOTSUPP; |
| 3190 | goto out; |
| 3191 | } |
| 3192 | |
| 3193 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3194 | if (err) |
| 3195 | goto out; |
| 3196 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3197 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3198 | if (err) |
| 3199 | goto out; |
| 3200 | |
| 3201 | #ifdef CONFIG_CFG80211_WEXT |
| 3202 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3203 | #endif |
| 3204 | } |
| 3205 | |
| 3206 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3207 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3208 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3209 | return err; |
| 3210 | } |
| 3211 | |
| 3212 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3215 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3216 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3217 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3218 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3219 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3220 | err = nl80211_parse_key(info, &key); |
| 3221 | if (err) |
| 3222 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3223 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3224 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3225 | return -EINVAL; |
| 3226 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3227 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3228 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3229 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3230 | if (key.type == -1) { |
| 3231 | if (mac_addr) |
| 3232 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3233 | else |
| 3234 | key.type = NL80211_KEYTYPE_GROUP; |
| 3235 | } |
| 3236 | |
| 3237 | /* for now */ |
| 3238 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3239 | key.type != NL80211_KEYTYPE_GROUP) |
| 3240 | return -EINVAL; |
| 3241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3242 | if (!rdev->ops->add_key) |
| 3243 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3244 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3245 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3246 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3247 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3248 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3249 | |
| 3250 | wdev_lock(dev->ieee80211_ptr); |
| 3251 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3252 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3253 | err = rdev_add_key(rdev, dev, key.idx, |
| 3254 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3255 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3256 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3257 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3258 | return err; |
| 3259 | } |
| 3260 | |
| 3261 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3262 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3264 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3265 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3266 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3267 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3268 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3269 | err = nl80211_parse_key(info, &key); |
| 3270 | if (err) |
| 3271 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3272 | |
| 3273 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3274 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3275 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3276 | if (key.type == -1) { |
| 3277 | if (mac_addr) |
| 3278 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3279 | else |
| 3280 | key.type = NL80211_KEYTYPE_GROUP; |
| 3281 | } |
| 3282 | |
| 3283 | /* for now */ |
| 3284 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3285 | key.type != NL80211_KEYTYPE_GROUP) |
| 3286 | return -EINVAL; |
| 3287 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3288 | if (!rdev->ops->del_key) |
| 3289 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3290 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3291 | wdev_lock(dev->ieee80211_ptr); |
| 3292 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3293 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3294 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3295 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3296 | err = -ENOENT; |
| 3297 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3298 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3299 | err = rdev_del_key(rdev, dev, key.idx, |
| 3300 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3301 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3302 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3303 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3304 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3305 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3306 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3307 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3308 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3309 | } |
| 3310 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3311 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3312 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3313 | return err; |
| 3314 | } |
| 3315 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3316 | /* This function returns an error or the number of nested attributes */ |
| 3317 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3318 | { |
| 3319 | struct nlattr *attr; |
| 3320 | int n_entries = 0, tmp; |
| 3321 | |
| 3322 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3323 | if (nla_len(attr) != ETH_ALEN) |
| 3324 | return -EINVAL; |
| 3325 | |
| 3326 | n_entries++; |
| 3327 | } |
| 3328 | |
| 3329 | return n_entries; |
| 3330 | } |
| 3331 | |
| 3332 | /* |
| 3333 | * This function parses ACL information and allocates memory for ACL data. |
| 3334 | * On successful return, the calling function is responsible to free the |
| 3335 | * ACL buffer returned by this function. |
| 3336 | */ |
| 3337 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3338 | struct genl_info *info) |
| 3339 | { |
| 3340 | enum nl80211_acl_policy acl_policy; |
| 3341 | struct nlattr *attr; |
| 3342 | struct cfg80211_acl_data *acl; |
| 3343 | int i = 0, n_entries, tmp; |
| 3344 | |
| 3345 | if (!wiphy->max_acl_mac_addrs) |
| 3346 | return ERR_PTR(-EOPNOTSUPP); |
| 3347 | |
| 3348 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3349 | return ERR_PTR(-EINVAL); |
| 3350 | |
| 3351 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3352 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3353 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3354 | return ERR_PTR(-EINVAL); |
| 3355 | |
| 3356 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3357 | return ERR_PTR(-EINVAL); |
| 3358 | |
| 3359 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3360 | if (n_entries < 0) |
| 3361 | return ERR_PTR(n_entries); |
| 3362 | |
| 3363 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3364 | return ERR_PTR(-ENOTSUPP); |
| 3365 | |
| 3366 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3367 | GFP_KERNEL); |
| 3368 | if (!acl) |
| 3369 | return ERR_PTR(-ENOMEM); |
| 3370 | |
| 3371 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3372 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3373 | i++; |
| 3374 | } |
| 3375 | |
| 3376 | acl->n_acl_entries = n_entries; |
| 3377 | acl->acl_policy = acl_policy; |
| 3378 | |
| 3379 | return acl; |
| 3380 | } |
| 3381 | |
| 3382 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3383 | { |
| 3384 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3385 | struct net_device *dev = info->user_ptr[1]; |
| 3386 | struct cfg80211_acl_data *acl; |
| 3387 | int err; |
| 3388 | |
| 3389 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3390 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3391 | return -EOPNOTSUPP; |
| 3392 | |
| 3393 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3394 | return -EINVAL; |
| 3395 | |
| 3396 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3397 | if (IS_ERR(acl)) |
| 3398 | return PTR_ERR(acl); |
| 3399 | |
| 3400 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3401 | |
| 3402 | kfree(acl); |
| 3403 | |
| 3404 | return err; |
| 3405 | } |
| 3406 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3407 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3408 | u8 *rates, u8 rates_len) |
| 3409 | { |
| 3410 | u8 i; |
| 3411 | u32 mask = 0; |
| 3412 | |
| 3413 | for (i = 0; i < rates_len; i++) { |
| 3414 | int rate = (rates[i] & 0x7f) * 5; |
| 3415 | int ridx; |
| 3416 | |
| 3417 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3418 | struct ieee80211_rate *srate = |
| 3419 | &sband->bitrates[ridx]; |
| 3420 | if (rate == srate->bitrate) { |
| 3421 | mask |= 1 << ridx; |
| 3422 | break; |
| 3423 | } |
| 3424 | } |
| 3425 | if (ridx == sband->n_bitrates) |
| 3426 | return 0; /* rate not found */ |
| 3427 | } |
| 3428 | |
| 3429 | return mask; |
| 3430 | } |
| 3431 | |
| 3432 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3433 | u8 *rates, u8 rates_len, |
| 3434 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3435 | { |
| 3436 | u8 i; |
| 3437 | |
| 3438 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3439 | |
| 3440 | for (i = 0; i < rates_len; i++) { |
| 3441 | int ridx, rbit; |
| 3442 | |
| 3443 | ridx = rates[i] / 8; |
| 3444 | rbit = BIT(rates[i] % 8); |
| 3445 | |
| 3446 | /* check validity */ |
| 3447 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3448 | return false; |
| 3449 | |
| 3450 | /* check availability */ |
| 3451 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3452 | mcs[ridx] |= rbit; |
| 3453 | else |
| 3454 | return false; |
| 3455 | } |
| 3456 | |
| 3457 | return true; |
| 3458 | } |
| 3459 | |
| 3460 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3461 | { |
| 3462 | u16 mcs_mask = 0; |
| 3463 | |
| 3464 | switch (vht_mcs_map) { |
| 3465 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3466 | break; |
| 3467 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3468 | mcs_mask = 0x00FF; |
| 3469 | break; |
| 3470 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3471 | mcs_mask = 0x01FF; |
| 3472 | break; |
| 3473 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3474 | mcs_mask = 0x03FF; |
| 3475 | break; |
| 3476 | default: |
| 3477 | break; |
| 3478 | } |
| 3479 | |
| 3480 | return mcs_mask; |
| 3481 | } |
| 3482 | |
| 3483 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3484 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3485 | { |
| 3486 | u8 nss; |
| 3487 | |
| 3488 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3489 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3490 | vht_mcs_map >>= 2; |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3495 | struct nl80211_txrate_vht *txrate, |
| 3496 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3497 | { |
| 3498 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3499 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3500 | u8 i; |
| 3501 | |
| 3502 | if (!sband->vht_cap.vht_supported) |
| 3503 | return false; |
| 3504 | |
| 3505 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3506 | |
| 3507 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3508 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3509 | |
| 3510 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3511 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3512 | mcs[i] = txrate->mcs[i]; |
| 3513 | else |
| 3514 | return false; |
| 3515 | } |
| 3516 | |
| 3517 | return true; |
| 3518 | } |
| 3519 | |
| 3520 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3521 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3522 | .len = NL80211_MAX_SUPP_RATES }, |
| 3523 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3524 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3525 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3526 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3527 | }; |
| 3528 | |
| 3529 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3530 | struct cfg80211_bitrate_mask *mask) |
| 3531 | { |
| 3532 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3534 | int rem, i; |
| 3535 | struct nlattr *tx_rates; |
| 3536 | struct ieee80211_supported_band *sband; |
| 3537 | u16 vht_tx_mcs_map; |
| 3538 | |
| 3539 | memset(mask, 0, sizeof(*mask)); |
| 3540 | /* Default to all rates enabled */ |
| 3541 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3542 | sband = rdev->wiphy.bands[i]; |
| 3543 | |
| 3544 | if (!sband) |
| 3545 | continue; |
| 3546 | |
| 3547 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3548 | memcpy(mask->control[i].ht_mcs, |
| 3549 | sband->ht_cap.mcs.rx_mask, |
| 3550 | sizeof(mask->control[i].ht_mcs)); |
| 3551 | |
| 3552 | if (!sband->vht_cap.vht_supported) |
| 3553 | continue; |
| 3554 | |
| 3555 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3556 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3557 | } |
| 3558 | |
| 3559 | /* if no rates are given set it back to the defaults */ |
| 3560 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3561 | goto out; |
| 3562 | |
| 3563 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3564 | * directly to the enum nl80211_band values used in cfg80211. |
| 3565 | */ |
| 3566 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3567 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3568 | enum nl80211_band band = nla_type(tx_rates); |
| 3569 | int err; |
| 3570 | |
| 3571 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3572 | return -EINVAL; |
| 3573 | sband = rdev->wiphy.bands[band]; |
| 3574 | if (sband == NULL) |
| 3575 | return -EINVAL; |
| 3576 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 3577 | nla_len(tx_rates), nl80211_txattr_policy); |
| 3578 | if (err) |
| 3579 | return err; |
| 3580 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3581 | mask->control[band].legacy = rateset_to_mask( |
| 3582 | sband, |
| 3583 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3584 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3585 | if ((mask->control[band].legacy == 0) && |
| 3586 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3587 | return -EINVAL; |
| 3588 | } |
| 3589 | if (tb[NL80211_TXRATE_HT]) { |
| 3590 | if (!ht_rateset_to_mask( |
| 3591 | sband, |
| 3592 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3593 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3594 | mask->control[band].ht_mcs)) |
| 3595 | return -EINVAL; |
| 3596 | } |
| 3597 | if (tb[NL80211_TXRATE_VHT]) { |
| 3598 | if (!vht_set_mcs_mask( |
| 3599 | sband, |
| 3600 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3601 | mask->control[band].vht_mcs)) |
| 3602 | return -EINVAL; |
| 3603 | } |
| 3604 | if (tb[NL80211_TXRATE_GI]) { |
| 3605 | mask->control[band].gi = |
| 3606 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3607 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3608 | return -EINVAL; |
| 3609 | } |
| 3610 | |
| 3611 | if (mask->control[band].legacy == 0) { |
| 3612 | /* don't allow empty legacy rates if HT or VHT |
| 3613 | * are not even supported. |
| 3614 | */ |
| 3615 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3616 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3617 | return -EINVAL; |
| 3618 | |
| 3619 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3620 | if (mask->control[band].ht_mcs[i]) |
| 3621 | goto out; |
| 3622 | |
| 3623 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3624 | if (mask->control[band].vht_mcs[i]) |
| 3625 | goto out; |
| 3626 | |
| 3627 | /* legacy and mcs rates may not be both empty */ |
| 3628 | return -EINVAL; |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | out: |
| 3633 | return 0; |
| 3634 | } |
| 3635 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3636 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3637 | enum nl80211_band band, |
| 3638 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3639 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3640 | u32 count_ht, count_vht, i; |
| 3641 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3642 | |
| 3643 | /* Allow only one rate */ |
| 3644 | if (hweight32(rate) > 1) |
| 3645 | return -EINVAL; |
| 3646 | |
| 3647 | count_ht = 0; |
| 3648 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3649 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3650 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3651 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3652 | count_ht++; |
| 3653 | if (count_ht > 1) |
| 3654 | return -EINVAL; |
| 3655 | } |
| 3656 | if (count_ht && rate) |
| 3657 | return -EINVAL; |
| 3658 | } |
| 3659 | |
| 3660 | count_vht = 0; |
| 3661 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3662 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3663 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3664 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3665 | count_vht++; |
| 3666 | if (count_vht > 1) |
| 3667 | return -EINVAL; |
| 3668 | } |
| 3669 | if (count_vht && rate) |
| 3670 | return -EINVAL; |
| 3671 | } |
| 3672 | |
| 3673 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3674 | return -EINVAL; |
| 3675 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3676 | if (rate && |
| 3677 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3678 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3679 | return -EINVAL; |
| 3680 | if (count_ht && |
| 3681 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3682 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3683 | return -EINVAL; |
| 3684 | if (count_vht && |
| 3685 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3686 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3687 | return -EINVAL; |
| 3688 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3689 | return 0; |
| 3690 | } |
| 3691 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3692 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3693 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3694 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3695 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3696 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3697 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3698 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3699 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3700 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3701 | return -EINVAL; |
| 3702 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3703 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3704 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3705 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3706 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3707 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3708 | if (!bcn->head_len) |
| 3709 | return -EINVAL; |
| 3710 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3713 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3714 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3715 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3716 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3717 | } |
| 3718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3719 | if (!haveinfo) |
| 3720 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3721 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3722 | if (attrs[NL80211_ATTR_IE]) { |
| 3723 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3724 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3725 | } |
| 3726 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3727 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3728 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3729 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3730 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3731 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3732 | } |
| 3733 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3734 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3735 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3736 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3737 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3738 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3739 | } |
| 3740 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3741 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3742 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3743 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3744 | } |
| 3745 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3746 | return 0; |
| 3747 | } |
| 3748 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3749 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3750 | struct cfg80211_ap_settings *params) |
| 3751 | { |
| 3752 | struct wireless_dev *wdev; |
| 3753 | bool ret = false; |
| 3754 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3755 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3756 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3757 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3758 | continue; |
| 3759 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3760 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3761 | continue; |
| 3762 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3763 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3764 | ret = true; |
| 3765 | break; |
| 3766 | } |
| 3767 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3768 | return ret; |
| 3769 | } |
| 3770 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3771 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3772 | enum nl80211_auth_type auth_type, |
| 3773 | enum nl80211_commands cmd) |
| 3774 | { |
| 3775 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3776 | return false; |
| 3777 | |
| 3778 | switch (cmd) { |
| 3779 | case NL80211_CMD_AUTHENTICATE: |
| 3780 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3781 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3782 | return false; |
Jouni Malinen | e20f90f | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3783 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3784 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3785 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3786 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3787 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3788 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3789 | return true; |
| 3790 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 6fe0e6f | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 3791 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3792 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3793 | return false; |
Srinivas Dasari | 6fe0e6f | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 3794 | |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3795 | /* FILS with SK PFS or PK not supported yet */ |
| 3796 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3797 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3798 | return false; |
| 3799 | if (!wiphy_ext_feature_isset( |
| 3800 | &rdev->wiphy, |
| 3801 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 3802 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 3803 | return false; |
| 3804 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3805 | case NL80211_CMD_START_AP: |
| 3806 | /* SAE not supported yet */ |
| 3807 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3808 | return false; |
Jouni Malinen | e20f90f | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3809 | /* FILS not supported yet */ |
| 3810 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3811 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3812 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3813 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3814 | return true; |
| 3815 | default: |
| 3816 | return false; |
| 3817 | } |
| 3818 | } |
| 3819 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3820 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3821 | { |
| 3822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3823 | struct net_device *dev = info->user_ptr[1]; |
| 3824 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3825 | struct cfg80211_ap_settings params; |
| 3826 | int err; |
| 3827 | |
| 3828 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3829 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3830 | return -EOPNOTSUPP; |
| 3831 | |
| 3832 | if (!rdev->ops->start_ap) |
| 3833 | return -EOPNOTSUPP; |
| 3834 | |
| 3835 | if (wdev->beacon_interval) |
| 3836 | return -EALREADY; |
| 3837 | |
| 3838 | memset(¶ms, 0, sizeof(params)); |
| 3839 | |
| 3840 | /* these are required for START_AP */ |
| 3841 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3842 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3843 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3844 | return -EINVAL; |
| 3845 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3846 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3847 | if (err) |
| 3848 | return err; |
| 3849 | |
| 3850 | params.beacon_interval = |
| 3851 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3852 | params.dtim_period = |
| 3853 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3854 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3855 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3856 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3857 | if (err) |
| 3858 | return err; |
| 3859 | |
| 3860 | /* |
| 3861 | * In theory, some of these attributes should be required here |
| 3862 | * but since they were not used when the command was originally |
| 3863 | * added, keep them optional for old user space programs to let |
| 3864 | * them continue to work with drivers that do not need the |
| 3865 | * additional information -- drivers must check! |
| 3866 | */ |
| 3867 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3868 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3869 | params.ssid_len = |
| 3870 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3871 | if (params.ssid_len == 0 || |
| 3872 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3873 | return -EINVAL; |
| 3874 | } |
| 3875 | |
| 3876 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3877 | params.hidden_ssid = nla_get_u32( |
| 3878 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3879 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3880 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3881 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3882 | return -EINVAL; |
| 3883 | } |
| 3884 | |
| 3885 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3886 | |
| 3887 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3888 | params.auth_type = nla_get_u32( |
| 3889 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3890 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3891 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3892 | return -EINVAL; |
| 3893 | } else |
| 3894 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3895 | |
| 3896 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3897 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3898 | if (err) |
| 3899 | return err; |
| 3900 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3901 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3902 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3903 | return -EOPNOTSUPP; |
| 3904 | params.inactivity_timeout = nla_get_u16( |
| 3905 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3906 | } |
| 3907 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3908 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3909 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3910 | return -EINVAL; |
| 3911 | params.p2p_ctwindow = |
| 3912 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3913 | if (params.p2p_ctwindow > 127) |
| 3914 | return -EINVAL; |
| 3915 | if (params.p2p_ctwindow != 0 && |
| 3916 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3917 | return -EINVAL; |
| 3918 | } |
| 3919 | |
| 3920 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3921 | u8 tmp; |
| 3922 | |
| 3923 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3924 | return -EINVAL; |
| 3925 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3926 | if (tmp > 1) |
| 3927 | return -EINVAL; |
| 3928 | params.p2p_opp_ps = tmp; |
| 3929 | if (params.p2p_opp_ps != 0 && |
| 3930 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3931 | return -EINVAL; |
| 3932 | } |
| 3933 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3934 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3935 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3936 | if (err) |
| 3937 | return err; |
| 3938 | } else if (wdev->preset_chandef.chan) { |
| 3939 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3940 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3941 | return -EINVAL; |
| 3942 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3943 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3944 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3945 | return -EINVAL; |
| 3946 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3947 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 3948 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 3949 | if (err) |
| 3950 | return err; |
| 3951 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3952 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 3953 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3954 | if (err) |
| 3955 | return err; |
| 3956 | } |
| 3957 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3958 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3959 | params.smps_mode = |
| 3960 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3961 | switch (params.smps_mode) { |
| 3962 | case NL80211_SMPS_OFF: |
| 3963 | break; |
| 3964 | case NL80211_SMPS_STATIC: |
| 3965 | if (!(rdev->wiphy.features & |
| 3966 | NL80211_FEATURE_STATIC_SMPS)) |
| 3967 | return -EINVAL; |
| 3968 | break; |
| 3969 | case NL80211_SMPS_DYNAMIC: |
| 3970 | if (!(rdev->wiphy.features & |
| 3971 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3972 | return -EINVAL; |
| 3973 | break; |
| 3974 | default: |
| 3975 | return -EINVAL; |
| 3976 | } |
| 3977 | } else { |
| 3978 | params.smps_mode = NL80211_SMPS_OFF; |
| 3979 | } |
| 3980 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3981 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3982 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3983 | return -EOPNOTSUPP; |
| 3984 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3985 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3986 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3987 | if (IS_ERR(params.acl)) |
| 3988 | return PTR_ERR(params.acl); |
| 3989 | } |
| 3990 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3991 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3992 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3993 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3994 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3995 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3996 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3997 | wdev->ssid_len = params.ssid_len; |
| 3998 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3999 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4000 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4001 | |
| 4002 | kfree(params.acl); |
| 4003 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4004 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4005 | } |
| 4006 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4007 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4008 | { |
| 4009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4010 | struct net_device *dev = info->user_ptr[1]; |
| 4011 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4012 | struct cfg80211_beacon_data params; |
| 4013 | int err; |
| 4014 | |
| 4015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4016 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4017 | return -EOPNOTSUPP; |
| 4018 | |
| 4019 | if (!rdev->ops->change_beacon) |
| 4020 | return -EOPNOTSUPP; |
| 4021 | |
| 4022 | if (!wdev->beacon_interval) |
| 4023 | return -EINVAL; |
| 4024 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4025 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4026 | if (err) |
| 4027 | return err; |
| 4028 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4029 | wdev_lock(wdev); |
| 4030 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4031 | wdev_unlock(wdev); |
| 4032 | |
| 4033 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
| 4036 | 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] | 4037 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4039 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4040 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4041 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4042 | } |
| 4043 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4044 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4045 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4046 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4047 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4048 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4049 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4050 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4051 | }; |
| 4052 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4053 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4054 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4055 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4056 | { |
| 4057 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4058 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4059 | int flag; |
| 4060 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4061 | /* |
| 4062 | * Try parsing the new attribute first so userspace |
| 4063 | * can specify both for older kernels. |
| 4064 | */ |
| 4065 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4066 | if (nla) { |
| 4067 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4068 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4069 | sta_flags = nla_data(nla); |
| 4070 | params->sta_flags_mask = sta_flags->mask; |
| 4071 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4072 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4073 | if ((params->sta_flags_mask | |
| 4074 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4075 | return -EINVAL; |
| 4076 | return 0; |
| 4077 | } |
| 4078 | |
| 4079 | /* if present, parse the old attribute */ |
| 4080 | |
| 4081 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | if (!nla) |
| 4083 | return 0; |
| 4084 | |
| 4085 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 4086 | nla, sta_flags_policy)) |
| 4087 | return -EINVAL; |
| 4088 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4089 | /* |
| 4090 | * Only allow certain flags for interface types so that |
| 4091 | * other attributes are silently ignored. Remember that |
| 4092 | * this is backward compatibility code with old userspace |
| 4093 | * and shouldn't be hit in other cases anyway. |
| 4094 | */ |
| 4095 | switch (iftype) { |
| 4096 | case NL80211_IFTYPE_AP: |
| 4097 | case NL80211_IFTYPE_AP_VLAN: |
| 4098 | case NL80211_IFTYPE_P2P_GO: |
| 4099 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4100 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4101 | BIT(NL80211_STA_FLAG_WME) | |
| 4102 | BIT(NL80211_STA_FLAG_MFP); |
| 4103 | break; |
| 4104 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4105 | case NL80211_IFTYPE_STATION: |
| 4106 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4107 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4108 | break; |
| 4109 | case NL80211_IFTYPE_MESH_POINT: |
| 4110 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4111 | BIT(NL80211_STA_FLAG_MFP) | |
| 4112 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4113 | default: |
| 4114 | return -EINVAL; |
| 4115 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4116 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4117 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4118 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4119 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4120 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4121 | /* no longer support new API additions in old API */ |
| 4122 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4123 | return -EINVAL; |
| 4124 | } |
| 4125 | } |
| 4126 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4127 | return 0; |
| 4128 | } |
| 4129 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4130 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4131 | int attr) |
| 4132 | { |
| 4133 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4134 | u32 bitrate; |
| 4135 | u16 bitrate_compat; |
Matthias Kaehlcke | 7164cb7 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 4136 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4137 | |
| 4138 | rate = nla_nest_start(msg, attr); |
| 4139 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4140 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4141 | |
| 4142 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4143 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4144 | /* report 16-bit bitrate only if we can */ |
| 4145 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4146 | if (bitrate > 0 && |
| 4147 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4148 | return false; |
| 4149 | if (bitrate_compat > 0 && |
| 4150 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4151 | return false; |
| 4152 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4153 | switch (info->bw) { |
| 4154 | case RATE_INFO_BW_5: |
| 4155 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4156 | break; |
| 4157 | case RATE_INFO_BW_10: |
| 4158 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4159 | break; |
| 4160 | default: |
| 4161 | WARN_ON(1); |
| 4162 | /* fall through */ |
| 4163 | case RATE_INFO_BW_20: |
| 4164 | rate_flg = 0; |
| 4165 | break; |
| 4166 | case RATE_INFO_BW_40: |
| 4167 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4168 | break; |
| 4169 | case RATE_INFO_BW_80: |
| 4170 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4171 | break; |
| 4172 | case RATE_INFO_BW_160: |
| 4173 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4174 | break; |
| 4175 | } |
| 4176 | |
| 4177 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4178 | return false; |
| 4179 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4180 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4181 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4182 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4183 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4184 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4185 | return false; |
| 4186 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4187 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4188 | return false; |
| 4189 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4190 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4191 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4192 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4193 | return false; |
| 4194 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4195 | |
| 4196 | nla_nest_end(msg, rate); |
| 4197 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4200 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4201 | int id) |
| 4202 | { |
| 4203 | void *attr; |
| 4204 | int i = 0; |
| 4205 | |
| 4206 | if (!mask) |
| 4207 | return true; |
| 4208 | |
| 4209 | attr = nla_nest_start(msg, id); |
| 4210 | if (!attr) |
| 4211 | return false; |
| 4212 | |
| 4213 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4214 | if (!(mask & BIT(i))) |
| 4215 | continue; |
| 4216 | |
| 4217 | if (nla_put_u8(msg, i, signal[i])) |
| 4218 | return false; |
| 4219 | } |
| 4220 | |
| 4221 | nla_nest_end(msg, attr); |
| 4222 | |
| 4223 | return true; |
| 4224 | } |
| 4225 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4226 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4227 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4228 | struct cfg80211_registered_device *rdev, |
| 4229 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4230 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4231 | { |
| 4232 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4233 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4234 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4235 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4236 | if (!hdr) |
| 4237 | return -1; |
| 4238 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4239 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4240 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4241 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4242 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4243 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4244 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4245 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4246 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4247 | |
| 4248 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4249 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4250 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4251 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4252 | sinfo->memb)) \ |
| 4253 | goto nla_put_failure; \ |
| 4254 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4255 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4256 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4257 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4258 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4259 | goto nla_put_failure; \ |
| 4260 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4261 | |
| 4262 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4263 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4264 | |
| 4265 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4266 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4267 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4268 | (u32)sinfo->rx_bytes)) |
| 4269 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4270 | |
| 4271 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4272 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4273 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4274 | (u32)sinfo->tx_bytes)) |
| 4275 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4276 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4277 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4278 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4279 | PUT_SINFO(LLID, llid, u16); |
| 4280 | PUT_SINFO(PLID, plid, u16); |
| 4281 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4282 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4283 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4284 | switch (rdev->wiphy.signal_type) { |
| 4285 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4286 | PUT_SINFO(SIGNAL, signal, u8); |
| 4287 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4288 | break; |
| 4289 | default: |
| 4290 | break; |
| 4291 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4292 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4293 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4294 | sinfo->chain_signal, |
| 4295 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4296 | goto nla_put_failure; |
| 4297 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4298 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4299 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4300 | sinfo->chain_signal_avg, |
| 4301 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4302 | goto nla_put_failure; |
| 4303 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4304 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4305 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4306 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4307 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4308 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4309 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4310 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4311 | NL80211_STA_INFO_RX_BITRATE)) |
| 4312 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4313 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4314 | |
| 4315 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4316 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4317 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4318 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4319 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4320 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4321 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4322 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4323 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4324 | |
| 4325 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4326 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4327 | if (!bss_param) |
| 4328 | goto nla_put_failure; |
| 4329 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4330 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4331 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4332 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4333 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4334 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4335 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4336 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4337 | sinfo->bss_param.dtim_period) || |
| 4338 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4339 | sinfo->bss_param.beacon_interval)) |
| 4340 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4341 | |
| 4342 | nla_nest_end(msg, bss_param); |
| 4343 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4344 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4345 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4346 | sizeof(struct nl80211_sta_flag_update), |
| 4347 | &sinfo->sta_flags)) |
| 4348 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4349 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4350 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4351 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4352 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4353 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4354 | |
| 4355 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4356 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4357 | |
| 4358 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4359 | struct nlattr *tidsattr; |
| 4360 | int tid; |
| 4361 | |
| 4362 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4363 | if (!tidsattr) |
| 4364 | goto nla_put_failure; |
| 4365 | |
| 4366 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4367 | struct cfg80211_tid_stats *tidstats; |
| 4368 | struct nlattr *tidattr; |
| 4369 | |
| 4370 | tidstats = &sinfo->pertid[tid]; |
| 4371 | |
| 4372 | if (!tidstats->filled) |
| 4373 | continue; |
| 4374 | |
| 4375 | tidattr = nla_nest_start(msg, tid + 1); |
| 4376 | if (!tidattr) |
| 4377 | goto nla_put_failure; |
| 4378 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4379 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4380 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4381 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4382 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4383 | goto nla_put_failure; \ |
| 4384 | } while (0) |
| 4385 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4386 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4387 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4388 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4389 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4390 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4391 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4392 | nla_nest_end(msg, tidattr); |
| 4393 | } |
| 4394 | |
| 4395 | nla_nest_end(msg, tidsattr); |
| 4396 | } |
| 4397 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4398 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4399 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4400 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4401 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4402 | sinfo->assoc_req_ies)) |
| 4403 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4404 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4405 | genlmsg_end(msg, hdr); |
| 4406 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4407 | |
| 4408 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4409 | genlmsg_cancel(msg, hdr); |
| 4410 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4411 | } |
| 4412 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4413 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4414 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4415 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4416 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4417 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4418 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4419 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4420 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4421 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4422 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4423 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4424 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4425 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4426 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4427 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4428 | if (!wdev->netdev) { |
| 4429 | err = -EINVAL; |
| 4430 | goto out_err; |
| 4431 | } |
| 4432 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4433 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4434 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4435 | goto out_err; |
| 4436 | } |
| 4437 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4438 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4439 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4440 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4441 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4442 | if (err == -ENOENT) |
| 4443 | break; |
| 4444 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4445 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4446 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4447 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4448 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4449 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4450 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4451 | &sinfo) < 0) |
| 4452 | goto out; |
| 4453 | |
| 4454 | sta_idx++; |
| 4455 | } |
| 4456 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4457 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4458 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4459 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4460 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4461 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4462 | |
| 4463 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4464 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4465 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4466 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4467 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4469 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4470 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4471 | struct sk_buff *msg; |
| 4472 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4474 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4475 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4476 | |
| 4477 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4478 | return -EINVAL; |
| 4479 | |
| 4480 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | if (!rdev->ops->get_station) |
| 4483 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4484 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4485 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4486 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4487 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4488 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4489 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4490 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4491 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4492 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4493 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4494 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4495 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | nlmsg_free(msg); |
| 4497 | return -ENOBUFS; |
| 4498 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4499 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4501 | } |
| 4502 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4503 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4504 | struct station_parameters *params, |
| 4505 | enum cfg80211_station_type statype) |
| 4506 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4507 | if (params->listen_interval != -1 && |
| 4508 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4509 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4510 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4511 | if (params->support_p2p_ps != -1 && |
| 4512 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4513 | return -EINVAL; |
| 4514 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4515 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4516 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4517 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4518 | return -EINVAL; |
| 4519 | |
| 4520 | /* When you run into this, adjust the code below for the new flag */ |
| 4521 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4522 | |
| 4523 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4524 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4525 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4526 | /* |
| 4527 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4528 | * code doesn't have the bug of including TDLS in the |
| 4529 | * mask everywhere. |
| 4530 | */ |
| 4531 | if (params->sta_flags_mask & |
| 4532 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4533 | BIT(NL80211_STA_FLAG_MFP) | |
| 4534 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4535 | return -EINVAL; |
| 4536 | break; |
| 4537 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4538 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4539 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4540 | return -EINVAL; |
| 4541 | /* ignore since it can't change */ |
| 4542 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4543 | break; |
| 4544 | default: |
| 4545 | /* disallow mesh-specific things */ |
| 4546 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4547 | return -EINVAL; |
| 4548 | if (params->local_pm) |
| 4549 | return -EINVAL; |
| 4550 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4551 | return -EINVAL; |
| 4552 | } |
| 4553 | |
| 4554 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4555 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4556 | /* TDLS can't be set, ... */ |
| 4557 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4558 | return -EINVAL; |
| 4559 | /* |
| 4560 | * ... but don't bother the driver with it. This works around |
| 4561 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4562 | * TLDS_PEER flag in the mask even for AP mode. |
| 4563 | */ |
| 4564 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4565 | } |
| 4566 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4567 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4568 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4569 | /* reject other things that can't change */ |
| 4570 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4571 | return -EINVAL; |
| 4572 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4573 | return -EINVAL; |
| 4574 | if (params->supported_rates) |
| 4575 | return -EINVAL; |
| 4576 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4577 | return -EINVAL; |
| 4578 | } |
| 4579 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4580 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4581 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4582 | if (params->vlan) |
| 4583 | return -EINVAL; |
| 4584 | } |
| 4585 | |
| 4586 | switch (statype) { |
| 4587 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4588 | /* Use this only for authorizing/unauthorizing a station */ |
| 4589 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4590 | return -EOPNOTSUPP; |
| 4591 | break; |
| 4592 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4593 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4594 | /* accept only the listed bits */ |
| 4595 | if (params->sta_flags_mask & |
| 4596 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4597 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4598 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4599 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4600 | BIT(NL80211_STA_FLAG_WME) | |
| 4601 | BIT(NL80211_STA_FLAG_MFP))) |
| 4602 | return -EINVAL; |
| 4603 | |
| 4604 | /* but authenticated/associated only if driver handles it */ |
| 4605 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4606 | params->sta_flags_mask & |
| 4607 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4608 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4609 | return -EINVAL; |
| 4610 | break; |
| 4611 | case CFG80211_STA_IBSS: |
| 4612 | case CFG80211_STA_AP_STA: |
| 4613 | /* reject any changes other than AUTHORIZED */ |
| 4614 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4615 | return -EINVAL; |
| 4616 | break; |
| 4617 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4618 | /* reject any changes other than AUTHORIZED or WME */ |
| 4619 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4620 | BIT(NL80211_STA_FLAG_WME))) |
| 4621 | return -EINVAL; |
| 4622 | /* force (at least) rates when authorizing */ |
| 4623 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4624 | !params->supported_rates) |
| 4625 | return -EINVAL; |
| 4626 | break; |
| 4627 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4628 | /* reject any changes */ |
| 4629 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4630 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4631 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4632 | return -EINVAL; |
| 4633 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4634 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4635 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4636 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4637 | return -EINVAL; |
| 4638 | break; |
| 4639 | } |
| 4640 | |
| 4641 | return 0; |
| 4642 | } |
| 4643 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4644 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4645 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4646 | * 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] | 4647 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4648 | static struct net_device *get_vlan(struct genl_info *info, |
| 4649 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4650 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4651 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4652 | struct net_device *v; |
| 4653 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4654 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4655 | if (!vlanattr) |
| 4656 | return NULL; |
| 4657 | |
| 4658 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4659 | if (!v) |
| 4660 | return ERR_PTR(-ENODEV); |
| 4661 | |
| 4662 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4663 | ret = -EINVAL; |
| 4664 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4665 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4666 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4667 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4668 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4669 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4670 | ret = -EINVAL; |
| 4671 | goto error; |
| 4672 | } |
| 4673 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4674 | if (!netif_running(v)) { |
| 4675 | ret = -ENETDOWN; |
| 4676 | goto error; |
| 4677 | } |
| 4678 | |
| 4679 | return v; |
| 4680 | error: |
| 4681 | dev_put(v); |
| 4682 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4683 | } |
| 4684 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4685 | static const struct nla_policy |
| 4686 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4687 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4688 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4689 | }; |
| 4690 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4691 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4692 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4693 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4694 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4695 | struct nlattr *nla; |
| 4696 | int err; |
| 4697 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4698 | /* parse WME attributes if present */ |
| 4699 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4700 | return 0; |
| 4701 | |
| 4702 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4703 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4704 | nl80211_sta_wme_policy); |
| 4705 | if (err) |
| 4706 | return err; |
| 4707 | |
| 4708 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4709 | params->uapsd_queues = nla_get_u8( |
| 4710 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4711 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4712 | return -EINVAL; |
| 4713 | |
| 4714 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4715 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4716 | |
| 4717 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4718 | return -EINVAL; |
| 4719 | |
| 4720 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4721 | |
| 4722 | return 0; |
| 4723 | } |
| 4724 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4725 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4726 | struct station_parameters *params) |
| 4727 | { |
| 4728 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4729 | params->supported_channels = |
| 4730 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4731 | params->supported_channels_len = |
| 4732 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4733 | /* |
| 4734 | * Need to include at least one (first channel, number of |
| 4735 | * channels) tuple for each subband, and must have proper |
| 4736 | * tuples for the rest of the data as well. |
| 4737 | */ |
| 4738 | if (params->supported_channels_len < 2) |
| 4739 | return -EINVAL; |
| 4740 | if (params->supported_channels_len % 2) |
| 4741 | return -EINVAL; |
| 4742 | } |
| 4743 | |
| 4744 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4745 | params->supported_oper_classes = |
| 4746 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4747 | params->supported_oper_classes_len = |
| 4748 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4749 | /* |
| 4750 | * The value of the Length field of the Supported Operating |
| 4751 | * Classes element is between 2 and 253. |
| 4752 | */ |
| 4753 | if (params->supported_oper_classes_len < 2 || |
| 4754 | params->supported_oper_classes_len > 253) |
| 4755 | return -EINVAL; |
| 4756 | } |
| 4757 | return 0; |
| 4758 | } |
| 4759 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4760 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4761 | struct station_parameters *params) |
| 4762 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4763 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4764 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4765 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4766 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4767 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4768 | params->ht_capa = |
| 4769 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4770 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4771 | params->vht_capa = |
| 4772 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4773 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4774 | err = nl80211_parse_sta_channel_info(info, params); |
| 4775 | if (err) |
| 4776 | return err; |
| 4777 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4778 | return nl80211_parse_sta_wme(info, params); |
| 4779 | } |
| 4780 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4781 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4782 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4784 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4785 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4786 | u8 *mac_addr; |
| 4787 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4788 | |
| 4789 | memset(¶ms, 0, sizeof(params)); |
| 4790 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4791 | if (!rdev->ops->change_station) |
| 4792 | return -EOPNOTSUPP; |
| 4793 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4794 | /* |
| 4795 | * AID and listen_interval properties can be set only for unassociated |
| 4796 | * station. Include these parameters here and will check them in |
| 4797 | * cfg80211_check_station_change(). |
| 4798 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4799 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4800 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4801 | |
| 4802 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4803 | params.listen_interval = |
| 4804 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4805 | else |
| 4806 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4807 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4808 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4809 | u8 tmp; |
| 4810 | |
| 4811 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4812 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4813 | return -EINVAL; |
| 4814 | |
| 4815 | params.support_p2p_ps = tmp; |
| 4816 | } else { |
| 4817 | params.support_p2p_ps = -1; |
| 4818 | } |
| 4819 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4820 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4821 | return -EINVAL; |
| 4822 | |
| 4823 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4824 | |
| 4825 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4826 | params.supported_rates = |
| 4827 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4828 | params.supported_rates_len = |
| 4829 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4830 | } |
| 4831 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4832 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4833 | params.capability = |
| 4834 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4835 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4836 | } |
| 4837 | |
| 4838 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4839 | params.ext_capab = |
| 4840 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4841 | params.ext_capab_len = |
| 4842 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4843 | } |
| 4844 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4845 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4846 | return -EINVAL; |
| 4847 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4848 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4849 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4850 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4851 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4852 | return -EINVAL; |
| 4853 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4854 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4855 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4856 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4857 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4858 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4859 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4860 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4861 | params.peer_aid = nla_get_u16( |
| 4862 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4863 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4864 | return -EINVAL; |
| 4865 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4866 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4867 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4868 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4869 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4870 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4871 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4872 | |
| 4873 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4874 | pm > NL80211_MESH_POWER_MAX) |
| 4875 | return -EINVAL; |
| 4876 | |
| 4877 | params.local_pm = pm; |
| 4878 | } |
| 4879 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4880 | /* Include parameters for TDLS peer (will check later) */ |
| 4881 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4882 | if (err) |
| 4883 | return err; |
| 4884 | |
| 4885 | params.vlan = get_vlan(info, rdev); |
| 4886 | if (IS_ERR(params.vlan)) |
| 4887 | return PTR_ERR(params.vlan); |
| 4888 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4889 | switch (dev->ieee80211_ptr->iftype) { |
| 4890 | case NL80211_IFTYPE_AP: |
| 4891 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4892 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4893 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4894 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4895 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4896 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4897 | break; |
| 4898 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4899 | err = -EOPNOTSUPP; |
| 4900 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4901 | } |
| 4902 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4903 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4904 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4905 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4906 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4907 | if (params.vlan) |
| 4908 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4909 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4910 | return err; |
| 4911 | } |
| 4912 | |
| 4913 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4914 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4916 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4917 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4918 | struct station_parameters params; |
| 4919 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4920 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4921 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4922 | |
| 4923 | memset(¶ms, 0, sizeof(params)); |
| 4924 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4925 | if (!rdev->ops->add_station) |
| 4926 | return -EOPNOTSUPP; |
| 4927 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4928 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4929 | return -EINVAL; |
| 4930 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4931 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4932 | return -EINVAL; |
| 4933 | |
| 4934 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4935 | return -EINVAL; |
| 4936 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4937 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4938 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4939 | return -EINVAL; |
| 4940 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4941 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4942 | params.supported_rates = |
| 4943 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4944 | params.supported_rates_len = |
| 4945 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4946 | params.listen_interval = |
| 4947 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4948 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4949 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4950 | u8 tmp; |
| 4951 | |
| 4952 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4953 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4954 | return -EINVAL; |
| 4955 | |
| 4956 | params.support_p2p_ps = tmp; |
| 4957 | } else { |
| 4958 | /* |
| 4959 | * if not specified, assume it's supported for P2P GO interface, |
| 4960 | * and is NOT supported for AP interface |
| 4961 | */ |
| 4962 | params.support_p2p_ps = |
| 4963 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4964 | } |
| 4965 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4966 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4967 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4968 | else |
| 4969 | 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] | 4970 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4971 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4972 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4973 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4974 | params.capability = |
| 4975 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4976 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4977 | } |
| 4978 | |
| 4979 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4980 | params.ext_capab = |
| 4981 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4982 | params.ext_capab_len = |
| 4983 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4984 | } |
| 4985 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4986 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4987 | params.ht_capa = |
| 4988 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4989 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4990 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4991 | params.vht_capa = |
| 4992 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4993 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4994 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4995 | params.opmode_notif_used = true; |
| 4996 | params.opmode_notif = |
| 4997 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4998 | } |
| 4999 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5000 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5001 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5002 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5003 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5004 | return -EINVAL; |
| 5005 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5006 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5007 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5008 | if (err) |
| 5009 | return err; |
| 5010 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5011 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5012 | if (err) |
| 5013 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5014 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5015 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5016 | return -EINVAL; |
| 5017 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5018 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5019 | * as userspace might just pass through the capabilities from the IEs |
| 5020 | * directly, rather than enforcing this restriction and returning an |
| 5021 | * error in this case. |
| 5022 | */ |
| 5023 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5024 | params.ht_capa = NULL; |
| 5025 | params.vht_capa = NULL; |
| 5026 | } |
| 5027 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5028 | /* When you run into this, adjust the code below for the new flag */ |
| 5029 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5030 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5031 | switch (dev->ieee80211_ptr->iftype) { |
| 5032 | case NL80211_IFTYPE_AP: |
| 5033 | case NL80211_IFTYPE_AP_VLAN: |
| 5034 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5035 | /* ignore WME attributes if iface/sta is not capable */ |
| 5036 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5037 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5038 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5039 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5040 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5041 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5042 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5043 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5044 | /* but don't bother the driver with it */ |
| 5045 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5046 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5047 | /* allow authenticated/associated only if driver handles it */ |
| 5048 | if (!(rdev->wiphy.features & |
| 5049 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5050 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5051 | return -EINVAL; |
| 5052 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5053 | /* Older userspace, or userspace wanting to be compatible with |
| 5054 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5055 | * and assoc flags in the mask, but assumes the station will be |
| 5056 | * added as associated anyway since this was the required driver |
| 5057 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5058 | * introduced. |
| 5059 | * In order to not bother drivers with this quirk in the API |
| 5060 | * set the flags in both the mask and set for new stations in |
| 5061 | * this case. |
| 5062 | */ |
| 5063 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5064 | params.sta_flags_mask |= auth_assoc; |
| 5065 | params.sta_flags_set |= auth_assoc; |
| 5066 | } |
| 5067 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5068 | /* must be last in here for error handling */ |
| 5069 | params.vlan = get_vlan(info, rdev); |
| 5070 | if (IS_ERR(params.vlan)) |
| 5071 | return PTR_ERR(params.vlan); |
| 5072 | break; |
| 5073 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5074 | /* ignore uAPSD data */ |
| 5075 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5076 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5077 | /* associated is disallowed */ |
| 5078 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5079 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5080 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5081 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5082 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5083 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5084 | break; |
| 5085 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5086 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5087 | /* ignore uAPSD data */ |
| 5088 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5089 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5090 | /* these are disallowed */ |
| 5091 | if (params.sta_flags_mask & |
| 5092 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5093 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5094 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5095 | /* Only TDLS peers can be added */ |
| 5096 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5097 | return -EINVAL; |
| 5098 | /* Can only add if TDLS ... */ |
| 5099 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5100 | return -EOPNOTSUPP; |
| 5101 | /* ... with external setup is supported */ |
| 5102 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5103 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5104 | /* |
| 5105 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5106 | * as authorized, but it shouldn't yet be. |
| 5107 | */ |
| 5108 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5109 | break; |
| 5110 | default: |
| 5111 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5112 | } |
| 5113 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5114 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5115 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5116 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5117 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5118 | if (params.vlan) |
| 5119 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5120 | return err; |
| 5121 | } |
| 5122 | |
| 5123 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5126 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5127 | struct station_del_parameters params; |
| 5128 | |
| 5129 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5130 | |
| 5131 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5132 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5133 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5135 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5137 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5138 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5140 | if (!rdev->ops->del_station) |
| 5141 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5142 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5143 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5144 | params.subtype = |
| 5145 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5146 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5147 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5148 | return -EINVAL; |
| 5149 | } else { |
| 5150 | /* Default to Deauthentication frame */ |
| 5151 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5152 | } |
| 5153 | |
| 5154 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5155 | params.reason_code = |
| 5156 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5157 | if (params.reason_code == 0) |
| 5158 | return -EINVAL; /* 0 is reserved */ |
| 5159 | } else { |
| 5160 | /* Default to reason code 2 */ |
| 5161 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5162 | } |
| 5163 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5164 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5165 | } |
| 5166 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5167 | 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] | 5168 | int flags, struct net_device *dev, |
| 5169 | u8 *dst, u8 *next_hop, |
| 5170 | struct mpath_info *pinfo) |
| 5171 | { |
| 5172 | void *hdr; |
| 5173 | struct nlattr *pinfoattr; |
| 5174 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5175 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5176 | if (!hdr) |
| 5177 | return -1; |
| 5178 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5179 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5180 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5181 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5182 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5183 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5184 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5185 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5186 | if (!pinfoattr) |
| 5187 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5188 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5189 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5190 | pinfo->frame_qlen)) |
| 5191 | goto nla_put_failure; |
| 5192 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5193 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5194 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5195 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5196 | pinfo->metric)) || |
| 5197 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5198 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5199 | pinfo->exptime)) || |
| 5200 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5201 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5202 | pinfo->flags)) || |
| 5203 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5204 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5205 | pinfo->discovery_timeout)) || |
| 5206 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5207 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5208 | pinfo->discovery_retries))) |
| 5209 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5210 | |
| 5211 | nla_nest_end(msg, pinfoattr); |
| 5212 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5213 | genlmsg_end(msg, hdr); |
| 5214 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5215 | |
| 5216 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5217 | genlmsg_cancel(msg, hdr); |
| 5218 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5219 | } |
| 5220 | |
| 5221 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5222 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5223 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5224 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5225 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5226 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5227 | u8 dst[ETH_ALEN]; |
| 5228 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5229 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5230 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5231 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5232 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5233 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5234 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5235 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5236 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5237 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5238 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5239 | goto out_err; |
| 5240 | } |
| 5241 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5242 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5243 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5244 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5247 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5248 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5249 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5250 | if (err == -ENOENT) |
| 5251 | break; |
| 5252 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5253 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5254 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5255 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5256 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5257 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5258 | &pinfo) < 0) |
| 5259 | goto out; |
| 5260 | |
| 5261 | path_idx++; |
| 5262 | } |
| 5263 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5264 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5265 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5266 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5267 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5268 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5269 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5273 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5275 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5276 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5277 | struct mpath_info pinfo; |
| 5278 | struct sk_buff *msg; |
| 5279 | u8 *dst = NULL; |
| 5280 | u8 next_hop[ETH_ALEN]; |
| 5281 | |
| 5282 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5283 | |
| 5284 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5285 | return -EINVAL; |
| 5286 | |
| 5287 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5288 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5289 | if (!rdev->ops->get_mpath) |
| 5290 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5291 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5292 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5293 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5294 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5295 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5296 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5297 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5298 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5300 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5301 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5302 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5303 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5304 | dev, dst, next_hop, &pinfo) < 0) { |
| 5305 | nlmsg_free(msg); |
| 5306 | return -ENOBUFS; |
| 5307 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5309 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5313 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5315 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5316 | u8 *dst = NULL; |
| 5317 | u8 *next_hop = NULL; |
| 5318 | |
| 5319 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5320 | return -EINVAL; |
| 5321 | |
| 5322 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5323 | return -EINVAL; |
| 5324 | |
| 5325 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5326 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5327 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5328 | if (!rdev->ops->change_mpath) |
| 5329 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5332 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5333 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5334 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5335 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5336 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5337 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5340 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5341 | u8 *dst = NULL; |
| 5342 | u8 *next_hop = NULL; |
| 5343 | |
| 5344 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5345 | return -EINVAL; |
| 5346 | |
| 5347 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5348 | return -EINVAL; |
| 5349 | |
| 5350 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5351 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5352 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5353 | if (!rdev->ops->add_mpath) |
| 5354 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5356 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5357 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5358 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5359 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5363 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5365 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5366 | u8 *dst = NULL; |
| 5367 | |
| 5368 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5369 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5370 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5371 | if (!rdev->ops->del_mpath) |
| 5372 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5373 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5374 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5375 | } |
| 5376 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5377 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5378 | { |
| 5379 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5380 | int err; |
| 5381 | struct net_device *dev = info->user_ptr[1]; |
| 5382 | struct mpath_info pinfo; |
| 5383 | struct sk_buff *msg; |
| 5384 | u8 *dst = NULL; |
| 5385 | u8 mpp[ETH_ALEN]; |
| 5386 | |
| 5387 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5388 | |
| 5389 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5390 | return -EINVAL; |
| 5391 | |
| 5392 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5393 | |
| 5394 | if (!rdev->ops->get_mpp) |
| 5395 | return -EOPNOTSUPP; |
| 5396 | |
| 5397 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5398 | return -EOPNOTSUPP; |
| 5399 | |
| 5400 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5401 | if (err) |
| 5402 | return err; |
| 5403 | |
| 5404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5405 | if (!msg) |
| 5406 | return -ENOMEM; |
| 5407 | |
| 5408 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5409 | dev, dst, mpp, &pinfo) < 0) { |
| 5410 | nlmsg_free(msg); |
| 5411 | return -ENOBUFS; |
| 5412 | } |
| 5413 | |
| 5414 | return genlmsg_reply(msg, info); |
| 5415 | } |
| 5416 | |
| 5417 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5418 | struct netlink_callback *cb) |
| 5419 | { |
| 5420 | struct mpath_info pinfo; |
| 5421 | struct cfg80211_registered_device *rdev; |
| 5422 | struct wireless_dev *wdev; |
| 5423 | u8 dst[ETH_ALEN]; |
| 5424 | u8 mpp[ETH_ALEN]; |
| 5425 | int path_idx = cb->args[2]; |
| 5426 | int err; |
| 5427 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5428 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5429 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5430 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5431 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5432 | |
| 5433 | if (!rdev->ops->dump_mpp) { |
| 5434 | err = -EOPNOTSUPP; |
| 5435 | goto out_err; |
| 5436 | } |
| 5437 | |
| 5438 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5439 | err = -EOPNOTSUPP; |
| 5440 | goto out_err; |
| 5441 | } |
| 5442 | |
| 5443 | while (1) { |
| 5444 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5445 | mpp, &pinfo); |
| 5446 | if (err == -ENOENT) |
| 5447 | break; |
| 5448 | if (err) |
| 5449 | goto out_err; |
| 5450 | |
| 5451 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5452 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5453 | wdev->netdev, dst, mpp, |
| 5454 | &pinfo) < 0) |
| 5455 | goto out; |
| 5456 | |
| 5457 | path_idx++; |
| 5458 | } |
| 5459 | |
| 5460 | out: |
| 5461 | cb->args[2] = path_idx; |
| 5462 | err = skb->len; |
| 5463 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5464 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5465 | return err; |
| 5466 | } |
| 5467 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5468 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5469 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5471 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5472 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5473 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5474 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5475 | |
| 5476 | memset(¶ms, 0, sizeof(params)); |
| 5477 | /* default to not changing parameters */ |
| 5478 | params.use_cts_prot = -1; |
| 5479 | params.use_short_preamble = -1; |
| 5480 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5481 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5482 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5483 | params.p2p_ctwindow = -1; |
| 5484 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5485 | |
| 5486 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5487 | params.use_cts_prot = |
| 5488 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5489 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5490 | params.use_short_preamble = |
| 5491 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5492 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5493 | params.use_short_slot_time = |
| 5494 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5495 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5496 | params.basic_rates = |
| 5497 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5498 | params.basic_rates_len = |
| 5499 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5500 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5501 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5502 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5503 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5504 | params.ht_opmode = |
| 5505 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5506 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5507 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5508 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5509 | return -EINVAL; |
| 5510 | params.p2p_ctwindow = |
| 5511 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5512 | if (params.p2p_ctwindow < 0) |
| 5513 | return -EINVAL; |
| 5514 | if (params.p2p_ctwindow != 0 && |
| 5515 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5516 | return -EINVAL; |
| 5517 | } |
| 5518 | |
| 5519 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5520 | u8 tmp; |
| 5521 | |
| 5522 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5523 | return -EINVAL; |
| 5524 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5525 | if (tmp > 1) |
| 5526 | return -EINVAL; |
| 5527 | params.p2p_opp_ps = tmp; |
| 5528 | if (params.p2p_opp_ps && |
| 5529 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5530 | return -EINVAL; |
| 5531 | } |
| 5532 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | if (!rdev->ops->change_bss) |
| 5534 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5535 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5536 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5537 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5538 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5539 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5540 | wdev_lock(wdev); |
| 5541 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5542 | wdev_unlock(wdev); |
| 5543 | |
| 5544 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5545 | } |
| 5546 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5547 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5548 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5549 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5550 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5551 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5552 | u32 owner_nlportid; |
| 5553 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5554 | /* |
| 5555 | * You should only get this when cfg80211 hasn't yet initialized |
| 5556 | * completely when built-in to the kernel right between the time |
| 5557 | * window between nl80211_init() and regulatory_init(), if that is |
| 5558 | * even possible. |
| 5559 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5560 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5561 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5562 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5563 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5564 | user_reg_hint_type = |
| 5565 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5566 | else |
| 5567 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5568 | |
| 5569 | switch (user_reg_hint_type) { |
| 5570 | case NL80211_USER_REG_HINT_USER: |
| 5571 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5572 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5573 | return -EINVAL; |
| 5574 | |
| 5575 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5576 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5577 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5578 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5579 | owner_nlportid = info->snd_portid; |
| 5580 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5581 | } else { |
| 5582 | owner_nlportid = 0; |
| 5583 | is_indoor = true; |
| 5584 | } |
| 5585 | |
| 5586 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5587 | default: |
| 5588 | return -EINVAL; |
| 5589 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5592 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5593 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5596 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5597 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5598 | struct mesh_config cur_params; |
| 5599 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5600 | void *hdr; |
| 5601 | struct nlattr *pinfoattr; |
| 5602 | struct sk_buff *msg; |
| 5603 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5604 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5605 | return -EOPNOTSUPP; |
| 5606 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5607 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5609 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5610 | wdev_lock(wdev); |
| 5611 | /* If not connected, get default parameters */ |
| 5612 | if (!wdev->mesh_id_len) |
| 5613 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5614 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5615 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5616 | wdev_unlock(wdev); |
| 5617 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5618 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5619 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5620 | |
| 5621 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5623 | if (!msg) |
| 5624 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5625 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5626 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5627 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5628 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5629 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5630 | if (!pinfoattr) |
| 5631 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5632 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5633 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5634 | cur_params.dot11MeshRetryTimeout) || |
| 5635 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5636 | cur_params.dot11MeshConfirmTimeout) || |
| 5637 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5638 | cur_params.dot11MeshHoldingTimeout) || |
| 5639 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5640 | cur_params.dot11MeshMaxPeerLinks) || |
| 5641 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5642 | cur_params.dot11MeshMaxRetries) || |
| 5643 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5644 | cur_params.dot11MeshTTL) || |
| 5645 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5646 | cur_params.element_ttl) || |
| 5647 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5648 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5649 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5650 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5651 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5652 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5653 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5654 | cur_params.path_refresh_time) || |
| 5655 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5656 | cur_params.min_discovery_timeout) || |
| 5657 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5658 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5659 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5660 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5661 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5662 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5663 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5664 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5665 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5666 | cur_params.dot11MeshHWMPRootMode) || |
| 5667 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5668 | cur_params.dot11MeshHWMPRannInterval) || |
| 5669 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5670 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5671 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5672 | cur_params.dot11MeshForwarding) || |
| 5673 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5674 | cur_params.rssi_threshold) || |
| 5675 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5676 | cur_params.ht_opmode) || |
| 5677 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5678 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5679 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5680 | cur_params.dot11MeshHWMProotInterval) || |
| 5681 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5682 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5683 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5684 | cur_params.power_mode) || |
| 5685 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5686 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5687 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5688 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5689 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5690 | nla_nest_end(msg, pinfoattr); |
| 5691 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5692 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5693 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5694 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5695 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5696 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5697 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5698 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5699 | } |
| 5700 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5701 | 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] | 5702 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5703 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5704 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5705 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5706 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5707 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5708 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5709 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5710 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5711 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5712 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5713 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5714 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5715 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5716 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5717 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5718 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5719 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5720 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5721 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5722 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5723 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5724 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5725 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5726 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5727 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5728 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5729 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5730 | }; |
| 5731 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5732 | static const struct nla_policy |
| 5733 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5734 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5735 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5736 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5737 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5738 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5739 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5740 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5741 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5742 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5743 | }; |
| 5744 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5745 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5746 | { |
| 5747 | u8 val = nla_get_u8(nla); |
| 5748 | if (val < min || val > max) |
| 5749 | return -EINVAL; |
| 5750 | *out = val; |
| 5751 | return 0; |
| 5752 | } |
| 5753 | |
| 5754 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5755 | { |
| 5756 | u8 val = nla_get_u8(nla); |
| 5757 | if (val < min || val > max) |
| 5758 | return -EINVAL; |
| 5759 | *out = val; |
| 5760 | return 0; |
| 5761 | } |
| 5762 | |
| 5763 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5764 | { |
| 5765 | u16 val = nla_get_u16(nla); |
| 5766 | if (val < min || val > max) |
| 5767 | return -EINVAL; |
| 5768 | *out = val; |
| 5769 | return 0; |
| 5770 | } |
| 5771 | |
| 5772 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5773 | { |
| 5774 | u32 val = nla_get_u32(nla); |
| 5775 | if (val < min || val > max) |
| 5776 | return -EINVAL; |
| 5777 | *out = val; |
| 5778 | return 0; |
| 5779 | } |
| 5780 | |
| 5781 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5782 | { |
| 5783 | s32 val = nla_get_s32(nla); |
| 5784 | if (val < min || val > max) |
| 5785 | return -EINVAL; |
| 5786 | *out = val; |
| 5787 | return 0; |
| 5788 | } |
| 5789 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5790 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5791 | enum nl80211_mesh_power_mode min, |
| 5792 | enum nl80211_mesh_power_mode max, |
| 5793 | enum nl80211_mesh_power_mode *out) |
| 5794 | { |
| 5795 | u32 val = nla_get_u32(nla); |
| 5796 | if (val < min || val > max) |
| 5797 | return -EINVAL; |
| 5798 | *out = val; |
| 5799 | return 0; |
| 5800 | } |
| 5801 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5802 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5803 | struct mesh_config *cfg, |
| 5804 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5805 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5806 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5807 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5808 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5809 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5810 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5811 | do { \ |
| 5812 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5813 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5814 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5815 | mask |= (1 << (attr - 1)); \ |
| 5816 | } \ |
| 5817 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5818 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5819 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5820 | return -EINVAL; |
| 5821 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5822 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5823 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5824 | return -EINVAL; |
| 5825 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5826 | /* This makes sure that there aren't more than 32 mesh config |
| 5827 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5828 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5829 | |
| 5830 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5831 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5832 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5833 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5834 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5835 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5836 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5837 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5838 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5839 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5840 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5841 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5842 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5843 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5844 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5845 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5847 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5848 | 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] | 5849 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5850 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5851 | 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] | 5852 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5853 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5855 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5856 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5857 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5859 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5860 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5861 | 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] | 5862 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5863 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5864 | 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] | 5865 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5866 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5867 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5868 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5869 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5870 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5872 | 1, 65535, mask, |
| 5873 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5874 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5876 | 1, 65535, mask, |
| 5877 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5878 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5879 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5880 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5881 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5882 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5883 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5885 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5886 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5887 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5888 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5889 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5891 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5892 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5893 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5894 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5895 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5896 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5897 | 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] | 5898 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5899 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5900 | /* |
| 5901 | * Check HT operation mode based on |
| 5902 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5903 | */ |
| 5904 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5905 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5906 | |
| 5907 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5908 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5909 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5910 | return -EINVAL; |
| 5911 | |
| 5912 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5913 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5914 | return -EINVAL; |
| 5915 | |
| 5916 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5917 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5918 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5919 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 5920 | return -EINVAL; |
| 5921 | break; |
| 5922 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 5923 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 5924 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5925 | return -EINVAL; |
| 5926 | break; |
| 5927 | } |
| 5928 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | f9bd791 | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 5929 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5930 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5932 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5933 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5934 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5936 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5937 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5939 | dot11MeshHWMPconfirmationInterval, |
| 5940 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5941 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5942 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5943 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5944 | NL80211_MESH_POWER_ACTIVE, |
| 5945 | NL80211_MESH_POWER_MAX, |
| 5946 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5947 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5948 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5949 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5950 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5951 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5952 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5953 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5954 | if (mask_out) |
| 5955 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5956 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5957 | return 0; |
| 5958 | |
| 5959 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5960 | } |
| 5961 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5962 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5963 | struct mesh_setup *setup) |
| 5964 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5966 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5967 | |
| 5968 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5969 | return -EINVAL; |
| 5970 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5971 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5972 | nl80211_mesh_setup_params_policy)) |
| 5973 | return -EINVAL; |
| 5974 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5975 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5976 | setup->sync_method = |
| 5977 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5978 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5979 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5980 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5981 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5982 | setup->path_sel_proto = |
| 5983 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5984 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5985 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5986 | |
| 5987 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5988 | setup->path_metric = |
| 5989 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5990 | IEEE80211_PATH_METRIC_VENDOR : |
| 5991 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5992 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5993 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5994 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5995 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5996 | if (!is_valid_ie_attr(ieattr)) |
| 5997 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5998 | setup->ie = nla_data(ieattr); |
| 5999 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6000 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6001 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6002 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6003 | return -EINVAL; |
| 6004 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6005 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6006 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6007 | if (setup->is_secure) |
| 6008 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6009 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6010 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6011 | if (!setup->user_mpm) |
| 6012 | return -EINVAL; |
| 6013 | setup->auth_id = |
| 6014 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6015 | } |
| 6016 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6017 | return 0; |
| 6018 | } |
| 6019 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6020 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6021 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6022 | { |
| 6023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6024 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6025 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6026 | struct mesh_config cfg; |
| 6027 | u32 mask; |
| 6028 | int err; |
| 6029 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6030 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6031 | return -EOPNOTSUPP; |
| 6032 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6033 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6034 | return -EOPNOTSUPP; |
| 6035 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6036 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6037 | if (err) |
| 6038 | return err; |
| 6039 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6040 | wdev_lock(wdev); |
| 6041 | if (!wdev->mesh_id_len) |
| 6042 | err = -ENOLINK; |
| 6043 | |
| 6044 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6045 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6046 | |
| 6047 | wdev_unlock(wdev); |
| 6048 | |
| 6049 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6052 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6053 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6054 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6055 | struct nlattr *nl_reg_rules; |
| 6056 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6057 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6058 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6059 | (regdom->dfs_region && |
| 6060 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6061 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6062 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6063 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6064 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6065 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6066 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6067 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6068 | struct nlattr *nl_reg_rule; |
| 6069 | const struct ieee80211_reg_rule *reg_rule; |
| 6070 | const struct ieee80211_freq_range *freq_range; |
| 6071 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6072 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6073 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6074 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6075 | freq_range = ®_rule->freq_range; |
| 6076 | power_rule = ®_rule->power_rule; |
| 6077 | |
| 6078 | nl_reg_rule = nla_nest_start(msg, i); |
| 6079 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6080 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6081 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6082 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6083 | if (!max_bandwidth_khz) |
| 6084 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6085 | reg_rule); |
| 6086 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6087 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6088 | reg_rule->flags) || |
| 6089 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6090 | freq_range->start_freq_khz) || |
| 6091 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6092 | freq_range->end_freq_khz) || |
| 6093 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6094 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6095 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6096 | power_rule->max_antenna_gain) || |
| 6097 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6098 | power_rule->max_eirp) || |
| 6099 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6100 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6101 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6102 | |
| 6103 | nla_nest_end(msg, nl_reg_rule); |
| 6104 | } |
| 6105 | |
| 6106 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6107 | return 0; |
| 6108 | |
| 6109 | nla_put_failure: |
| 6110 | return -EMSGSIZE; |
| 6111 | } |
| 6112 | |
| 6113 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6114 | { |
| 6115 | const struct ieee80211_regdomain *regdom = NULL; |
| 6116 | struct cfg80211_registered_device *rdev; |
| 6117 | struct wiphy *wiphy = NULL; |
| 6118 | struct sk_buff *msg; |
| 6119 | void *hdr; |
| 6120 | |
| 6121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6122 | if (!msg) |
| 6123 | return -ENOBUFS; |
| 6124 | |
| 6125 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6126 | NL80211_CMD_GET_REG); |
| 6127 | if (!hdr) |
| 6128 | goto put_failure; |
| 6129 | |
| 6130 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6131 | bool self_managed; |
| 6132 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6133 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6134 | if (IS_ERR(rdev)) { |
| 6135 | nlmsg_free(msg); |
| 6136 | return PTR_ERR(rdev); |
| 6137 | } |
| 6138 | |
| 6139 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6140 | self_managed = wiphy->regulatory_flags & |
| 6141 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6142 | regdom = get_wiphy_regdom(wiphy); |
| 6143 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6144 | /* a self-managed-reg device must have a private regdom */ |
| 6145 | if (WARN_ON(!regdom && self_managed)) { |
| 6146 | nlmsg_free(msg); |
| 6147 | return -EINVAL; |
| 6148 | } |
| 6149 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6150 | if (regdom && |
| 6151 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6152 | goto nla_put_failure; |
| 6153 | } |
| 6154 | |
| 6155 | if (!wiphy && reg_last_request_cell_base() && |
| 6156 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6157 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6158 | goto nla_put_failure; |
| 6159 | |
| 6160 | rcu_read_lock(); |
| 6161 | |
| 6162 | if (!regdom) |
| 6163 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6164 | |
| 6165 | if (nl80211_put_regdom(regdom, msg)) |
| 6166 | goto nla_put_failure_rcu; |
| 6167 | |
| 6168 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6169 | |
| 6170 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6171 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6172 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6173 | nla_put_failure_rcu: |
| 6174 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6175 | nla_put_failure: |
| 6176 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6177 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6178 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6179 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6180 | } |
| 6181 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6182 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6183 | u32 seq, int flags, struct wiphy *wiphy, |
| 6184 | const struct ieee80211_regdomain *regdom) |
| 6185 | { |
| 6186 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6187 | NL80211_CMD_GET_REG); |
| 6188 | |
| 6189 | if (!hdr) |
| 6190 | return -1; |
| 6191 | |
| 6192 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6193 | |
| 6194 | if (nl80211_put_regdom(regdom, msg)) |
| 6195 | goto nla_put_failure; |
| 6196 | |
| 6197 | if (!wiphy && reg_last_request_cell_base() && |
| 6198 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6199 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6200 | goto nla_put_failure; |
| 6201 | |
| 6202 | if (wiphy && |
| 6203 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6204 | goto nla_put_failure; |
| 6205 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6206 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6207 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6208 | goto nla_put_failure; |
| 6209 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6210 | genlmsg_end(msg, hdr); |
| 6211 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6212 | |
| 6213 | nla_put_failure: |
| 6214 | genlmsg_cancel(msg, hdr); |
| 6215 | return -EMSGSIZE; |
| 6216 | } |
| 6217 | |
| 6218 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6219 | struct netlink_callback *cb) |
| 6220 | { |
| 6221 | const struct ieee80211_regdomain *regdom = NULL; |
| 6222 | struct cfg80211_registered_device *rdev; |
| 6223 | int err, reg_idx, start = cb->args[2]; |
| 6224 | |
| 6225 | rtnl_lock(); |
| 6226 | |
| 6227 | if (cfg80211_regdomain && start == 0) { |
| 6228 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6229 | NLM_F_MULTI, NULL, |
| 6230 | rtnl_dereference(cfg80211_regdomain)); |
| 6231 | if (err < 0) |
| 6232 | goto out_err; |
| 6233 | } |
| 6234 | |
| 6235 | /* the global regdom is idx 0 */ |
| 6236 | reg_idx = 1; |
| 6237 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6238 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6239 | if (!regdom) |
| 6240 | continue; |
| 6241 | |
| 6242 | if (++reg_idx <= start) |
| 6243 | continue; |
| 6244 | |
| 6245 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6246 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6247 | if (err < 0) { |
| 6248 | reg_idx--; |
| 6249 | break; |
| 6250 | } |
| 6251 | } |
| 6252 | |
| 6253 | cb->args[2] = reg_idx; |
| 6254 | err = skb->len; |
| 6255 | out_err: |
| 6256 | rtnl_unlock(); |
| 6257 | return err; |
| 6258 | } |
| 6259 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6260 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6261 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6262 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6263 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6264 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6265 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6266 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6267 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6268 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6269 | }; |
| 6270 | |
| 6271 | static int parse_reg_rule(struct nlattr *tb[], |
| 6272 | struct ieee80211_reg_rule *reg_rule) |
| 6273 | { |
| 6274 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6275 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6276 | |
| 6277 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6278 | return -EINVAL; |
| 6279 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6280 | return -EINVAL; |
| 6281 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6282 | return -EINVAL; |
| 6283 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6284 | return -EINVAL; |
| 6285 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6286 | return -EINVAL; |
| 6287 | |
| 6288 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6289 | |
| 6290 | freq_range->start_freq_khz = |
| 6291 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6292 | freq_range->end_freq_khz = |
| 6293 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6294 | freq_range->max_bandwidth_khz = |
| 6295 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6296 | |
| 6297 | power_rule->max_eirp = |
| 6298 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6299 | |
| 6300 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6301 | power_rule->max_antenna_gain = |
| 6302 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6303 | |
| 6304 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6305 | reg_rule->dfs_cac_ms = |
| 6306 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6307 | |
| 6308 | return 0; |
| 6309 | } |
| 6310 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6311 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6312 | { |
| 6313 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6314 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6315 | char *alpha2; |
| 6316 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6317 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6318 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6319 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6320 | |
| 6321 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6322 | return -EINVAL; |
| 6323 | |
| 6324 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6325 | return -EINVAL; |
| 6326 | |
| 6327 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6328 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6329 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6330 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6331 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6332 | 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] | 6333 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6334 | num_rules++; |
| 6335 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6336 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6337 | } |
| 6338 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6339 | if (!reg_is_valid_request(alpha2)) |
| 6340 | return -EINVAL; |
| 6341 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6342 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6343 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6344 | |
| 6345 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6346 | if (!rd) |
| 6347 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6348 | |
| 6349 | rd->n_reg_rules = num_rules; |
| 6350 | rd->alpha2[0] = alpha2[0]; |
| 6351 | rd->alpha2[1] = alpha2[1]; |
| 6352 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6353 | /* |
| 6354 | * Disable DFS master mode if the DFS region was |
| 6355 | * not supported or known on this kernel. |
| 6356 | */ |
| 6357 | if (reg_supported_dfs_region(dfs_region)) |
| 6358 | rd->dfs_region = dfs_region; |
| 6359 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6360 | 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] | 6361 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6362 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 6363 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 6364 | reg_rule_policy); |
| 6365 | if (r) |
| 6366 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6367 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6368 | if (r) |
| 6369 | goto bad_reg; |
| 6370 | |
| 6371 | rule_idx++; |
| 6372 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6373 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6374 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6375 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6376 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6377 | } |
| 6378 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6379 | /* set_regdom takes ownership of rd */ |
| 6380 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6381 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6382 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6383 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6384 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6385 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6386 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6387 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6388 | { |
| 6389 | struct nlattr *attr1, *attr2; |
| 6390 | int n_channels = 0, tmp1, tmp2; |
| 6391 | |
Srinivas Dasari | e471290 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 6392 | nla_for_each_nested(attr1, freqs, tmp1) |
| 6393 | if (nla_len(attr1) != sizeof(u32)) |
| 6394 | return 0; |
| 6395 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6396 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6397 | n_channels++; |
| 6398 | /* |
| 6399 | * Some hardware has a limited channel list for |
| 6400 | * scanning, and it is pretty much nonsensical |
| 6401 | * to scan for a channel twice, so disallow that |
| 6402 | * and don't require drivers to check that the |
| 6403 | * channel list they get isn't longer than what |
| 6404 | * they can scan, as long as they can scan all |
| 6405 | * the channels they registered at once. |
| 6406 | */ |
| 6407 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6408 | if (attr1 != attr2 && |
| 6409 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6410 | return 0; |
| 6411 | } |
| 6412 | |
| 6413 | return n_channels; |
| 6414 | } |
| 6415 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6416 | 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] | 6417 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6418 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6422 | struct cfg80211_bss_selection *bss_select) |
| 6423 | { |
| 6424 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6425 | struct nlattr *nest; |
| 6426 | int err; |
| 6427 | bool found = false; |
| 6428 | int i; |
| 6429 | |
| 6430 | /* only process one nested attribute */ |
| 6431 | nest = nla_data(nla); |
| 6432 | if (!nla_ok(nest, nla_len(nest))) |
| 6433 | return -EINVAL; |
| 6434 | |
| 6435 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), |
| 6436 | nla_len(nest), nl80211_bss_select_policy); |
| 6437 | if (err) |
| 6438 | return err; |
| 6439 | |
| 6440 | /* only one attribute may be given */ |
| 6441 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6442 | if (attr[i]) { |
| 6443 | if (found) |
| 6444 | return -EINVAL; |
| 6445 | found = true; |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6450 | |
| 6451 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6452 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6453 | |
| 6454 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6455 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6456 | bss_select->param.band_pref = |
| 6457 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6458 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6459 | return -EINVAL; |
| 6460 | } |
| 6461 | |
| 6462 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6463 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6464 | |
| 6465 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6466 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6467 | bss_select->param.adjust.band = adj_param->band; |
| 6468 | bss_select->param.adjust.delta = adj_param->delta; |
| 6469 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6470 | return -EINVAL; |
| 6471 | } |
| 6472 | |
| 6473 | /* user-space did not provide behaviour attribute */ |
| 6474 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6475 | return -EINVAL; |
| 6476 | |
| 6477 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6478 | return -EINVAL; |
| 6479 | |
| 6480 | return 0; |
| 6481 | } |
| 6482 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6483 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6484 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6485 | { |
| 6486 | int i; |
| 6487 | |
| 6488 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6489 | eth_zero_addr(mac_addr); |
| 6490 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6491 | mac_addr[0] = 0x2; |
| 6492 | mac_addr_mask[0] = 0x3; |
| 6493 | |
| 6494 | return 0; |
| 6495 | } |
| 6496 | |
| 6497 | /* need both or none */ |
| 6498 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6499 | return -EINVAL; |
| 6500 | |
| 6501 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6502 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6503 | |
| 6504 | /* don't allow or configure an mcast address */ |
| 6505 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6506 | is_multicast_ether_addr(mac_addr)) |
| 6507 | return -EINVAL; |
| 6508 | |
| 6509 | /* |
| 6510 | * allow users to pass a MAC address that has bits set outside |
| 6511 | * of the mask, but don't bother drivers with having to deal |
| 6512 | * with such bits |
| 6513 | */ |
| 6514 | for (i = 0; i < ETH_ALEN; i++) |
| 6515 | mac_addr[i] &= mac_addr_mask[i]; |
| 6516 | |
| 6517 | return 0; |
| 6518 | } |
| 6519 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6520 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6521 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6523 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6524 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6525 | struct nlattr *attr; |
| 6526 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6527 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6528 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6529 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6530 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6531 | return -EINVAL; |
| 6532 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6533 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6534 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6535 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6536 | return -EOPNOTSUPP; |
| 6537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6538 | if (!rdev->ops->scan) |
| 6539 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6540 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6541 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6542 | err = -EBUSY; |
| 6543 | goto unlock; |
| 6544 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6545 | |
| 6546 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6547 | n_channels = validate_scan_freqs( |
| 6548 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6549 | if (!n_channels) { |
| 6550 | err = -EINVAL; |
| 6551 | goto unlock; |
| 6552 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6553 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6554 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6555 | } |
| 6556 | |
| 6557 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6558 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6559 | n_ssids++; |
| 6560 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6561 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6562 | err = -EINVAL; |
| 6563 | goto unlock; |
| 6564 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6565 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6566 | if (info->attrs[NL80211_ATTR_IE]) |
| 6567 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6568 | else |
| 6569 | ie_len = 0; |
| 6570 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6571 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6572 | err = -EINVAL; |
| 6573 | goto unlock; |
| 6574 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6575 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6576 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6577 | + sizeof(*request->ssids) * n_ssids |
| 6578 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6579 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6580 | if (!request) { |
| 6581 | err = -ENOMEM; |
| 6582 | goto unlock; |
| 6583 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6584 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6585 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6586 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6587 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6588 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6589 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6590 | request->ie = (void *)(request->ssids + n_ssids); |
| 6591 | else |
| 6592 | request->ie = (void *)(request->channels + n_channels); |
| 6593 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6594 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6595 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6596 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6597 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6598 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6599 | struct ieee80211_channel *chan; |
| 6600 | |
| 6601 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6602 | |
| 6603 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6604 | err = -EINVAL; |
| 6605 | goto out_free; |
| 6606 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6607 | |
| 6608 | /* ignore disabled channels */ |
| 6609 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6610 | continue; |
| 6611 | |
| 6612 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6613 | i++; |
| 6614 | } |
| 6615 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6616 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6617 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6618 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6619 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6620 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6621 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6622 | if (!wiphy->bands[band]) |
| 6623 | continue; |
| 6624 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6625 | struct ieee80211_channel *chan; |
| 6626 | |
| 6627 | chan = &wiphy->bands[band]->channels[j]; |
| 6628 | |
| 6629 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6630 | continue; |
| 6631 | |
| 6632 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6633 | i++; |
| 6634 | } |
| 6635 | } |
| 6636 | } |
| 6637 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6638 | if (!i) { |
| 6639 | err = -EINVAL; |
| 6640 | goto out_free; |
| 6641 | } |
| 6642 | |
| 6643 | request->n_channels = i; |
| 6644 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6645 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6646 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6647 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6648 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6649 | err = -EINVAL; |
| 6650 | goto out_free; |
| 6651 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6652 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6653 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6654 | i++; |
| 6655 | } |
| 6656 | } |
| 6657 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6658 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6659 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6660 | memcpy((void *)request->ie, |
| 6661 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6662 | request->ie_len); |
| 6663 | } |
| 6664 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6665 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6666 | if (wiphy->bands[i]) |
| 6667 | request->rates[i] = |
| 6668 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6669 | |
| 6670 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6671 | nla_for_each_nested(attr, |
| 6672 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6673 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6674 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6675 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6676 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6677 | err = -EINVAL; |
| 6678 | goto out_free; |
| 6679 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6680 | |
| 6681 | if (!wiphy->bands[band]) |
| 6682 | continue; |
| 6683 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6684 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6685 | nla_data(attr), |
| 6686 | nla_len(attr), |
| 6687 | &request->rates[band]); |
| 6688 | if (err) |
| 6689 | goto out_free; |
| 6690 | } |
| 6691 | } |
| 6692 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6693 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6694 | if (!wiphy_ext_feature_isset(wiphy, |
| 6695 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6696 | err = -EOPNOTSUPP; |
| 6697 | goto out_free; |
| 6698 | } |
| 6699 | |
| 6700 | request->duration = |
| 6701 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6702 | request->duration_mandatory = |
| 6703 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6704 | } |
| 6705 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6706 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6707 | request->flags = nla_get_u32( |
| 6708 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Srinivas Dasari | df7d3c6 | 2018-01-17 16:44:16 +0530 | [diff] [blame] | 6709 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6710 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 6711 | ((request->flags & NL80211_SCAN_FLAG_LOW_SPAN) && |
| 6712 | !wiphy_ext_feature_isset(wiphy, |
| 6713 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) || |
| 6714 | ((request->flags & NL80211_SCAN_FLAG_LOW_POWER) && |
| 6715 | !wiphy_ext_feature_isset(wiphy, |
| 6716 | NL80211_EXT_FEATURE_LOW_POWER_SCAN)) || |
| 6717 | ((request->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) && |
| 6718 | !wiphy_ext_feature_isset(wiphy, |
| 6719 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6720 | err = -EOPNOTSUPP; |
| 6721 | goto out_free; |
| 6722 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6723 | |
| 6724 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6725 | if (!(wiphy->features & |
| 6726 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6727 | err = -EOPNOTSUPP; |
| 6728 | goto out_free; |
| 6729 | } |
| 6730 | |
| 6731 | if (wdev->current_bss) { |
| 6732 | err = -EOPNOTSUPP; |
| 6733 | goto out_free; |
| 6734 | } |
| 6735 | |
| 6736 | err = nl80211_parse_random_mac(info->attrs, |
| 6737 | request->mac_addr, |
| 6738 | request->mac_addr_mask); |
| 6739 | if (err) |
| 6740 | goto out_free; |
| 6741 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6742 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6743 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6744 | request->no_cck = |
| 6745 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6746 | |
Vamsi Krishna | 4581639 | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6747 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6748 | * BSSID to scan for. This was problematic because that same attribute |
| 6749 | * was already used for another purpose (local random MAC address). The |
| 6750 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6751 | * compatibility with older userspace components, also use the |
| 6752 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6753 | * the specific BSSID use case instead of the random MAC address |
| 6754 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6755 | */ |
| 6756 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6757 | memcpy(request->bssid, |
| 6758 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6759 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6760 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6761 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6762 | ETH_ALEN); |
| 6763 | else |
| 6764 | eth_broadcast_addr(request->bssid); |
| 6765 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6766 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6767 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6768 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6769 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6770 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6771 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6772 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6773 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6774 | nl80211_send_scan_start(rdev, wdev); |
| 6775 | if (wdev->netdev) |
| 6776 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6777 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6778 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6779 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6780 | kfree(request); |
| 6781 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6782 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6783 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6784 | return err; |
| 6785 | } |
| 6786 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6787 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6788 | { |
| 6789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6790 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6791 | |
| 6792 | if (!rdev->ops->abort_scan) |
| 6793 | return -EOPNOTSUPP; |
| 6794 | |
| 6795 | if (rdev->scan_msg) |
| 6796 | return 0; |
| 6797 | |
| 6798 | if (!rdev->scan_req) |
| 6799 | return -ENOENT; |
| 6800 | |
| 6801 | rdev_abort_scan(rdev, wdev); |
| 6802 | return 0; |
| 6803 | } |
| 6804 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6805 | static int |
| 6806 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6807 | struct cfg80211_sched_scan_request *request, |
| 6808 | struct nlattr **attrs) |
| 6809 | { |
| 6810 | int tmp, err, i = 0; |
| 6811 | struct nlattr *attr; |
| 6812 | |
| 6813 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6814 | u32 interval; |
| 6815 | |
| 6816 | /* |
| 6817 | * If scan plans are not specified, |
| 6818 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6819 | * case one scan plan will be set with the specified scan |
| 6820 | * interval and infinite number of iterations. |
| 6821 | */ |
| 6822 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6823 | return -EINVAL; |
| 6824 | |
| 6825 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6826 | if (!interval) |
| 6827 | return -EINVAL; |
| 6828 | |
| 6829 | request->scan_plans[0].interval = |
| 6830 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6831 | if (!request->scan_plans[0].interval) |
| 6832 | return -EINVAL; |
| 6833 | |
| 6834 | if (request->scan_plans[0].interval > |
| 6835 | wiphy->max_sched_scan_plan_interval) |
| 6836 | request->scan_plans[0].interval = |
| 6837 | wiphy->max_sched_scan_plan_interval; |
| 6838 | |
| 6839 | return 0; |
| 6840 | } |
| 6841 | |
| 6842 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6843 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6844 | |
| 6845 | if (WARN_ON(i >= n_plans)) |
| 6846 | return -EINVAL; |
| 6847 | |
| 6848 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6849 | nla_data(attr), nla_len(attr), |
| 6850 | nl80211_plan_policy); |
| 6851 | if (err) |
| 6852 | return err; |
| 6853 | |
| 6854 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6855 | return -EINVAL; |
| 6856 | |
| 6857 | request->scan_plans[i].interval = |
| 6858 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6859 | if (!request->scan_plans[i].interval || |
| 6860 | request->scan_plans[i].interval > |
| 6861 | wiphy->max_sched_scan_plan_interval) |
| 6862 | return -EINVAL; |
| 6863 | |
| 6864 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6865 | request->scan_plans[i].iterations = |
| 6866 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6867 | if (!request->scan_plans[i].iterations || |
| 6868 | (request->scan_plans[i].iterations > |
| 6869 | wiphy->max_sched_scan_plan_iterations)) |
| 6870 | return -EINVAL; |
| 6871 | } else if (i < n_plans - 1) { |
| 6872 | /* |
| 6873 | * All scan plans but the last one must specify |
| 6874 | * a finite number of iterations |
| 6875 | */ |
| 6876 | return -EINVAL; |
| 6877 | } |
| 6878 | |
| 6879 | i++; |
| 6880 | } |
| 6881 | |
| 6882 | /* |
| 6883 | * The last scan plan must not specify the number of |
| 6884 | * iterations, it is supposed to run infinitely |
| 6885 | */ |
| 6886 | if (request->scan_plans[n_plans - 1].iterations) |
| 6887 | return -EINVAL; |
| 6888 | |
| 6889 | return 0; |
| 6890 | } |
| 6891 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6892 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6893 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6894 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6895 | { |
| 6896 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6897 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6898 | 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] | 6899 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6900 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6901 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6902 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6903 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6904 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6905 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6906 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6907 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6908 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6909 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6910 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6911 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6912 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6913 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6914 | } |
| 6915 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6916 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6917 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6918 | tmp) |
| 6919 | n_ssids++; |
| 6920 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6921 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6922 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6923 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6924 | /* |
| 6925 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6926 | * the old implementation, matchsets containing only the RSSI attribute |
| 6927 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6928 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6929 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6930 | * older userspace that treated a matchset with only the RSSI as the |
| 6931 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6932 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6933 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6934 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6935 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6936 | tmp) { |
| 6937 | struct nlattr *rssi; |
| 6938 | |
| 6939 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6940 | nla_data(attr), nla_len(attr), |
| 6941 | nl80211_match_policy); |
| 6942 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6943 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6944 | /* add other standalone attributes here */ |
| 6945 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6946 | n_match_sets++; |
| 6947 | continue; |
| 6948 | } |
| 6949 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6950 | if (rssi) |
| 6951 | default_match_rssi = nla_get_s32(rssi); |
| 6952 | } |
| 6953 | } |
| 6954 | |
| 6955 | /* However, if there's no other matchset, add the RSSI one */ |
| 6956 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6957 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6958 | |
| 6959 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6960 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6961 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6962 | if (attrs[NL80211_ATTR_IE]) |
| 6963 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6964 | else |
| 6965 | ie_len = 0; |
| 6966 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6967 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6968 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6969 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6970 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6971 | /* |
| 6972 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6973 | * each scan plan already specifies its own interval |
| 6974 | */ |
| 6975 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6976 | return ERR_PTR(-EINVAL); |
| 6977 | |
| 6978 | nla_for_each_nested(attr, |
| 6979 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6980 | n_plans++; |
| 6981 | } else { |
| 6982 | /* |
| 6983 | * The scan interval attribute is kept for backward |
| 6984 | * compatibility. If no scan plans are specified and sched scan |
| 6985 | * interval is specified, one scan plan will be set with this |
| 6986 | * scan interval and infinite number of iterations. |
| 6987 | */ |
| 6988 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6989 | return ERR_PTR(-EINVAL); |
| 6990 | |
| 6991 | n_plans = 1; |
| 6992 | } |
| 6993 | |
| 6994 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6995 | return ERR_PTR(-EINVAL); |
| 6996 | |
vamsi krishna | f4f1a54 | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 6997 | if (!wiphy_ext_feature_isset( |
| 6998 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 6999 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7000 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7001 | return ERR_PTR(-EINVAL); |
| 7002 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7003 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7004 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7005 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7006 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7007 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7008 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7009 | if (!request) |
| 7010 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7011 | |
| 7012 | if (n_ssids) |
| 7013 | request->ssids = (void *)&request->channels[n_channels]; |
| 7014 | request->n_ssids = n_ssids; |
| 7015 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7016 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7017 | request->ie = (void *)(request->ssids + n_ssids); |
| 7018 | else |
| 7019 | request->ie = (void *)(request->channels + n_channels); |
| 7020 | } |
| 7021 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7022 | if (n_match_sets) { |
| 7023 | if (request->ie) |
| 7024 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7025 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7026 | request->match_sets = |
| 7027 | (void *)(request->ssids + n_ssids); |
| 7028 | else |
| 7029 | request->match_sets = |
| 7030 | (void *)(request->channels + n_channels); |
| 7031 | } |
| 7032 | request->n_match_sets = n_match_sets; |
| 7033 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7034 | if (n_match_sets) |
| 7035 | request->scan_plans = (void *)(request->match_sets + |
| 7036 | n_match_sets); |
| 7037 | else if (request->ie) |
| 7038 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7039 | else if (n_ssids) |
| 7040 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7041 | else |
| 7042 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7043 | |
| 7044 | request->n_scan_plans = n_plans; |
| 7045 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7046 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7047 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7048 | /* user specified, bail out if channel not found */ |
| 7049 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7050 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7051 | tmp) { |
| 7052 | struct ieee80211_channel *chan; |
| 7053 | |
| 7054 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7055 | |
| 7056 | if (!chan) { |
| 7057 | err = -EINVAL; |
| 7058 | goto out_free; |
| 7059 | } |
| 7060 | |
| 7061 | /* ignore disabled channels */ |
| 7062 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7063 | continue; |
| 7064 | |
| 7065 | request->channels[i] = chan; |
| 7066 | i++; |
| 7067 | } |
| 7068 | } else { |
| 7069 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7070 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7071 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7072 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7073 | if (!wiphy->bands[band]) |
| 7074 | continue; |
| 7075 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7076 | struct ieee80211_channel *chan; |
| 7077 | |
| 7078 | chan = &wiphy->bands[band]->channels[j]; |
| 7079 | |
| 7080 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7081 | continue; |
| 7082 | |
| 7083 | request->channels[i] = chan; |
| 7084 | i++; |
| 7085 | } |
| 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | if (!i) { |
| 7090 | err = -EINVAL; |
| 7091 | goto out_free; |
| 7092 | } |
| 7093 | |
| 7094 | request->n_channels = i; |
| 7095 | |
| 7096 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7097 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7098 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7099 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7100 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7101 | err = -EINVAL; |
| 7102 | goto out_free; |
| 7103 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7104 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7105 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7106 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7107 | i++; |
| 7108 | } |
| 7109 | } |
| 7110 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7111 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7112 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7113 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7114 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7115 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 7116 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7117 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7118 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 7119 | nla_data(attr), nla_len(attr), |
| 7120 | nl80211_match_policy); |
| 7121 | if (err) |
| 7122 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7123 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7124 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7125 | if (WARN_ON(i >= n_match_sets)) { |
| 7126 | /* this indicates a programming error, |
| 7127 | * the loop above should have verified |
| 7128 | * things properly |
| 7129 | */ |
| 7130 | err = -EINVAL; |
| 7131 | goto out_free; |
| 7132 | } |
| 7133 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7134 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7135 | err = -EINVAL; |
| 7136 | goto out_free; |
| 7137 | } |
| 7138 | memcpy(request->match_sets[i].ssid.ssid, |
| 7139 | nla_data(ssid), nla_len(ssid)); |
| 7140 | request->match_sets[i].ssid.ssid_len = |
| 7141 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7142 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7143 | request->match_sets[i].rssi_thold = |
| 7144 | default_match_rssi; |
| 7145 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7146 | if (rssi) |
| 7147 | request->match_sets[i].rssi_thold = |
| 7148 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7149 | } |
| 7150 | i++; |
| 7151 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7152 | |
| 7153 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7154 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7155 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7156 | |
| 7157 | request->min_rssi_thold = INT_MAX; |
| 7158 | for (i = 0; i < n_match_sets; i++) |
| 7159 | request->min_rssi_thold = |
| 7160 | min(request->match_sets[i].rssi_thold, |
| 7161 | request->min_rssi_thold); |
| 7162 | } else { |
| 7163 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7164 | } |
| 7165 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7166 | if (ie_len) { |
| 7167 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7168 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7169 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7170 | request->ie_len); |
| 7171 | } |
| 7172 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7173 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7174 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7175 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 7176 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7177 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7178 | err = -EOPNOTSUPP; |
| 7179 | goto out_free; |
| 7180 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7181 | |
| 7182 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7183 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 7184 | |
| 7185 | if (!wdev) /* must be net-detect */ |
| 7186 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7187 | |
| 7188 | if (!(wiphy->features & flg)) { |
| 7189 | err = -EOPNOTSUPP; |
| 7190 | goto out_free; |
| 7191 | } |
| 7192 | |
| 7193 | if (wdev && wdev->current_bss) { |
| 7194 | err = -EOPNOTSUPP; |
| 7195 | goto out_free; |
| 7196 | } |
| 7197 | |
| 7198 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 7199 | request->mac_addr_mask); |
| 7200 | if (err) |
| 7201 | goto out_free; |
| 7202 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7203 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7204 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7205 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7206 | request->delay = |
| 7207 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7208 | |
vamsi krishna | f4f1a54 | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7209 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7210 | request->relative_rssi = nla_get_s8( |
| 7211 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7212 | request->relative_rssi_set = true; |
| 7213 | } |
| 7214 | |
| 7215 | if (request->relative_rssi_set && |
| 7216 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7217 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7218 | |
| 7219 | rssi_adjust = nla_data( |
| 7220 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7221 | request->rssi_adjust.band = rssi_adjust->band; |
| 7222 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7223 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7224 | err = -EINVAL; |
| 7225 | goto out_free; |
| 7226 | } |
| 7227 | } |
| 7228 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7229 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7230 | if (err) |
| 7231 | goto out_free; |
| 7232 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7233 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7234 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7235 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7236 | |
| 7237 | out_free: |
| 7238 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7239 | return ERR_PTR(err); |
| 7240 | } |
| 7241 | |
| 7242 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7243 | struct genl_info *info) |
| 7244 | { |
| 7245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7246 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7247 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7248 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7249 | int err; |
| 7250 | |
| 7251 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7252 | !rdev->ops->sched_scan_start) |
| 7253 | return -EOPNOTSUPP; |
| 7254 | |
| 7255 | if (rdev->sched_scan_req) |
| 7256 | return -EINPROGRESS; |
| 7257 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7258 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 7259 | info->attrs); |
| 7260 | |
| 7261 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7262 | if (err) |
| 7263 | goto out_err; |
| 7264 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7265 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7266 | if (err) |
| 7267 | goto out_free; |
| 7268 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7269 | sched_scan_req->dev = dev; |
| 7270 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7271 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7272 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7273 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7274 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7275 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7276 | |
| 7277 | nl80211_send_sched_scan(rdev, dev, |
| 7278 | NL80211_CMD_START_SCHED_SCAN); |
| 7279 | return 0; |
| 7280 | |
| 7281 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7282 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7283 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7284 | return err; |
| 7285 | } |
| 7286 | |
| 7287 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7288 | struct genl_info *info) |
| 7289 | { |
| 7290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7291 | |
| 7292 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7293 | !rdev->ops->sched_scan_stop) |
| 7294 | return -EOPNOTSUPP; |
| 7295 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7296 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7297 | } |
| 7298 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7299 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7300 | struct genl_info *info) |
| 7301 | { |
| 7302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7303 | struct net_device *dev = info->user_ptr[1]; |
| 7304 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7305 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7306 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7307 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7308 | int err; |
| 7309 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7310 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7311 | if (dfs_region == NL80211_DFS_UNSET) |
| 7312 | return -EINVAL; |
| 7313 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7314 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7315 | if (err) |
| 7316 | return err; |
| 7317 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7318 | if (netif_carrier_ok(dev)) |
| 7319 | return -EBUSY; |
| 7320 | |
Amar Singhal | 42839af | 2014-03-19 18:36:58 -0700 | [diff] [blame] | 7321 | if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD) |
| 7322 | return -EOPNOTSUPP; |
| 7323 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7324 | if (wdev->cac_started) |
| 7325 | return -EBUSY; |
| 7326 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7327 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7328 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7329 | if (err < 0) |
| 7330 | return err; |
| 7331 | |
| 7332 | if (err == 0) |
| 7333 | return -EINVAL; |
| 7334 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7335 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7336 | return -EINVAL; |
| 7337 | |
| 7338 | if (!rdev->ops->start_radar_detection) |
| 7339 | return -EOPNOTSUPP; |
| 7340 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7341 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7342 | if (WARN_ON(!cac_time_ms)) |
| 7343 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7344 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7345 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7346 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7347 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7348 | wdev->cac_started = true; |
| 7349 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7350 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7351 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7352 | return err; |
| 7353 | } |
| 7354 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7355 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7356 | { |
| 7357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7358 | struct net_device *dev = info->user_ptr[1]; |
| 7359 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7360 | struct cfg80211_csa_settings params; |
| 7361 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7362 | * function is called under RTNL lock, so this should not be a problem. |
| 7363 | */ |
| 7364 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7365 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7366 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7367 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7368 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7369 | |
| 7370 | if (!rdev->ops->channel_switch || |
| 7371 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7372 | return -EOPNOTSUPP; |
| 7373 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7374 | switch (dev->ieee80211_ptr->iftype) { |
| 7375 | case NL80211_IFTYPE_AP: |
| 7376 | case NL80211_IFTYPE_P2P_GO: |
| 7377 | need_new_beacon = true; |
| 7378 | |
| 7379 | /* useless if AP is not running */ |
| 7380 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7381 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7382 | break; |
| 7383 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7384 | if (!wdev->ssid_len) |
| 7385 | return -ENOTCONN; |
| 7386 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7387 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7388 | if (!wdev->mesh_id_len) |
| 7389 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7390 | break; |
| 7391 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7392 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7393 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7394 | |
| 7395 | memset(¶ms, 0, sizeof(params)); |
| 7396 | |
| 7397 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7398 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7399 | return -EINVAL; |
| 7400 | |
| 7401 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7402 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7403 | return -EINVAL; |
| 7404 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7405 | /* Even though the attribute is u32, the specification says |
| 7406 | * u8, so let's make sure we don't overflow. |
| 7407 | */ |
| 7408 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7409 | if (cs_count > 255) |
| 7410 | return -EINVAL; |
| 7411 | |
| 7412 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7413 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7414 | if (!need_new_beacon) |
| 7415 | goto skip_beacons; |
| 7416 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7417 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7418 | if (err) |
| 7419 | return err; |
| 7420 | |
| 7421 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7422 | info->attrs[NL80211_ATTR_CSA_IES], |
| 7423 | nl80211_policy); |
| 7424 | if (err) |
| 7425 | return err; |
| 7426 | |
| 7427 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7428 | if (err) |
| 7429 | return err; |
| 7430 | |
| 7431 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7432 | return -EINVAL; |
| 7433 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7434 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7435 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7436 | return -EINVAL; |
| 7437 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7438 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7439 | if (rdev->wiphy.max_num_csa_counters && |
| 7440 | (params.n_counter_offsets_beacon > |
| 7441 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7442 | return -EINVAL; |
| 7443 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7444 | params.counter_offsets_beacon = |
| 7445 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7446 | |
| 7447 | /* sanity checks - counters should fit and be the same */ |
| 7448 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7449 | u16 offset = params.counter_offsets_beacon[i]; |
| 7450 | |
| 7451 | if (offset >= params.beacon_csa.tail_len) |
| 7452 | return -EINVAL; |
| 7453 | |
| 7454 | if (params.beacon_csa.tail[offset] != params.count) |
| 7455 | return -EINVAL; |
| 7456 | } |
| 7457 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7458 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7459 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7460 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7461 | return -EINVAL; |
| 7462 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7463 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7464 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7465 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7466 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7467 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7468 | |
| 7469 | params.counter_offsets_presp = |
| 7470 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7471 | |
| 7472 | /* sanity checks - counters should fit and be the same */ |
| 7473 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7474 | u16 offset = params.counter_offsets_presp[i]; |
| 7475 | |
| 7476 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7477 | return -EINVAL; |
| 7478 | |
| 7479 | if (params.beacon_csa.probe_resp[offset] != |
| 7480 | params.count) |
| 7481 | return -EINVAL; |
| 7482 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7483 | } |
| 7484 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7485 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7486 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7487 | if (err) |
| 7488 | return err; |
| 7489 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7490 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7491 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7492 | return -EINVAL; |
| 7493 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7494 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7495 | ¶ms.chandef, |
| 7496 | wdev->iftype); |
| 7497 | if (err < 0) |
| 7498 | return err; |
| 7499 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 7500 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7501 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7502 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7503 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7504 | params.block_tx = true; |
| 7505 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7506 | wdev_lock(wdev); |
| 7507 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7508 | wdev_unlock(wdev); |
| 7509 | |
| 7510 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7511 | } |
| 7512 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7513 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7514 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7515 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7516 | struct wireless_dev *wdev, |
| 7517 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7518 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7519 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7520 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7521 | void *hdr; |
| 7522 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7523 | |
| 7524 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7525 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7526 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7527 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7528 | if (!hdr) |
| 7529 | return -1; |
| 7530 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7531 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7532 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7533 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7534 | goto nla_put_failure; |
| 7535 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7536 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7537 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7538 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7539 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7540 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7541 | |
| 7542 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7543 | if (!bss) |
| 7544 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7545 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7546 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7547 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7548 | |
| 7549 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7550 | /* indicate whether we have probe response data or not */ |
| 7551 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7552 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7553 | goto fail_unlock_rcu; |
| 7554 | |
| 7555 | /* this pointer prefers to be pointed to probe response data |
| 7556 | * but is always valid |
| 7557 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7558 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7559 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7560 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7561 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7562 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7563 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7564 | ies->len, ies->data)) |
| 7565 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7566 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7567 | |
| 7568 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7569 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7570 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7571 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7572 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7573 | goto fail_unlock_rcu; |
| 7574 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7575 | ies->len, ies->data)) |
| 7576 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7577 | } |
| 7578 | rcu_read_unlock(); |
| 7579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7580 | if (res->beacon_interval && |
| 7581 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7582 | goto nla_put_failure; |
| 7583 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7584 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7585 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7586 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7587 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7588 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7589 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7590 | if (intbss->parent_tsf && |
| 7591 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7592 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7593 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7594 | intbss->parent_bssid))) |
| 7595 | goto nla_put_failure; |
| 7596 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7597 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7598 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7599 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7600 | goto nla_put_failure; |
| 7601 | |
Sunil Dutt | 0c86848 | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 7602 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 7603 | intbss->pub.chain_signal, |
| 7604 | NL80211_BSS_CHAIN_SIGNAL)) |
| 7605 | goto nla_put_failure; |
| 7606 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7607 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7608 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7609 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7610 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7611 | break; |
| 7612 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7613 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7614 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7615 | break; |
| 7616 | default: |
| 7617 | break; |
| 7618 | } |
| 7619 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7620 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7621 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7622 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7623 | if (intbss == wdev->current_bss && |
| 7624 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7625 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7626 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7627 | break; |
| 7628 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7629 | if (intbss == wdev->current_bss && |
| 7630 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7631 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7632 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7633 | break; |
| 7634 | default: |
| 7635 | break; |
| 7636 | } |
| 7637 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7638 | nla_nest_end(msg, bss); |
| 7639 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7640 | genlmsg_end(msg, hdr); |
| 7641 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7642 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7643 | fail_unlock_rcu: |
| 7644 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7645 | nla_put_failure: |
| 7646 | genlmsg_cancel(msg, hdr); |
| 7647 | return -EMSGSIZE; |
| 7648 | } |
| 7649 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7650 | 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] | 7651 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7652 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7653 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7654 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7655 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7656 | int err; |
| 7657 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7658 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7659 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7660 | if (err) { |
| 7661 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7662 | return err; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7663 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7664 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7665 | wdev_lock(wdev); |
| 7666 | spin_lock_bh(&rdev->bss_lock); |
| 7667 | cfg80211_bss_expire(rdev); |
| 7668 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7669 | cb->seq = rdev->bss_generation; |
| 7670 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7671 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7672 | if (++idx <= start) |
| 7673 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7674 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7675 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7676 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7677 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7678 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7679 | } |
| 7680 | } |
| 7681 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7682 | spin_unlock_bh(&rdev->bss_lock); |
| 7683 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7684 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7685 | cb->args[2] = idx; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7686 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7687 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7688 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7689 | } |
| 7690 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7691 | 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] | 7692 | int flags, struct net_device *dev, |
| 7693 | bool allow_radio_stats, |
| 7694 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7695 | { |
| 7696 | void *hdr; |
| 7697 | struct nlattr *infoattr; |
| 7698 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7699 | /* skip radio stats if userspace didn't request them */ |
| 7700 | if (!survey->channel && !allow_radio_stats) |
| 7701 | return 0; |
| 7702 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7703 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7704 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7705 | if (!hdr) |
| 7706 | return -ENOMEM; |
| 7707 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7708 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7709 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7710 | |
| 7711 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7712 | if (!infoattr) |
| 7713 | goto nla_put_failure; |
| 7714 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7715 | if (survey->channel && |
| 7716 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7717 | survey->channel->center_freq)) |
| 7718 | goto nla_put_failure; |
| 7719 | |
| 7720 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7721 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7722 | goto nla_put_failure; |
| 7723 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7724 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7725 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7726 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7727 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7728 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7729 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7730 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7731 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7732 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7733 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7734 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7735 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7736 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7737 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7738 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7739 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7740 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7741 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7742 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7743 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7744 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7745 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7746 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7747 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7748 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7749 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7750 | |
| 7751 | nla_nest_end(msg, infoattr); |
| 7752 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7753 | genlmsg_end(msg, hdr); |
| 7754 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7755 | |
| 7756 | nla_put_failure: |
| 7757 | genlmsg_cancel(msg, hdr); |
| 7758 | return -EMSGSIZE; |
| 7759 | } |
| 7760 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7761 | 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] | 7762 | { |
| 7763 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7764 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7765 | struct wireless_dev *wdev; |
| 7766 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7767 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7768 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7769 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7770 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7771 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7772 | if (res) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7773 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7774 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7775 | /* prepare_wdev_dump parsed the attributes */ |
| 7776 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 7777 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7778 | if (!wdev->netdev) { |
| 7779 | res = -EINVAL; |
| 7780 | goto out_err; |
| 7781 | } |
| 7782 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7783 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7784 | res = -EOPNOTSUPP; |
| 7785 | goto out_err; |
| 7786 | } |
| 7787 | |
| 7788 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7789 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7790 | if (res == -ENOENT) |
| 7791 | break; |
| 7792 | if (res) |
| 7793 | goto out_err; |
| 7794 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7795 | /* don't send disabled channels, but do send non-channel data */ |
| 7796 | if (survey.channel && |
| 7797 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7798 | survey_idx++; |
| 7799 | continue; |
| 7800 | } |
| 7801 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7802 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7803 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7804 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7805 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7806 | goto out; |
| 7807 | survey_idx++; |
| 7808 | } |
| 7809 | |
| 7810 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7811 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7812 | res = skb->len; |
| 7813 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7814 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7815 | return res; |
| 7816 | } |
| 7817 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7818 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7819 | { |
| 7820 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7821 | NL80211_WPA_VERSION_2)); |
| 7822 | } |
| 7823 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7824 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7827 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7828 | struct ieee80211_channel *chan; |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7829 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 7830 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7831 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7832 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7833 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7834 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7835 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7836 | return -EINVAL; |
| 7837 | |
| 7838 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7839 | return -EINVAL; |
| 7840 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7841 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7842 | return -EINVAL; |
| 7843 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7844 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7845 | return -EINVAL; |
| 7846 | |
| 7847 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7848 | return -EINVAL; |
| 7849 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7850 | err = nl80211_parse_key(info, &key); |
| 7851 | if (err) |
| 7852 | return err; |
| 7853 | |
| 7854 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7855 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7856 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7857 | if (!key.p.key || !key.p.key_len) |
| 7858 | return -EINVAL; |
| 7859 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7860 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7861 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7862 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7863 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 7864 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7865 | return -EINVAL; |
| 7866 | } else { |
| 7867 | key.p.key_len = 0; |
| 7868 | key.p.key = NULL; |
| 7869 | } |
| 7870 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7871 | if (key.idx >= 0) { |
| 7872 | int i; |
| 7873 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7874 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7875 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7876 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7877 | ok = true; |
| 7878 | break; |
| 7879 | } |
| 7880 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7881 | if (!ok) |
| 7882 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7883 | } |
| 7884 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7885 | if (!rdev->ops->auth) |
| 7886 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7887 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7888 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7889 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7890 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7891 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7892 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7893 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7894 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7895 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7896 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7897 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7898 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7899 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7900 | |
| 7901 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7902 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7903 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7904 | } |
| 7905 | |
| 7906 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7907 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7908 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7909 | |
Jouni Malinen | e20f90f | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 7910 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 7911 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 7912 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 7913 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7914 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7915 | return -EINVAL; |
| 7916 | |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7917 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | e20f90f | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 7918 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 7919 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 7920 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 7921 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7922 | return -EINVAL; |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7923 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 7924 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7925 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7926 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7927 | return -EINVAL; |
| 7928 | } |
| 7929 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7930 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7931 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7932 | /* |
| 7933 | * Since we no longer track auth state, ignore |
| 7934 | * requests to only change local state. |
| 7935 | */ |
| 7936 | if (local_state_change) |
| 7937 | return 0; |
| 7938 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7939 | wdev_lock(dev->ieee80211_ptr); |
| 7940 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7941 | ssid, ssid_len, ie, ie_len, |
| 7942 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 3255b4a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7943 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7944 | wdev_unlock(dev->ieee80211_ptr); |
| 7945 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7946 | } |
| 7947 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7948 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7949 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7950 | struct cfg80211_crypto_settings *settings, |
| 7951 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7952 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7953 | memset(settings, 0, sizeof(*settings)); |
| 7954 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7955 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7956 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7957 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7958 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7959 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7960 | proto = nla_get_u16( |
| 7961 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7962 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7963 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7964 | proto != ETH_P_PAE) |
| 7965 | return -EINVAL; |
| 7966 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7967 | settings->control_port_no_encrypt = true; |
| 7968 | } else |
| 7969 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7970 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7971 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7972 | void *data; |
| 7973 | int len, i; |
| 7974 | |
| 7975 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7976 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7977 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7978 | |
| 7979 | if (len % sizeof(u32)) |
| 7980 | return -EINVAL; |
| 7981 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7982 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7983 | return -EINVAL; |
| 7984 | |
| 7985 | memcpy(settings->ciphers_pairwise, data, len); |
| 7986 | |
| 7987 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7988 | if (!cfg80211_supported_cipher_suite( |
| 7989 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7990 | settings->ciphers_pairwise[i])) |
| 7991 | return -EINVAL; |
| 7992 | } |
| 7993 | |
| 7994 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7995 | settings->cipher_group = |
| 7996 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7997 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7998 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7999 | return -EINVAL; |
| 8000 | } |
| 8001 | |
| 8002 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8003 | settings->wpa_versions = |
| 8004 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8005 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8006 | return -EINVAL; |
| 8007 | } |
| 8008 | |
| 8009 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8010 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8011 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8012 | |
| 8013 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8014 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8015 | settings->n_akm_suites = len / sizeof(u32); |
| 8016 | |
| 8017 | if (len % sizeof(u32)) |
| 8018 | return -EINVAL; |
| 8019 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8020 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8021 | return -EINVAL; |
| 8022 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8023 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8024 | } |
| 8025 | |
| 8026 | return 0; |
| 8027 | } |
| 8028 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8029 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8030 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8032 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8033 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8034 | struct cfg80211_assoc_request req = {}; |
| 8035 | const u8 *bssid, *ssid; |
| 8036 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8037 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8038 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8039 | return -EINVAL; |
| 8040 | |
| 8041 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8042 | !info->attrs[NL80211_ATTR_SSID] || |
| 8043 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8044 | return -EINVAL; |
| 8045 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8046 | if (!rdev->ops->assoc) |
| 8047 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8048 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8049 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8050 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8051 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8052 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8053 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8054 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8055 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8056 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8057 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8058 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8059 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8060 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8061 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8062 | |
| 8063 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8064 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8065 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8066 | } |
| 8067 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8068 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8069 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8070 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8071 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8072 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8073 | else if (mfp != NL80211_MFP_NO) |
| 8074 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8075 | } |
| 8076 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8077 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8078 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8079 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8080 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8081 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8082 | |
| 8083 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8084 | memcpy(&req.ht_capa_mask, |
| 8085 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8086 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8087 | |
| 8088 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8089 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8090 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8091 | memcpy(&req.ht_capa, |
| 8092 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8093 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8094 | } |
| 8095 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8096 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8097 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8098 | |
| 8099 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8100 | memcpy(&req.vht_capa_mask, |
| 8101 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8102 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8103 | |
| 8104 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8105 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8106 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8107 | memcpy(&req.vht_capa, |
| 8108 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8109 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8110 | } |
| 8111 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8112 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8113 | if (!((rdev->wiphy.features & |
| 8114 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8115 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8116 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8117 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8118 | return -EINVAL; |
| 8119 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8120 | } |
| 8121 | |
Jouni Malinen | c9a6362 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8122 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8123 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8124 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8125 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8126 | return -EINVAL; |
| 8127 | req.fils_nonces = |
| 8128 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8129 | } |
| 8130 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8131 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8132 | if (!err) { |
| 8133 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | 5f3f4d3 | 2018-02-04 21:57:28 +0530 | [diff] [blame] | 8134 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8135 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8136 | ssid, ssid_len, &req); |
Andrzej Zaborowski | 5f3f4d3 | 2018-02-04 21:57:28 +0530 | [diff] [blame] | 8137 | |
| 8138 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8139 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8140 | info->snd_portid; |
| 8141 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8142 | bssid, ETH_ALEN); |
| 8143 | } |
| 8144 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8145 | wdev_unlock(dev->ieee80211_ptr); |
| 8146 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8147 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8148 | return err; |
| 8149 | } |
| 8150 | |
| 8151 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8152 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8154 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8155 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8156 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8157 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8158 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8159 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8160 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8161 | return -EINVAL; |
| 8162 | |
| 8163 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8164 | return -EINVAL; |
| 8165 | |
| 8166 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8167 | return -EINVAL; |
| 8168 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8169 | if (!rdev->ops->deauth) |
| 8170 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8171 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8172 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8173 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8174 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8175 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8176 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8177 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8178 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8179 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8180 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8181 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8182 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8183 | |
| 8184 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8185 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8186 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8187 | } |
| 8188 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8189 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8190 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8191 | wdev_lock(dev->ieee80211_ptr); |
| 8192 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8193 | local_state_change); |
| 8194 | wdev_unlock(dev->ieee80211_ptr); |
| 8195 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8196 | } |
| 8197 | |
| 8198 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8199 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8201 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8202 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8203 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8204 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8205 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8206 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8207 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8208 | return -EINVAL; |
| 8209 | |
| 8210 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8211 | return -EINVAL; |
| 8212 | |
| 8213 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8214 | return -EINVAL; |
| 8215 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8216 | if (!rdev->ops->disassoc) |
| 8217 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8218 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8219 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8220 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8221 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8222 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8223 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8224 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8225 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8226 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8227 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8228 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8229 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8230 | |
| 8231 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8232 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8233 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8234 | } |
| 8235 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8236 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8237 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8238 | wdev_lock(dev->ieee80211_ptr); |
| 8239 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8240 | local_state_change); |
| 8241 | wdev_unlock(dev->ieee80211_ptr); |
| 8242 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8243 | } |
| 8244 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8245 | static bool |
| 8246 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8247 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8248 | int rateval) |
| 8249 | { |
| 8250 | struct wiphy *wiphy = &rdev->wiphy; |
| 8251 | bool found = false; |
| 8252 | int band, i; |
| 8253 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8254 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8255 | struct ieee80211_supported_band *sband; |
| 8256 | |
| 8257 | sband = wiphy->bands[band]; |
| 8258 | if (!sband) |
| 8259 | continue; |
| 8260 | |
| 8261 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8262 | if (sband->bitrates[i].bitrate == rateval) { |
| 8263 | mcast_rate[band] = i + 1; |
| 8264 | found = true; |
| 8265 | break; |
| 8266 | } |
| 8267 | } |
| 8268 | } |
| 8269 | |
| 8270 | return found; |
| 8271 | } |
| 8272 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8273 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8274 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8276 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8277 | struct cfg80211_ibss_params ibss; |
| 8278 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8279 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8280 | int err; |
| 8281 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8282 | memset(&ibss, 0, sizeof(ibss)); |
| 8283 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8284 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8285 | return -EINVAL; |
| 8286 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8287 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8288 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8289 | return -EINVAL; |
| 8290 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8291 | ibss.beacon_interval = 100; |
| 8292 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8293 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8294 | ibss.beacon_interval = |
| 8295 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8296 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8297 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8298 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8299 | if (err) |
| 8300 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8302 | if (!rdev->ops->join_ibss) |
| 8303 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8304 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8305 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8306 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8307 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8308 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8309 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8310 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8311 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8312 | |
| 8313 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8314 | return -EINVAL; |
| 8315 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8316 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8317 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8318 | |
| 8319 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8320 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8321 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8322 | } |
| 8323 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8324 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8325 | if (err) |
| 8326 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8327 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8328 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8329 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8330 | return -EINVAL; |
| 8331 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8332 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8333 | case NL80211_CHAN_WIDTH_5: |
| 8334 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8335 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8336 | break; |
| 8337 | case NL80211_CHAN_WIDTH_20: |
| 8338 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8339 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8340 | return -EINVAL; |
| 8341 | break; |
| 8342 | case NL80211_CHAN_WIDTH_80: |
| 8343 | case NL80211_CHAN_WIDTH_80P80: |
| 8344 | case NL80211_CHAN_WIDTH_160: |
| 8345 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8346 | return -EINVAL; |
| 8347 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8348 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8349 | return -EINVAL; |
| 8350 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8351 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8352 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8353 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8354 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8355 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8356 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8357 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8358 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8359 | u8 *rates = |
| 8360 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8361 | int n_rates = |
| 8362 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8363 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8364 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8365 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8366 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8367 | &ibss.basic_rates); |
| 8368 | if (err) |
| 8369 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8370 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8371 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8372 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8373 | memcpy(&ibss.ht_capa_mask, |
| 8374 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8375 | sizeof(ibss.ht_capa_mask)); |
| 8376 | |
| 8377 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8378 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8379 | return -EINVAL; |
| 8380 | memcpy(&ibss.ht_capa, |
| 8381 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8382 | sizeof(ibss.ht_capa)); |
| 8383 | } |
| 8384 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8385 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8386 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8387 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8388 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8390 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8391 | bool no_ht = false; |
| 8392 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8393 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8394 | info->attrs[NL80211_ATTR_KEYS], |
| 8395 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8396 | if (IS_ERR(connkeys)) |
| 8397 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8398 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8399 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8400 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8401 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8402 | return -EINVAL; |
| 8403 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8404 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8405 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8406 | ibss.control_port = |
| 8407 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8408 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8409 | ibss.userspace_handles_dfs = |
| 8410 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8411 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8412 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8413 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8414 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8415 | return err; |
| 8416 | } |
| 8417 | |
| 8418 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8419 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8421 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8423 | if (!rdev->ops->leave_ibss) |
| 8424 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8427 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8428 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8429 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8430 | } |
| 8431 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8432 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8433 | { |
| 8434 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8435 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8436 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8437 | u32 nla_rate; |
| 8438 | int err; |
| 8439 | |
| 8440 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8441 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8442 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8443 | return -EOPNOTSUPP; |
| 8444 | |
| 8445 | if (!rdev->ops->set_mcast_rate) |
| 8446 | return -EOPNOTSUPP; |
| 8447 | |
| 8448 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8449 | |
| 8450 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8451 | return -EINVAL; |
| 8452 | |
| 8453 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8454 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8455 | return -EINVAL; |
| 8456 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8457 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8458 | |
| 8459 | return err; |
| 8460 | } |
| 8461 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8462 | static struct sk_buff * |
| 8463 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8464 | struct wireless_dev *wdev, int approxlen, |
| 8465 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8466 | enum nl80211_attrs attr, |
| 8467 | const struct nl80211_vendor_cmd_info *info, |
| 8468 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8469 | { |
| 8470 | struct sk_buff *skb; |
| 8471 | void *hdr; |
| 8472 | struct nlattr *data; |
| 8473 | |
| 8474 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8475 | if (!skb) |
| 8476 | return NULL; |
| 8477 | |
| 8478 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8479 | if (!hdr) { |
| 8480 | kfree_skb(skb); |
| 8481 | return NULL; |
| 8482 | } |
| 8483 | |
| 8484 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8485 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8486 | |
| 8487 | if (info) { |
| 8488 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8489 | info->vendor_id)) |
| 8490 | goto nla_put_failure; |
| 8491 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8492 | info->subcmd)) |
| 8493 | goto nla_put_failure; |
| 8494 | } |
| 8495 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8496 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8497 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8498 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8499 | goto nla_put_failure; |
| 8500 | if (wdev->netdev && |
| 8501 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8502 | wdev->netdev->ifindex)) |
| 8503 | goto nla_put_failure; |
| 8504 | } |
| 8505 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8506 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8507 | if (!data) |
| 8508 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8509 | |
| 8510 | ((void **)skb->cb)[0] = rdev; |
| 8511 | ((void **)skb->cb)[1] = hdr; |
| 8512 | ((void **)skb->cb)[2] = data; |
| 8513 | |
| 8514 | return skb; |
| 8515 | |
| 8516 | nla_put_failure: |
| 8517 | kfree_skb(skb); |
| 8518 | return NULL; |
| 8519 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8520 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8521 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8522 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8523 | enum nl80211_commands cmd, |
| 8524 | enum nl80211_attrs attr, |
| 8525 | int vendor_event_idx, |
| 8526 | int approxlen, gfp_t gfp) |
| 8527 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8528 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8529 | const struct nl80211_vendor_cmd_info *info; |
| 8530 | |
| 8531 | switch (cmd) { |
| 8532 | case NL80211_CMD_TESTMODE: |
| 8533 | if (WARN_ON(vendor_event_idx != -1)) |
| 8534 | return NULL; |
| 8535 | info = NULL; |
| 8536 | break; |
| 8537 | case NL80211_CMD_VENDOR: |
| 8538 | if (WARN_ON(vendor_event_idx < 0 || |
| 8539 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8540 | return NULL; |
| 8541 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8542 | break; |
| 8543 | default: |
| 8544 | WARN_ON(1); |
| 8545 | return NULL; |
| 8546 | } |
| 8547 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8548 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8549 | cmd, attr, info, gfp); |
| 8550 | } |
| 8551 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8552 | |
| 8553 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8554 | { |
| 8555 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8556 | void *hdr = ((void **)skb->cb)[1]; |
| 8557 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8558 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8559 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8560 | /* clear CB data for netlink core to own from now on */ |
| 8561 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8562 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8563 | nla_nest_end(skb, data); |
| 8564 | genlmsg_end(skb, hdr); |
| 8565 | |
| 8566 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8567 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8568 | |
| 8569 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8570 | mcgrp, gfp); |
| 8571 | } |
| 8572 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8573 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8574 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8575 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8578 | struct wireless_dev *wdev = |
| 8579 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8580 | int err; |
| 8581 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8582 | if (!rdev->ops->testmode_cmd) |
| 8583 | return -EOPNOTSUPP; |
| 8584 | |
| 8585 | if (IS_ERR(wdev)) { |
| 8586 | err = PTR_ERR(wdev); |
| 8587 | if (err != -EINVAL) |
| 8588 | return err; |
| 8589 | wdev = NULL; |
| 8590 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8591 | return -EINVAL; |
| 8592 | } |
| 8593 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8594 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8595 | return -EINVAL; |
| 8596 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8597 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8598 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8599 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8600 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8601 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8602 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8603 | return err; |
| 8604 | } |
| 8605 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8606 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8607 | struct netlink_callback *cb) |
| 8608 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8609 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8610 | int err; |
| 8611 | long phy_idx; |
| 8612 | void *data = NULL; |
| 8613 | int data_len = 0; |
| 8614 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8615 | rtnl_lock(); |
| 8616 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8617 | if (cb->args[0]) { |
| 8618 | /* |
| 8619 | * 0 is a valid index, but not valid for args[0], |
| 8620 | * so we need to offset by 1. |
| 8621 | */ |
| 8622 | phy_idx = cb->args[0] - 1; |
| 8623 | } else { |
| 8624 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 8625 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 8626 | nl80211_policy); |
| 8627 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8628 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8629 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8630 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 8631 | nl80211_fam.attrbuf); |
| 8632 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8633 | err = PTR_ERR(rdev); |
| 8634 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8635 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8636 | phy_idx = rdev->wiphy_idx; |
| 8637 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8638 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8639 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 8640 | cb->args[1] = |
| 8641 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 8642 | } |
| 8643 | |
| 8644 | if (cb->args[1]) { |
| 8645 | data = nla_data((void *)cb->args[1]); |
| 8646 | data_len = nla_len((void *)cb->args[1]); |
| 8647 | } |
| 8648 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8649 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8650 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8651 | err = -ENOENT; |
| 8652 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8653 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8654 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8655 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8656 | err = -EOPNOTSUPP; |
| 8657 | goto out_err; |
| 8658 | } |
| 8659 | |
| 8660 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8661 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8662 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8663 | NL80211_CMD_TESTMODE); |
| 8664 | struct nlattr *tmdata; |
| 8665 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8666 | if (!hdr) |
| 8667 | break; |
| 8668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8669 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8670 | genlmsg_cancel(skb, hdr); |
| 8671 | break; |
| 8672 | } |
| 8673 | |
| 8674 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8675 | if (!tmdata) { |
| 8676 | genlmsg_cancel(skb, hdr); |
| 8677 | break; |
| 8678 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8679 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8680 | nla_nest_end(skb, tmdata); |
| 8681 | |
| 8682 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8683 | genlmsg_cancel(skb, hdr); |
| 8684 | break; |
| 8685 | } else if (err) { |
| 8686 | genlmsg_cancel(skb, hdr); |
| 8687 | goto out_err; |
| 8688 | } |
| 8689 | |
| 8690 | genlmsg_end(skb, hdr); |
| 8691 | } |
| 8692 | |
| 8693 | err = skb->len; |
| 8694 | /* see above */ |
| 8695 | cb->args[0] = phy_idx + 1; |
| 8696 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8697 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8698 | return err; |
| 8699 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8700 | #endif |
| 8701 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8702 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8703 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8704 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8705 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8706 | struct cfg80211_connect_params connect; |
| 8707 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8708 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8709 | int err; |
| 8710 | |
| 8711 | memset(&connect, 0, sizeof(connect)); |
| 8712 | |
| 8713 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8714 | return -EINVAL; |
| 8715 | |
| 8716 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8717 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8718 | return -EINVAL; |
| 8719 | |
| 8720 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8721 | connect.auth_type = |
| 8722 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8723 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8724 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8725 | return -EINVAL; |
| 8726 | } else |
| 8727 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8728 | |
| 8729 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8730 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8731 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8732 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8733 | if (err) |
| 8734 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8735 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8736 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8737 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8738 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8739 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8740 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8741 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8742 | connect.bg_scan_period = -1; |
| 8743 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8744 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8745 | connect.bg_scan_period = |
| 8746 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8747 | } |
| 8748 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8749 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8750 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8751 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8752 | connect.bssid_hint = |
| 8753 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8754 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8755 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8756 | |
| 8757 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8758 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8759 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8760 | } |
| 8761 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8762 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8763 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8764 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8765 | connect.mfp != NL80211_MFP_NO) |
| 8766 | return -EINVAL; |
| 8767 | } else { |
| 8768 | connect.mfp = NL80211_MFP_NO; |
| 8769 | } |
| 8770 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8771 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8772 | connect.prev_bssid = |
| 8773 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8774 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8775 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8776 | connect.channel = nl80211_get_valid_chan( |
| 8777 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8778 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8779 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8780 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8781 | connect.channel_hint = nl80211_get_valid_chan( |
| 8782 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8783 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8784 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8785 | } |
| 8786 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8787 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8788 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8789 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8790 | if (IS_ERR(connkeys)) |
| 8791 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8792 | } |
| 8793 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8794 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8795 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8796 | |
| 8797 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8798 | memcpy(&connect.ht_capa_mask, |
| 8799 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8800 | sizeof(connect.ht_capa_mask)); |
| 8801 | |
| 8802 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8803 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8804 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8805 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8806 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8807 | memcpy(&connect.ht_capa, |
| 8808 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8809 | sizeof(connect.ht_capa)); |
| 8810 | } |
| 8811 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8812 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8813 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8814 | |
| 8815 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8816 | memcpy(&connect.vht_capa_mask, |
| 8817 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8818 | sizeof(connect.vht_capa_mask)); |
| 8819 | |
| 8820 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8821 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8822 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8823 | return -EINVAL; |
| 8824 | } |
| 8825 | memcpy(&connect.vht_capa, |
| 8826 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8827 | sizeof(connect.vht_capa)); |
| 8828 | } |
| 8829 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8830 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8831 | if (!((rdev->wiphy.features & |
| 8832 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8833 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8834 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8835 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8836 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8837 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8838 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8839 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8840 | } |
| 8841 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8842 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8843 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8844 | kzfree(connkeys); |
| 8845 | return -EOPNOTSUPP; |
| 8846 | } |
| 8847 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8848 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8849 | /* bss selection makes no sense if bssid is set */ |
| 8850 | if (connect.bssid) { |
| 8851 | kzfree(connkeys); |
| 8852 | return -EINVAL; |
| 8853 | } |
| 8854 | |
| 8855 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8856 | wiphy, &connect.bss_select); |
| 8857 | if (err) { |
| 8858 | kzfree(connkeys); |
| 8859 | return err; |
| 8860 | } |
| 8861 | } |
| 8862 | |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 8863 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 8864 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 8865 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 8866 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 8867 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 8868 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8869 | connect.fils_erp_username = |
| 8870 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8871 | connect.fils_erp_username_len = |
| 8872 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8873 | connect.fils_erp_realm = |
| 8874 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8875 | connect.fils_erp_realm_len = |
| 8876 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8877 | connect.fils_erp_next_seq_num = |
| 8878 | nla_get_u16( |
| 8879 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 8880 | connect.fils_erp_rrk = |
| 8881 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8882 | connect.fils_erp_rrk_len = |
| 8883 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8884 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 8885 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 8886 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 8887 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8888 | kzfree(connkeys); |
| 8889 | return -EINVAL; |
| 8890 | } |
| 8891 | |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 8892 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 8893 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8894 | return -EINVAL; |
| 8895 | } |
| 8896 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 8897 | } |
| 8898 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8899 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | 5f3f4d3 | 2018-02-04 21:57:28 +0530 | [diff] [blame] | 8900 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8901 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8902 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8903 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8904 | kzfree(connkeys); |
Andrzej Zaborowski | 5f3f4d3 | 2018-02-04 21:57:28 +0530 | [diff] [blame] | 8905 | |
| 8906 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8907 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 8908 | if (connect.bssid) |
| 8909 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8910 | connect.bssid, ETH_ALEN); |
| 8911 | else |
| 8912 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 8913 | 0, ETH_ALEN); |
| 8914 | } |
| 8915 | |
| 8916 | wdev_unlock(dev->ieee80211_ptr); |
| 8917 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8918 | return err; |
| 8919 | } |
| 8920 | |
vamsi krishna | 30da4e8 | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 8921 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 8922 | struct genl_info *info) |
| 8923 | { |
| 8924 | struct cfg80211_connect_params connect = {}; |
| 8925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8926 | struct net_device *dev = info->user_ptr[1]; |
| 8927 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8928 | u32 changed = 0; |
| 8929 | int ret; |
| 8930 | |
| 8931 | if (!rdev->ops->update_connect_params) |
| 8932 | return -EOPNOTSUPP; |
| 8933 | |
| 8934 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8935 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8936 | return -EINVAL; |
| 8937 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8938 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8939 | changed |= UPDATE_ASSOC_IES; |
| 8940 | } |
| 8941 | |
Vidyullatha Kanchanapally | 5f5a26b | 2017-08-02 16:31:40 +0530 | [diff] [blame] | 8942 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 8943 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 8944 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 8945 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 8946 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 8947 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8948 | connect.fils_erp_username = |
| 8949 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8950 | connect.fils_erp_username_len = |
| 8951 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8952 | connect.fils_erp_realm = |
| 8953 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8954 | connect.fils_erp_realm_len = |
| 8955 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8956 | connect.fils_erp_next_seq_num = |
| 8957 | nla_get_u16( |
| 8958 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 8959 | connect.fils_erp_rrk = |
| 8960 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8961 | connect.fils_erp_rrk_len = |
| 8962 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8963 | changed |= UPDATE_FILS_ERP_INFO; |
| 8964 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 8965 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 8966 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 8967 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8968 | return -EINVAL; |
| 8969 | } |
| 8970 | |
| 8971 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8972 | u32 auth_type = |
| 8973 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 8974 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 8975 | NL80211_CMD_CONNECT)) |
| 8976 | return -EINVAL; |
| 8977 | connect.auth_type = auth_type; |
| 8978 | changed |= UPDATE_AUTH_TYPE; |
| 8979 | } |
| 8980 | |
vamsi krishna | 30da4e8 | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 8981 | wdev_lock(dev->ieee80211_ptr); |
| 8982 | if (!wdev->current_bss) |
| 8983 | ret = -ENOLINK; |
| 8984 | else |
| 8985 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 8986 | wdev_unlock(dev->ieee80211_ptr); |
| 8987 | |
| 8988 | return ret; |
| 8989 | } |
| 8990 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8991 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8992 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8993 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8994 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8995 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8996 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8997 | |
| 8998 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8999 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9000 | else |
| 9001 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9002 | |
| 9003 | if (reason == 0) |
| 9004 | return -EINVAL; |
| 9005 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9006 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9007 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9008 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9009 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9010 | wdev_lock(dev->ieee80211_ptr); |
| 9011 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9012 | wdev_unlock(dev->ieee80211_ptr); |
| 9013 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9014 | } |
| 9015 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9016 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9017 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9019 | struct net *net; |
| 9020 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9021 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9022 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9023 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9024 | |
| 9025 | net = get_net_ns_by_pid(pid); |
| 9026 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9027 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9028 | |
| 9029 | net = get_net_ns_by_fd(fd); |
| 9030 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9031 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9032 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9033 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9034 | if (IS_ERR(net)) |
| 9035 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9036 | |
| 9037 | err = 0; |
| 9038 | |
| 9039 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9040 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9041 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9042 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9043 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9044 | return err; |
| 9045 | } |
| 9046 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9047 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9048 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9050 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9051 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9052 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9053 | struct cfg80211_pmksa pmksa; |
| 9054 | |
| 9055 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9056 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9057 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9058 | return -EINVAL; |
| 9059 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9060 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9061 | |
| 9062 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9063 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9064 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9065 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9066 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9067 | info->attrs[NL80211_ATTR_PMK])) { |
| 9068 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9069 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9070 | pmksa.cache_id = |
| 9071 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9072 | } else { |
| 9073 | return -EINVAL; |
| 9074 | } |
| 9075 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9076 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9077 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9078 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9079 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9080 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9081 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9082 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9083 | |
| 9084 | switch (info->genlhdr->cmd) { |
| 9085 | case NL80211_CMD_SET_PMKSA: |
| 9086 | rdev_ops = rdev->ops->set_pmksa; |
| 9087 | break; |
| 9088 | case NL80211_CMD_DEL_PMKSA: |
| 9089 | rdev_ops = rdev->ops->del_pmksa; |
| 9090 | break; |
| 9091 | default: |
| 9092 | WARN_ON(1); |
| 9093 | break; |
| 9094 | } |
| 9095 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9096 | if (!rdev_ops) |
| 9097 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9098 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9099 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9100 | } |
| 9101 | |
| 9102 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9103 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9105 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9106 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9107 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9108 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9109 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9111 | if (!rdev->ops->flush_pmksa) |
| 9112 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9113 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9114 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9115 | } |
| 9116 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9117 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9118 | { |
| 9119 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9120 | struct net_device *dev = info->user_ptr[1]; |
| 9121 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9122 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9123 | u16 status_code; |
| 9124 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9125 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9126 | |
| 9127 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9128 | !rdev->ops->tdls_mgmt) |
| 9129 | return -EOPNOTSUPP; |
| 9130 | |
| 9131 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9132 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9133 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9134 | !info->attrs[NL80211_ATTR_IE] || |
| 9135 | !info->attrs[NL80211_ATTR_MAC]) |
| 9136 | return -EINVAL; |
| 9137 | |
| 9138 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9139 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9140 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9141 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9142 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9143 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9144 | peer_capability = |
| 9145 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9146 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9147 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9148 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9149 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9150 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9151 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9152 | } |
| 9153 | |
| 9154 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9155 | { |
| 9156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9157 | struct net_device *dev = info->user_ptr[1]; |
| 9158 | enum nl80211_tdls_operation operation; |
| 9159 | u8 *peer; |
| 9160 | |
| 9161 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9162 | !rdev->ops->tdls_oper) |
| 9163 | return -EOPNOTSUPP; |
| 9164 | |
| 9165 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9166 | !info->attrs[NL80211_ATTR_MAC]) |
| 9167 | return -EINVAL; |
| 9168 | |
| 9169 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9170 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9171 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9172 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9173 | } |
| 9174 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9175 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9176 | struct genl_info *info) |
| 9177 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9179 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9180 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9181 | struct sk_buff *msg; |
| 9182 | void *hdr; |
| 9183 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9184 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9185 | int err; |
| 9186 | |
| 9187 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9188 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9189 | return -EINVAL; |
| 9190 | |
| 9191 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9192 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9193 | if (!rdev->ops->remain_on_channel || |
| 9194 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9195 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9196 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9197 | /* |
| 9198 | * We should be on that channel for at least a minimum amount of |
| 9199 | * time (10ms) but no longer than the driver supports. |
| 9200 | */ |
| 9201 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9202 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9203 | return -EINVAL; |
| 9204 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9205 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9206 | if (err) |
| 9207 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9208 | |
| 9209 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9210 | if (!msg) |
| 9211 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9212 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9213 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9214 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9215 | if (!hdr) { |
| 9216 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9217 | goto free_msg; |
| 9218 | } |
| 9219 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9220 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9221 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9222 | |
| 9223 | if (err) |
| 9224 | goto free_msg; |
| 9225 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9226 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9227 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9228 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9229 | |
| 9230 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9231 | |
| 9232 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9233 | |
| 9234 | nla_put_failure: |
| 9235 | err = -ENOBUFS; |
| 9236 | free_msg: |
| 9237 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9238 | return err; |
| 9239 | } |
| 9240 | |
| 9241 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9242 | struct genl_info *info) |
| 9243 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9245 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9246 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9247 | |
| 9248 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9249 | return -EINVAL; |
| 9250 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9251 | if (!rdev->ops->cancel_remain_on_channel) |
| 9252 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9253 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9254 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9255 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9256 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9257 | } |
| 9258 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9259 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9260 | struct genl_info *info) |
| 9261 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9262 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9264 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9265 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9267 | if (!rdev->ops->set_bitrate_mask) |
| 9268 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9269 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9270 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9271 | if (err) |
| 9272 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9273 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9274 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9275 | } |
| 9276 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9277 | 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] | 9278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9280 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9281 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9282 | |
| 9283 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9284 | return -EINVAL; |
| 9285 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9286 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9287 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9288 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9289 | switch (wdev->iftype) { |
| 9290 | case NL80211_IFTYPE_STATION: |
| 9291 | case NL80211_IFTYPE_ADHOC: |
| 9292 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9293 | case NL80211_IFTYPE_AP: |
| 9294 | case NL80211_IFTYPE_AP_VLAN: |
| 9295 | case NL80211_IFTYPE_MESH_POINT: |
| 9296 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9297 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9298 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9299 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9300 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9301 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9302 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9303 | |
| 9304 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9305 | if (!rdev->ops->mgmt_tx) |
| 9306 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9307 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9308 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9309 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9310 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9311 | } |
| 9312 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9313 | 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] | 9314 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9316 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9317 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9318 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9319 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9320 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9321 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9322 | struct cfg80211_mgmt_tx_params params = { |
| 9323 | .dont_wait_for_ack = |
| 9324 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9325 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9326 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9327 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9328 | return -EINVAL; |
| 9329 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9330 | if (!rdev->ops->mgmt_tx) |
| 9331 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9332 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9333 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9334 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9335 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9336 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9337 | case NL80211_IFTYPE_STATION: |
| 9338 | case NL80211_IFTYPE_ADHOC: |
| 9339 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9340 | case NL80211_IFTYPE_AP: |
| 9341 | case NL80211_IFTYPE_AP_VLAN: |
| 9342 | case NL80211_IFTYPE_MESH_POINT: |
| 9343 | case NL80211_IFTYPE_P2P_GO: |
| 9344 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9345 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9346 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9347 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9348 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9349 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9350 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9351 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9352 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9353 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9354 | |
| 9355 | /* |
| 9356 | * We should wait on the channel for at least a minimum amount |
| 9357 | * of time (10ms) but no longer than the driver supports. |
| 9358 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9359 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9360 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9361 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9362 | } |
| 9363 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9364 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9365 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9366 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9367 | return -EINVAL; |
| 9368 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9369 | 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] | 9370 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9371 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9372 | * the driver. The latter will use the current one |
| 9373 | */ |
| 9374 | chandef.chan = NULL; |
| 9375 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9376 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9377 | if (err) |
| 9378 | return err; |
| 9379 | } |
| 9380 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9381 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9382 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9383 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9384 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9385 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9386 | |
| 9387 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9388 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9389 | int i; |
| 9390 | |
| 9391 | if (len % sizeof(u16)) |
| 9392 | return -EINVAL; |
| 9393 | |
| 9394 | params.n_csa_offsets = len / sizeof(u16); |
| 9395 | params.csa_offsets = |
| 9396 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9397 | |
| 9398 | /* check that all the offsets fit the frame */ |
| 9399 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9400 | if (params.csa_offsets[i] >= params.len) |
| 9401 | return -EINVAL; |
| 9402 | } |
| 9403 | } |
| 9404 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9405 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9406 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9407 | if (!msg) |
| 9408 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9409 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9410 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9411 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9412 | if (!hdr) { |
| 9413 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9414 | goto free_msg; |
| 9415 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9416 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9417 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9418 | params.chan = chandef.chan; |
| 9419 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9420 | if (err) |
| 9421 | goto free_msg; |
| 9422 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9423 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9424 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9425 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9426 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9427 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9428 | genlmsg_end(msg, hdr); |
| 9429 | return genlmsg_reply(msg, info); |
| 9430 | } |
| 9431 | |
| 9432 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9433 | |
| 9434 | nla_put_failure: |
| 9435 | err = -ENOBUFS; |
| 9436 | free_msg: |
| 9437 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9438 | return err; |
| 9439 | } |
| 9440 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9441 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9442 | { |
| 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 | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9445 | u64 cookie; |
| 9446 | |
| 9447 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9448 | return -EINVAL; |
| 9449 | |
| 9450 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9451 | return -EOPNOTSUPP; |
| 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_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9460 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9461 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9462 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9463 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9464 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9465 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9466 | |
| 9467 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9468 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9469 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9470 | } |
| 9471 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9472 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9475 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9476 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9477 | u8 ps_state; |
| 9478 | bool state; |
| 9479 | int err; |
| 9480 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9481 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9482 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9483 | |
| 9484 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9486 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9487 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9488 | |
| 9489 | wdev = dev->ieee80211_ptr; |
| 9490 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9491 | if (!rdev->ops->set_power_mgmt) |
| 9492 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9493 | |
| 9494 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9495 | |
| 9496 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9497 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9498 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9499 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9500 | if (!err) |
| 9501 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9502 | return err; |
| 9503 | } |
| 9504 | |
| 9505 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9508 | enum nl80211_ps_state ps_state; |
| 9509 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9510 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9511 | struct sk_buff *msg; |
| 9512 | void *hdr; |
| 9513 | int err; |
| 9514 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9515 | wdev = dev->ieee80211_ptr; |
| 9516 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9517 | if (!rdev->ops->set_power_mgmt) |
| 9518 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9519 | |
| 9520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9521 | if (!msg) |
| 9522 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9523 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9524 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9525 | NL80211_CMD_GET_POWER_SAVE); |
| 9526 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9527 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9528 | goto free_msg; |
| 9529 | } |
| 9530 | |
| 9531 | if (wdev->ps) |
| 9532 | ps_state = NL80211_PS_ENABLED; |
| 9533 | else |
| 9534 | ps_state = NL80211_PS_DISABLED; |
| 9535 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9536 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9537 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9538 | |
| 9539 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9540 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9542 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9543 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9544 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9545 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9546 | return err; |
| 9547 | } |
| 9548 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9549 | static const struct nla_policy |
| 9550 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9551 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9552 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9553 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9554 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9555 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9556 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9557 | }; |
| 9558 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9559 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9560 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9561 | { |
| 9562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9563 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9565 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9566 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9567 | return -EINVAL; |
| 9568 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9569 | if (!rdev->ops->set_cqm_txe_config) |
| 9570 | return -EOPNOTSUPP; |
| 9571 | |
| 9572 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9573 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9574 | return -EOPNOTSUPP; |
| 9575 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9576 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9577 | } |
| 9578 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9579 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9580 | s32 threshold, u32 hysteresis) |
| 9581 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9583 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9584 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9585 | |
| 9586 | if (threshold > 0) |
| 9587 | return -EINVAL; |
| 9588 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9589 | /* disabling - hysteresis should also be zero then */ |
| 9590 | if (threshold == 0) |
| 9591 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9592 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | if (!rdev->ops->set_cqm_rssi_config) |
| 9594 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9595 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9596 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9597 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9598 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9599 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9600 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9601 | } |
| 9602 | |
| 9603 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9604 | { |
| 9605 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9606 | struct nlattr *cqm; |
| 9607 | int err; |
| 9608 | |
| 9609 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9610 | if (!cqm) |
| 9611 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9612 | |
| 9613 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9614 | nl80211_attr_cqm_policy); |
| 9615 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9616 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9617 | |
| 9618 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9619 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9620 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9621 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9622 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9623 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9624 | } |
| 9625 | |
| 9626 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9627 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9628 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9629 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9630 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9631 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9632 | |
| 9633 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9634 | } |
| 9635 | |
| 9636 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9637 | } |
| 9638 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9639 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9640 | { |
| 9641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9642 | struct net_device *dev = info->user_ptr[1]; |
| 9643 | struct ocb_setup setup = {}; |
| 9644 | int err; |
| 9645 | |
| 9646 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9647 | if (err) |
| 9648 | return err; |
| 9649 | |
| 9650 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9651 | } |
| 9652 | |
| 9653 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9654 | { |
| 9655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9656 | struct net_device *dev = info->user_ptr[1]; |
| 9657 | |
| 9658 | return cfg80211_leave_ocb(rdev, dev); |
| 9659 | } |
| 9660 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9661 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9662 | { |
| 9663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9664 | struct net_device *dev = info->user_ptr[1]; |
| 9665 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9666 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9667 | int err; |
| 9668 | |
| 9669 | /* start with default */ |
| 9670 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9671 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9672 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9673 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9674 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9675 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9676 | if (err) |
| 9677 | return err; |
| 9678 | } |
| 9679 | |
| 9680 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9681 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9682 | return -EINVAL; |
| 9683 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9684 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9685 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9686 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9687 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9688 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9689 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9690 | return -EINVAL; |
| 9691 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9692 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9693 | setup.beacon_interval = |
| 9694 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9695 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9696 | err = cfg80211_validate_beacon_int(rdev, |
| 9697 | NL80211_IFTYPE_MESH_POINT, |
| 9698 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9699 | if (err) |
| 9700 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9701 | } |
| 9702 | |
| 9703 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9704 | setup.dtim_period = |
| 9705 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9706 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9707 | return -EINVAL; |
| 9708 | } |
| 9709 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9710 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9711 | /* parse additional setup parameters if given */ |
| 9712 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9713 | if (err) |
| 9714 | return err; |
| 9715 | } |
| 9716 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9717 | if (setup.user_mpm) |
| 9718 | cfg.auto_open_plinks = false; |
| 9719 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9720 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9721 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9722 | if (err) |
| 9723 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9724 | } else { |
| 9725 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9726 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9727 | } |
| 9728 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9729 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9730 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9731 | int n_rates = |
| 9732 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9733 | struct ieee80211_supported_band *sband; |
| 9734 | |
| 9735 | if (!setup.chandef.chan) |
| 9736 | return -EINVAL; |
| 9737 | |
| 9738 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9739 | |
| 9740 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9741 | &setup.basic_rates); |
| 9742 | if (err) |
| 9743 | return err; |
| 9744 | } |
| 9745 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9746 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 9747 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 9748 | if (err) |
| 9749 | return err; |
| 9750 | |
Johannes Berg | 091eac3 | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 9751 | if (!setup.chandef.chan) |
| 9752 | return -EINVAL; |
| 9753 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9754 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 9755 | &setup.beacon_rate); |
| 9756 | if (err) |
| 9757 | return err; |
| 9758 | } |
| 9759 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9760 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9764 | { |
| 9765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9766 | struct net_device *dev = info->user_ptr[1]; |
| 9767 | |
| 9768 | return cfg80211_leave_mesh(rdev, dev); |
| 9769 | } |
| 9770 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9771 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9772 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9773 | struct cfg80211_registered_device *rdev) |
| 9774 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9775 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9776 | struct nlattr *nl_pats, *nl_pat; |
| 9777 | int i, pat_len; |
| 9778 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9779 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9780 | return 0; |
| 9781 | |
| 9782 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9783 | if (!nl_pats) |
| 9784 | return -ENOBUFS; |
| 9785 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9786 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9787 | nl_pat = nla_nest_start(msg, i + 1); |
| 9788 | if (!nl_pat) |
| 9789 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9790 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9791 | 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] | 9792 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9793 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9794 | wowlan->patterns[i].pattern) || |
| 9795 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9796 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9797 | return -ENOBUFS; |
| 9798 | nla_nest_end(msg, nl_pat); |
| 9799 | } |
| 9800 | nla_nest_end(msg, nl_pats); |
| 9801 | |
| 9802 | return 0; |
| 9803 | } |
| 9804 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9805 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9806 | struct cfg80211_wowlan_tcp *tcp) |
| 9807 | { |
| 9808 | struct nlattr *nl_tcp; |
| 9809 | |
| 9810 | if (!tcp) |
| 9811 | return 0; |
| 9812 | |
| 9813 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9814 | if (!nl_tcp) |
| 9815 | return -ENOBUFS; |
| 9816 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9817 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9818 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9819 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9820 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9821 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9822 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9823 | tcp->payload_len, tcp->payload) || |
| 9824 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9825 | tcp->data_interval) || |
| 9826 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9827 | tcp->wake_len, tcp->wake_data) || |
| 9828 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9829 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9830 | return -ENOBUFS; |
| 9831 | |
| 9832 | if (tcp->payload_seq.len && |
| 9833 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9834 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9835 | return -ENOBUFS; |
| 9836 | |
| 9837 | if (tcp->payload_tok.len && |
| 9838 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9839 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9840 | &tcp->payload_tok)) |
| 9841 | return -ENOBUFS; |
| 9842 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9843 | nla_nest_end(msg, nl_tcp); |
| 9844 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9845 | return 0; |
| 9846 | } |
| 9847 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9848 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9849 | struct cfg80211_sched_scan_request *req) |
| 9850 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9851 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9852 | int i; |
| 9853 | |
| 9854 | if (!req) |
| 9855 | return 0; |
| 9856 | |
| 9857 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9858 | if (!nd) |
| 9859 | return -ENOBUFS; |
| 9860 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9861 | if (req->n_scan_plans == 1 && |
| 9862 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9863 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9864 | return -ENOBUFS; |
| 9865 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9866 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9867 | return -ENOBUFS; |
| 9868 | |
vamsi krishna | f4f1a54 | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 9869 | if (req->relative_rssi_set) { |
| 9870 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 9871 | |
| 9872 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 9873 | req->relative_rssi)) |
| 9874 | return -ENOBUFS; |
| 9875 | |
| 9876 | rssi_adjust.band = req->rssi_adjust.band; |
| 9877 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 9878 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 9879 | sizeof(rssi_adjust), &rssi_adjust)) |
| 9880 | return -ENOBUFS; |
| 9881 | } |
| 9882 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9883 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9884 | if (!freqs) |
| 9885 | return -ENOBUFS; |
| 9886 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9887 | for (i = 0; i < req->n_channels; i++) { |
| 9888 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9889 | return -ENOBUFS; |
| 9890 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9891 | |
| 9892 | nla_nest_end(msg, freqs); |
| 9893 | |
| 9894 | if (req->n_match_sets) { |
| 9895 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9896 | if (!matches) |
| 9897 | return -ENOBUFS; |
| 9898 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9899 | for (i = 0; i < req->n_match_sets; i++) { |
| 9900 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9901 | if (!match) |
| 9902 | return -ENOBUFS; |
| 9903 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9904 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9905 | req->match_sets[i].ssid.ssid_len, |
| 9906 | req->match_sets[i].ssid.ssid)) |
| 9907 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9908 | nla_nest_end(msg, match); |
| 9909 | } |
| 9910 | nla_nest_end(msg, matches); |
| 9911 | } |
| 9912 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9913 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9914 | if (!scan_plans) |
| 9915 | return -ENOBUFS; |
| 9916 | |
| 9917 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9918 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9919 | if (!scan_plan) |
| 9920 | return -ENOBUFS; |
| 9921 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9922 | if (!scan_plan || |
| 9923 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9924 | req->scan_plans[i].interval) || |
| 9925 | (req->scan_plans[i].iterations && |
| 9926 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9927 | req->scan_plans[i].iterations))) |
| 9928 | return -ENOBUFS; |
| 9929 | nla_nest_end(msg, scan_plan); |
| 9930 | } |
| 9931 | nla_nest_end(msg, scan_plans); |
| 9932 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9933 | nla_nest_end(msg, nd); |
| 9934 | |
| 9935 | return 0; |
| 9936 | } |
| 9937 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9938 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9939 | { |
| 9940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9941 | struct sk_buff *msg; |
| 9942 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9943 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9944 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9945 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9946 | return -EOPNOTSUPP; |
| 9947 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9948 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9949 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9950 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9951 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9952 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9953 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9954 | } |
| 9955 | |
| 9956 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9957 | if (!msg) |
| 9958 | return -ENOMEM; |
| 9959 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9960 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9961 | NL80211_CMD_GET_WOWLAN); |
| 9962 | if (!hdr) |
| 9963 | goto nla_put_failure; |
| 9964 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9965 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9966 | struct nlattr *nl_wowlan; |
| 9967 | |
| 9968 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9969 | if (!nl_wowlan) |
| 9970 | goto nla_put_failure; |
| 9971 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9972 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9974 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9975 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9976 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9977 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9978 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9979 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9980 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9981 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9982 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9983 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9984 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9985 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9986 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9987 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9988 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9989 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9990 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9991 | if (nl80211_send_wowlan_tcp(msg, |
| 9992 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9993 | goto nla_put_failure; |
| 9994 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9995 | if (nl80211_send_wowlan_nd( |
| 9996 | msg, |
| 9997 | rdev->wiphy.wowlan_config->nd_config)) |
| 9998 | goto nla_put_failure; |
| 9999 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10000 | nla_nest_end(msg, nl_wowlan); |
| 10001 | } |
| 10002 | |
| 10003 | genlmsg_end(msg, hdr); |
| 10004 | return genlmsg_reply(msg, info); |
| 10005 | |
| 10006 | nla_put_failure: |
| 10007 | nlmsg_free(msg); |
| 10008 | return -ENOBUFS; |
| 10009 | } |
| 10010 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10011 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10012 | struct nlattr *attr, |
| 10013 | struct cfg80211_wowlan *trig) |
| 10014 | { |
| 10015 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10016 | struct cfg80211_wowlan_tcp *cfg; |
| 10017 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10018 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10019 | u32 size; |
| 10020 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10021 | int err, port; |
| 10022 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10023 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10024 | return -EINVAL; |
| 10025 | |
| 10026 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 10027 | nla_data(attr), nla_len(attr), |
| 10028 | nl80211_wowlan_tcp_policy); |
| 10029 | if (err) |
| 10030 | return err; |
| 10031 | |
| 10032 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10033 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10034 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10035 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10036 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10037 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10038 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10039 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10040 | return -EINVAL; |
| 10041 | |
| 10042 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10043 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10044 | return -EINVAL; |
| 10045 | |
| 10046 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10047 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10048 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10049 | return -EINVAL; |
| 10050 | |
| 10051 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10052 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10053 | return -EINVAL; |
| 10054 | |
| 10055 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10056 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10057 | return -EINVAL; |
| 10058 | |
| 10059 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10060 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10061 | |
| 10062 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10063 | tokens_size = tokln - sizeof(*tok); |
| 10064 | |
| 10065 | if (!tok->len || tokens_size % tok->len) |
| 10066 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10067 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10068 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10069 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10070 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10071 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10072 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10073 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10074 | return -EINVAL; |
| 10075 | if (tok->offset + tok->len > data_size) |
| 10076 | return -EINVAL; |
| 10077 | } |
| 10078 | |
| 10079 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10080 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10081 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10082 | return -EINVAL; |
| 10083 | if (seq->len == 0 || seq->len > 4) |
| 10084 | return -EINVAL; |
| 10085 | if (seq->len + seq->offset > data_size) |
| 10086 | return -EINVAL; |
| 10087 | } |
| 10088 | |
| 10089 | size = sizeof(*cfg); |
| 10090 | size += data_size; |
| 10091 | size += wake_size + wake_mask_size; |
| 10092 | size += tokens_size; |
| 10093 | |
| 10094 | cfg = kzalloc(size, GFP_KERNEL); |
| 10095 | if (!cfg) |
| 10096 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10097 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10098 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10099 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10100 | ETH_ALEN); |
| 10101 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10102 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10103 | else |
| 10104 | port = 0; |
| 10105 | #ifdef CONFIG_INET |
| 10106 | /* allocate a socket and port for it and use it */ |
| 10107 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10108 | IPPROTO_TCP, &cfg->sock, 1); |
| 10109 | if (err) { |
| 10110 | kfree(cfg); |
| 10111 | return err; |
| 10112 | } |
| 10113 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10114 | sock_release(cfg->sock); |
| 10115 | kfree(cfg); |
| 10116 | return -EADDRINUSE; |
| 10117 | } |
| 10118 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10119 | #else |
| 10120 | if (!port) { |
| 10121 | kfree(cfg); |
| 10122 | return -EINVAL; |
| 10123 | } |
| 10124 | cfg->src_port = port; |
| 10125 | #endif |
| 10126 | |
| 10127 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10128 | cfg->payload_len = data_size; |
| 10129 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10130 | memcpy((void *)cfg->payload, |
| 10131 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10132 | data_size); |
| 10133 | if (seq) |
| 10134 | cfg->payload_seq = *seq; |
| 10135 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10136 | cfg->wake_len = wake_size; |
| 10137 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10138 | memcpy((void *)cfg->wake_data, |
| 10139 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10140 | wake_size); |
| 10141 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10142 | data_size + wake_size; |
| 10143 | memcpy((void *)cfg->wake_mask, |
| 10144 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10145 | wake_mask_size); |
| 10146 | if (tok) { |
| 10147 | cfg->tokens_size = tokens_size; |
| 10148 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10149 | } |
| 10150 | |
| 10151 | trig->tcp = cfg; |
| 10152 | |
| 10153 | return 0; |
| 10154 | } |
| 10155 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10156 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10157 | const struct wiphy_wowlan_support *wowlan, |
| 10158 | struct nlattr *attr, |
| 10159 | struct cfg80211_wowlan *trig) |
| 10160 | { |
| 10161 | struct nlattr **tb; |
| 10162 | int err; |
| 10163 | |
| 10164 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10165 | if (!tb) |
| 10166 | return -ENOMEM; |
| 10167 | |
| 10168 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10169 | err = -EOPNOTSUPP; |
| 10170 | goto out; |
| 10171 | } |
| 10172 | |
| 10173 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 10174 | nla_data(attr), nla_len(attr), |
| 10175 | nl80211_policy); |
| 10176 | if (err) |
| 10177 | goto out; |
| 10178 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 10179 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10180 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10181 | if (err) |
| 10182 | trig->nd_config = NULL; |
| 10183 | |
| 10184 | out: |
| 10185 | kfree(tb); |
| 10186 | return err; |
| 10187 | } |
| 10188 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10189 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10190 | { |
| 10191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10192 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10193 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10194 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10195 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10196 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10197 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10198 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10199 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10200 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10201 | return -EOPNOTSUPP; |
| 10202 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10203 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10204 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10205 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10206 | goto set_wakeup; |
| 10207 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10208 | |
| 10209 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10210 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 10211 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 10212 | nl80211_wowlan_policy); |
| 10213 | if (err) |
| 10214 | return err; |
| 10215 | |
| 10216 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10217 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10218 | return -EINVAL; |
| 10219 | new_triggers.any = true; |
| 10220 | } |
| 10221 | |
| 10222 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10223 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10224 | return -EINVAL; |
| 10225 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10226 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10227 | } |
| 10228 | |
| 10229 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10230 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10231 | return -EINVAL; |
| 10232 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10233 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10234 | } |
| 10235 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10236 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10237 | return -EINVAL; |
| 10238 | |
| 10239 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10240 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10241 | return -EINVAL; |
| 10242 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10243 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10244 | } |
| 10245 | |
| 10246 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10247 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10248 | return -EINVAL; |
| 10249 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10250 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10251 | } |
| 10252 | |
| 10253 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10254 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10255 | return -EINVAL; |
| 10256 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10257 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10258 | } |
| 10259 | |
| 10260 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10261 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10262 | return -EINVAL; |
| 10263 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10264 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10265 | } |
| 10266 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10267 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10268 | struct nlattr *pat; |
| 10269 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10270 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10271 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10272 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10273 | regular = true; |
| 10274 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10275 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10276 | rem) |
| 10277 | n_patterns++; |
| 10278 | if (n_patterns > wowlan->n_patterns) |
| 10279 | return -EINVAL; |
| 10280 | |
| 10281 | new_triggers.patterns = kcalloc(n_patterns, |
| 10282 | sizeof(new_triggers.patterns[0]), |
| 10283 | GFP_KERNEL); |
| 10284 | if (!new_triggers.patterns) |
| 10285 | return -ENOMEM; |
| 10286 | |
| 10287 | new_triggers.n_patterns = n_patterns; |
| 10288 | i = 0; |
| 10289 | |
| 10290 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10291 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10292 | u8 *mask_pat; |
| 10293 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10294 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
Peng Xu | 4ec90fd | 2017-10-10 13:56:53 -0700 | [diff] [blame] | 10295 | nla_len(pat), nl80211_packet_pattern_policy); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10296 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10297 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10298 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10299 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10300 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10301 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10302 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10303 | goto error; |
| 10304 | if (pat_len > wowlan->pattern_max_len || |
| 10305 | pat_len < wowlan->pattern_min_len) |
| 10306 | goto error; |
| 10307 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10308 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10309 | pkt_offset = 0; |
| 10310 | else |
| 10311 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10312 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10313 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10314 | goto error; |
| 10315 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10316 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10317 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10318 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10319 | err = -ENOMEM; |
| 10320 | goto error; |
| 10321 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10322 | new_triggers.patterns[i].mask = mask_pat; |
| 10323 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10324 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10325 | mask_pat += mask_len; |
| 10326 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10327 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10328 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10329 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10330 | pat_len); |
| 10331 | i++; |
| 10332 | } |
| 10333 | } |
| 10334 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10335 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10336 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10337 | err = nl80211_parse_wowlan_tcp( |
| 10338 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10339 | &new_triggers); |
| 10340 | if (err) |
| 10341 | goto error; |
| 10342 | } |
| 10343 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10344 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10345 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10346 | err = nl80211_parse_wowlan_nd( |
| 10347 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10348 | &new_triggers); |
| 10349 | if (err) |
| 10350 | goto error; |
| 10351 | } |
| 10352 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10353 | /* The 'any' trigger means the device continues operating more or less |
| 10354 | * as in its normal operation mode and wakes up the host on most of the |
| 10355 | * normal interrupts (like packet RX, ...) |
| 10356 | * It therefore makes little sense to combine with the more constrained |
| 10357 | * wakeup trigger modes. |
| 10358 | */ |
| 10359 | if (new_triggers.any && regular) { |
| 10360 | err = -EINVAL; |
| 10361 | goto error; |
| 10362 | } |
| 10363 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10364 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10365 | if (!ntrig) { |
| 10366 | err = -ENOMEM; |
| 10367 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10368 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10369 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10370 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10371 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10372 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10373 | if (rdev->ops->set_wakeup && |
| 10374 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10375 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10376 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10377 | return 0; |
| 10378 | error: |
| 10379 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10380 | kfree(new_triggers.patterns[i].mask); |
| 10381 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10382 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10383 | sock_release(new_triggers.tcp->sock); |
| 10384 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10385 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10386 | return err; |
| 10387 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10388 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10389 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10390 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10391 | struct cfg80211_registered_device *rdev) |
| 10392 | { |
| 10393 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10394 | int i, j, pat_len; |
| 10395 | struct cfg80211_coalesce_rules *rule; |
| 10396 | |
| 10397 | if (!rdev->coalesce->n_rules) |
| 10398 | return 0; |
| 10399 | |
| 10400 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10401 | if (!nl_rules) |
| 10402 | return -ENOBUFS; |
| 10403 | |
| 10404 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10405 | nl_rule = nla_nest_start(msg, i + 1); |
| 10406 | if (!nl_rule) |
| 10407 | return -ENOBUFS; |
| 10408 | |
| 10409 | rule = &rdev->coalesce->rules[i]; |
| 10410 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10411 | rule->delay)) |
| 10412 | return -ENOBUFS; |
| 10413 | |
| 10414 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10415 | rule->condition)) |
| 10416 | return -ENOBUFS; |
| 10417 | |
| 10418 | nl_pats = nla_nest_start(msg, |
| 10419 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10420 | if (!nl_pats) |
| 10421 | return -ENOBUFS; |
| 10422 | |
| 10423 | for (j = 0; j < rule->n_patterns; j++) { |
| 10424 | nl_pat = nla_nest_start(msg, j + 1); |
| 10425 | if (!nl_pat) |
| 10426 | return -ENOBUFS; |
| 10427 | pat_len = rule->patterns[j].pattern_len; |
| 10428 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10429 | DIV_ROUND_UP(pat_len, 8), |
| 10430 | rule->patterns[j].mask) || |
| 10431 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10432 | rule->patterns[j].pattern) || |
| 10433 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10434 | rule->patterns[j].pkt_offset)) |
| 10435 | return -ENOBUFS; |
| 10436 | nla_nest_end(msg, nl_pat); |
| 10437 | } |
| 10438 | nla_nest_end(msg, nl_pats); |
| 10439 | nla_nest_end(msg, nl_rule); |
| 10440 | } |
| 10441 | nla_nest_end(msg, nl_rules); |
| 10442 | |
| 10443 | return 0; |
| 10444 | } |
| 10445 | |
| 10446 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10447 | { |
| 10448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10449 | struct sk_buff *msg; |
| 10450 | void *hdr; |
| 10451 | |
| 10452 | if (!rdev->wiphy.coalesce) |
| 10453 | return -EOPNOTSUPP; |
| 10454 | |
| 10455 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10456 | if (!msg) |
| 10457 | return -ENOMEM; |
| 10458 | |
| 10459 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10460 | NL80211_CMD_GET_COALESCE); |
| 10461 | if (!hdr) |
| 10462 | goto nla_put_failure; |
| 10463 | |
| 10464 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10465 | goto nla_put_failure; |
| 10466 | |
| 10467 | genlmsg_end(msg, hdr); |
| 10468 | return genlmsg_reply(msg, info); |
| 10469 | |
| 10470 | nla_put_failure: |
| 10471 | nlmsg_free(msg); |
| 10472 | return -ENOBUFS; |
| 10473 | } |
| 10474 | |
| 10475 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10476 | { |
| 10477 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10478 | int i, j; |
| 10479 | struct cfg80211_coalesce_rules *rule; |
| 10480 | |
| 10481 | if (!coalesce) |
| 10482 | return; |
| 10483 | |
| 10484 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10485 | rule = &coalesce->rules[i]; |
| 10486 | for (j = 0; j < rule->n_patterns; j++) |
| 10487 | kfree(rule->patterns[j].mask); |
| 10488 | kfree(rule->patterns); |
| 10489 | } |
| 10490 | kfree(coalesce->rules); |
| 10491 | kfree(coalesce); |
| 10492 | rdev->coalesce = NULL; |
| 10493 | } |
| 10494 | |
| 10495 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10496 | struct nlattr *rule, |
| 10497 | struct cfg80211_coalesce_rules *new_rule) |
| 10498 | { |
| 10499 | int err, i; |
| 10500 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10501 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10502 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10503 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10504 | |
| 10505 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 10506 | nla_len(rule), nl80211_coalesce_policy); |
| 10507 | if (err) |
| 10508 | return err; |
| 10509 | |
| 10510 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10511 | new_rule->delay = |
| 10512 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10513 | if (new_rule->delay > coalesce->max_delay) |
| 10514 | return -EINVAL; |
| 10515 | |
| 10516 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10517 | new_rule->condition = |
| 10518 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10519 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10520 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10521 | return -EINVAL; |
| 10522 | |
| 10523 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10524 | return -EINVAL; |
| 10525 | |
| 10526 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10527 | rem) |
| 10528 | n_patterns++; |
| 10529 | if (n_patterns > coalesce->n_patterns) |
| 10530 | return -EINVAL; |
| 10531 | |
| 10532 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10533 | GFP_KERNEL); |
| 10534 | if (!new_rule->patterns) |
| 10535 | return -ENOMEM; |
| 10536 | |
| 10537 | new_rule->n_patterns = n_patterns; |
| 10538 | i = 0; |
| 10539 | |
| 10540 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10541 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10542 | u8 *mask_pat; |
| 10543 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10544 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
Peng Xu | 4ec90fd | 2017-10-10 13:56:53 -0700 | [diff] [blame] | 10545 | nla_len(pat), nl80211_packet_pattern_policy); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10546 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10547 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10548 | return -EINVAL; |
| 10549 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10550 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10551 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10552 | return -EINVAL; |
| 10553 | if (pat_len > coalesce->pattern_max_len || |
| 10554 | pat_len < coalesce->pattern_min_len) |
| 10555 | return -EINVAL; |
| 10556 | |
| 10557 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10558 | pkt_offset = 0; |
| 10559 | else |
| 10560 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10561 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10562 | return -EINVAL; |
| 10563 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10564 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10565 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10566 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10567 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10568 | |
| 10569 | new_rule->patterns[i].mask = mask_pat; |
| 10570 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10571 | mask_len); |
| 10572 | |
| 10573 | mask_pat += mask_len; |
| 10574 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10575 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10576 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10577 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10578 | i++; |
| 10579 | } |
| 10580 | |
| 10581 | return 0; |
| 10582 | } |
| 10583 | |
| 10584 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10585 | { |
| 10586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10587 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10588 | struct cfg80211_coalesce new_coalesce = {}; |
| 10589 | struct cfg80211_coalesce *n_coalesce; |
| 10590 | int err, rem_rule, n_rules = 0, i, j; |
| 10591 | struct nlattr *rule; |
| 10592 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10593 | |
| 10594 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10595 | return -EOPNOTSUPP; |
| 10596 | |
| 10597 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10598 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10599 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10600 | return 0; |
| 10601 | } |
| 10602 | |
| 10603 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10604 | rem_rule) |
| 10605 | n_rules++; |
| 10606 | if (n_rules > coalesce->n_rules) |
| 10607 | return -EINVAL; |
| 10608 | |
| 10609 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10610 | GFP_KERNEL); |
| 10611 | if (!new_coalesce.rules) |
| 10612 | return -ENOMEM; |
| 10613 | |
| 10614 | new_coalesce.n_rules = n_rules; |
| 10615 | i = 0; |
| 10616 | |
| 10617 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10618 | rem_rule) { |
| 10619 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10620 | &new_coalesce.rules[i]); |
| 10621 | if (err) |
| 10622 | goto error; |
| 10623 | |
| 10624 | i++; |
| 10625 | } |
| 10626 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10627 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10628 | if (err) |
| 10629 | goto error; |
| 10630 | |
| 10631 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10632 | if (!n_coalesce) { |
| 10633 | err = -ENOMEM; |
| 10634 | goto error; |
| 10635 | } |
| 10636 | cfg80211_rdev_free_coalesce(rdev); |
| 10637 | rdev->coalesce = n_coalesce; |
| 10638 | |
| 10639 | return 0; |
| 10640 | error: |
| 10641 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10642 | tmp_rule = &new_coalesce.rules[i]; |
| 10643 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10644 | kfree(tmp_rule->patterns[j].mask); |
| 10645 | kfree(tmp_rule->patterns); |
| 10646 | } |
| 10647 | kfree(new_coalesce.rules); |
| 10648 | |
| 10649 | return err; |
| 10650 | } |
| 10651 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10652 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10653 | { |
| 10654 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10655 | struct net_device *dev = info->user_ptr[1]; |
| 10656 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10657 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10658 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10659 | int err; |
| 10660 | |
| 10661 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10662 | return -EINVAL; |
| 10663 | |
| 10664 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 10665 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10666 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10667 | nl80211_rekey_policy); |
| 10668 | if (err) |
| 10669 | return err; |
| 10670 | |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 10671 | if (!tb[NL80211_REKEY_DATA_KEK] || !tb[NL80211_REKEY_DATA_REPLAY_CTR] || |
| 10672 | (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10673 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10674 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10675 | NL80211_EXT_FEATURE_FILS_STA) && |
| 10676 | !tb[NL80211_REKEY_DATA_KCK])) |
| 10677 | return -EINVAL; |
| 10678 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10679 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10680 | return -ERANGE; |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 10681 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) < NL80211_KEK_LEN) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10682 | return -ERANGE; |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 10683 | if (tb[NL80211_REKEY_DATA_KCK] && |
| 10684 | nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10685 | return -ERANGE; |
| 10686 | |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 10687 | memset(&rekey_data, 0, sizeof(rekey_data)); |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10688 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
Vidyullatha Kanchanapally | 84aa3ba | 2017-05-25 20:20:41 +0530 | [diff] [blame] | 10689 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 10690 | if (tb[NL80211_REKEY_DATA_KCK]) |
| 10691 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10692 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10693 | |
| 10694 | wdev_lock(wdev); |
| 10695 | if (!wdev->current_bss) { |
| 10696 | err = -ENOTCONN; |
| 10697 | goto out; |
| 10698 | } |
| 10699 | |
| 10700 | if (!rdev->ops->set_rekey_data) { |
| 10701 | err = -EOPNOTSUPP; |
| 10702 | goto out; |
| 10703 | } |
| 10704 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10705 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10706 | out: |
| 10707 | wdev_unlock(wdev); |
| 10708 | return err; |
| 10709 | } |
| 10710 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10711 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10712 | struct genl_info *info) |
| 10713 | { |
| 10714 | struct net_device *dev = info->user_ptr[1]; |
| 10715 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10716 | |
| 10717 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10718 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10719 | return -EINVAL; |
| 10720 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10721 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10722 | return -EBUSY; |
| 10723 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10724 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10725 | return 0; |
| 10726 | } |
| 10727 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10728 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10729 | struct genl_info *info) |
| 10730 | { |
| 10731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10732 | struct net_device *dev = info->user_ptr[1]; |
| 10733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10734 | struct sk_buff *msg; |
| 10735 | void *hdr; |
| 10736 | const u8 *addr; |
| 10737 | u64 cookie; |
| 10738 | int err; |
| 10739 | |
| 10740 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10741 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10742 | return -EOPNOTSUPP; |
| 10743 | |
| 10744 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10745 | return -EINVAL; |
| 10746 | |
| 10747 | if (!rdev->ops->probe_client) |
| 10748 | return -EOPNOTSUPP; |
| 10749 | |
| 10750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10751 | if (!msg) |
| 10752 | return -ENOMEM; |
| 10753 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10754 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10755 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10756 | if (!hdr) { |
| 10757 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10758 | goto free_msg; |
| 10759 | } |
| 10760 | |
| 10761 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10762 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10763 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10764 | if (err) |
| 10765 | goto free_msg; |
| 10766 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10767 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10768 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10769 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10770 | |
| 10771 | genlmsg_end(msg, hdr); |
| 10772 | |
| 10773 | return genlmsg_reply(msg, info); |
| 10774 | |
| 10775 | nla_put_failure: |
| 10776 | err = -ENOBUFS; |
| 10777 | free_msg: |
| 10778 | nlmsg_free(msg); |
| 10779 | return err; |
| 10780 | } |
| 10781 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10782 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10783 | { |
| 10784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10785 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10786 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10787 | |
| 10788 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10789 | return -EOPNOTSUPP; |
| 10790 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10791 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10792 | if (!nreg) |
| 10793 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10794 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10795 | /* First, check if already registered. */ |
| 10796 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10797 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10798 | if (reg->nlportid == info->snd_portid) { |
| 10799 | rv = -EALREADY; |
| 10800 | goto out_err; |
| 10801 | } |
| 10802 | } |
| 10803 | /* Add it to the list */ |
| 10804 | nreg->nlportid = info->snd_portid; |
| 10805 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10806 | |
| 10807 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10808 | |
| 10809 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10810 | out_err: |
| 10811 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10812 | kfree(nreg); |
| 10813 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10814 | } |
| 10815 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10816 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10817 | { |
| 10818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10819 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10820 | int err; |
| 10821 | |
| 10822 | if (!rdev->ops->start_p2p_device) |
| 10823 | return -EOPNOTSUPP; |
| 10824 | |
| 10825 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10826 | return -EOPNOTSUPP; |
| 10827 | |
| 10828 | if (wdev->p2p_started) |
| 10829 | return 0; |
| 10830 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10831 | if (rfkill_blocked(rdev->rfkill)) |
| 10832 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10833 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10834 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10835 | if (err) |
| 10836 | return err; |
| 10837 | |
| 10838 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10839 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10840 | |
| 10841 | return 0; |
| 10842 | } |
| 10843 | |
| 10844 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10845 | { |
| 10846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10847 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10848 | |
| 10849 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10850 | return -EOPNOTSUPP; |
| 10851 | |
| 10852 | if (!rdev->ops->stop_p2p_device) |
| 10853 | return -EOPNOTSUPP; |
| 10854 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10855 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10856 | |
| 10857 | return 0; |
| 10858 | } |
| 10859 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10860 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 10861 | { |
| 10862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10863 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10864 | struct cfg80211_nan_conf conf = {}; |
| 10865 | int err; |
| 10866 | |
| 10867 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10868 | return -EOPNOTSUPP; |
| 10869 | |
| 10870 | if (wdev->nan_started) |
| 10871 | return -EEXIST; |
| 10872 | |
| 10873 | if (rfkill_blocked(rdev->rfkill)) |
| 10874 | return -ERFKILL; |
| 10875 | |
| 10876 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 10877 | return -EINVAL; |
| 10878 | |
| 10879 | if (!info->attrs[NL80211_ATTR_NAN_DUAL]) |
| 10880 | return -EINVAL; |
| 10881 | |
| 10882 | conf.master_pref = |
| 10883 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 10884 | if (!conf.master_pref) |
| 10885 | return -EINVAL; |
| 10886 | |
| 10887 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 10888 | |
| 10889 | err = rdev_start_nan(rdev, wdev, &conf); |
| 10890 | if (err) |
| 10891 | return err; |
| 10892 | |
| 10893 | wdev->nan_started = true; |
| 10894 | rdev->opencount++; |
| 10895 | |
| 10896 | return 0; |
| 10897 | } |
| 10898 | |
| 10899 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 10900 | { |
| 10901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10902 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10903 | |
| 10904 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10905 | return -EOPNOTSUPP; |
| 10906 | |
| 10907 | cfg80211_stop_nan(rdev, wdev); |
| 10908 | |
| 10909 | return 0; |
| 10910 | } |
| 10911 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10912 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 10913 | { |
| 10914 | struct nlattr *attr; |
| 10915 | int len = 0, n_entries = 0, rem; |
| 10916 | |
| 10917 | nla_for_each_nested(attr, filter_attr, rem) { |
| 10918 | len += nla_len(attr); |
| 10919 | n_entries++; |
| 10920 | } |
| 10921 | |
| 10922 | if (len >= U8_MAX) |
| 10923 | return -EINVAL; |
| 10924 | |
| 10925 | return n_entries; |
| 10926 | } |
| 10927 | |
| 10928 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 10929 | struct cfg80211_nan_func *func, |
| 10930 | bool tx) |
| 10931 | { |
| 10932 | struct nlattr *attr; |
| 10933 | int n_entries, rem, i; |
| 10934 | struct cfg80211_nan_func_filter *filter; |
| 10935 | |
| 10936 | n_entries = validate_nan_filter(attr_filter); |
| 10937 | if (n_entries < 0) |
| 10938 | return n_entries; |
| 10939 | |
| 10940 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 10941 | |
| 10942 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 10943 | if (!filter) |
| 10944 | return -ENOMEM; |
| 10945 | |
| 10946 | i = 0; |
| 10947 | nla_for_each_nested(attr, attr_filter, rem) { |
| 10948 | filter[i].filter = kmemdup(nla_data(attr), nla_len(attr), |
| 10949 | GFP_KERNEL); |
| 10950 | filter[i].len = nla_len(attr); |
| 10951 | i++; |
| 10952 | } |
| 10953 | if (tx) { |
| 10954 | func->num_tx_filters = n_entries; |
| 10955 | func->tx_filters = filter; |
| 10956 | } else { |
| 10957 | func->num_rx_filters = n_entries; |
| 10958 | func->rx_filters = filter; |
| 10959 | } |
| 10960 | |
| 10961 | return 0; |
| 10962 | } |
| 10963 | |
| 10964 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 10965 | struct genl_info *info) |
| 10966 | { |
| 10967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10968 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10969 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 10970 | struct cfg80211_nan_func *func; |
| 10971 | struct sk_buff *msg = NULL; |
| 10972 | void *hdr = NULL; |
| 10973 | int err = 0; |
| 10974 | |
| 10975 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10976 | return -EOPNOTSUPP; |
| 10977 | |
| 10978 | if (!wdev->nan_started) |
| 10979 | return -ENOTCONN; |
| 10980 | |
| 10981 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 10982 | return -EINVAL; |
| 10983 | |
| 10984 | if (wdev->owner_nlportid && |
| 10985 | wdev->owner_nlportid != info->snd_portid) |
| 10986 | return -ENOTCONN; |
| 10987 | |
| 10988 | err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 10989 | nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]), |
| 10990 | nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]), |
| 10991 | nl80211_nan_func_policy); |
| 10992 | if (err) |
| 10993 | return err; |
| 10994 | |
| 10995 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 10996 | if (!func) |
| 10997 | return -ENOMEM; |
| 10998 | |
| 10999 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11000 | |
| 11001 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11002 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11003 | err = -EINVAL; |
| 11004 | goto out; |
| 11005 | } |
| 11006 | |
| 11007 | |
| 11008 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11009 | |
| 11010 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11011 | err = -EINVAL; |
| 11012 | goto out; |
| 11013 | } |
| 11014 | |
| 11015 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11016 | sizeof(func->service_id)); |
| 11017 | |
| 11018 | func->close_range = |
| 11019 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11020 | |
| 11021 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11022 | func->serv_spec_info_len = |
| 11023 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11024 | func->serv_spec_info = |
| 11025 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11026 | func->serv_spec_info_len, |
| 11027 | GFP_KERNEL); |
| 11028 | if (!func->serv_spec_info) { |
| 11029 | err = -ENOMEM; |
| 11030 | goto out; |
| 11031 | } |
| 11032 | } |
| 11033 | |
| 11034 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11035 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11036 | |
| 11037 | switch (func->type) { |
| 11038 | case NL80211_NAN_FUNC_PUBLISH: |
| 11039 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11040 | err = -EINVAL; |
| 11041 | goto out; |
| 11042 | } |
| 11043 | |
| 11044 | func->publish_type = |
| 11045 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11046 | func->publish_bcast = |
| 11047 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11048 | |
| 11049 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11050 | func->publish_bcast) { |
| 11051 | err = -EINVAL; |
| 11052 | goto out; |
| 11053 | } |
| 11054 | break; |
| 11055 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11056 | func->subscribe_active = |
| 11057 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11058 | break; |
| 11059 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11060 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 4ec2b1c | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 11061 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 11062 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11063 | err = -EINVAL; |
| 11064 | goto out; |
| 11065 | } |
| 11066 | |
| 11067 | func->followup_id = |
| 11068 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11069 | func->followup_reqid = |
| 11070 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11071 | memcpy(func->followup_dest.addr, |
| 11072 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11073 | sizeof(func->followup_dest.addr)); |
| 11074 | if (func->ttl) { |
| 11075 | err = -EINVAL; |
| 11076 | goto out; |
| 11077 | } |
| 11078 | break; |
| 11079 | default: |
| 11080 | err = -EINVAL; |
| 11081 | goto out; |
| 11082 | } |
| 11083 | |
| 11084 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11085 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11086 | |
| 11087 | err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11088 | nla_data(tb[NL80211_NAN_FUNC_SRF]), |
| 11089 | nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL); |
| 11090 | if (err) |
| 11091 | goto out; |
| 11092 | |
| 11093 | func->srf_include = |
| 11094 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11095 | |
| 11096 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11097 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11098 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11099 | err = -EINVAL; |
| 11100 | goto out; |
| 11101 | } |
| 11102 | |
| 11103 | func->srf_bf_len = |
| 11104 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11105 | func->srf_bf = |
| 11106 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11107 | func->srf_bf_len, GFP_KERNEL); |
| 11108 | if (!func->srf_bf) { |
| 11109 | err = -ENOMEM; |
| 11110 | goto out; |
| 11111 | } |
| 11112 | |
| 11113 | func->srf_bf_idx = |
| 11114 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11115 | } else { |
| 11116 | struct nlattr *attr, *mac_attr = |
| 11117 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11118 | int n_entries, rem, i = 0; |
| 11119 | |
| 11120 | if (!mac_attr) { |
| 11121 | err = -EINVAL; |
| 11122 | goto out; |
| 11123 | } |
| 11124 | |
| 11125 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11126 | if (n_entries <= 0) { |
| 11127 | err = -EINVAL; |
| 11128 | goto out; |
| 11129 | } |
| 11130 | |
| 11131 | func->srf_num_macs = n_entries; |
| 11132 | func->srf_macs = |
| 11133 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11134 | GFP_KERNEL); |
| 11135 | if (!func->srf_macs) { |
| 11136 | err = -ENOMEM; |
| 11137 | goto out; |
| 11138 | } |
| 11139 | |
| 11140 | nla_for_each_nested(attr, mac_attr, rem) |
| 11141 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11142 | sizeof(*func->srf_macs)); |
| 11143 | } |
| 11144 | } |
| 11145 | |
| 11146 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11147 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11148 | func, true); |
| 11149 | if (err) |
| 11150 | goto out; |
| 11151 | } |
| 11152 | |
| 11153 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11154 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11155 | func, false); |
| 11156 | if (err) |
| 11157 | goto out; |
| 11158 | } |
| 11159 | |
| 11160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11161 | if (!msg) { |
| 11162 | err = -ENOMEM; |
| 11163 | goto out; |
| 11164 | } |
| 11165 | |
| 11166 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11167 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11168 | /* This can't really happen - we just allocated 4KB */ |
| 11169 | if (WARN_ON(!hdr)) { |
| 11170 | err = -ENOMEM; |
| 11171 | goto out; |
| 11172 | } |
| 11173 | |
| 11174 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11175 | out: |
| 11176 | if (err < 0) { |
| 11177 | cfg80211_free_nan_func(func); |
| 11178 | nlmsg_free(msg); |
| 11179 | return err; |
| 11180 | } |
| 11181 | |
| 11182 | /* propagate the instance id and cookie to userspace */ |
| 11183 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11184 | NL80211_ATTR_PAD)) |
| 11185 | goto nla_put_failure; |
| 11186 | |
| 11187 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11188 | if (!func_attr) |
| 11189 | goto nla_put_failure; |
| 11190 | |
| 11191 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11192 | func->instance_id)) |
| 11193 | goto nla_put_failure; |
| 11194 | |
| 11195 | nla_nest_end(msg, func_attr); |
| 11196 | |
| 11197 | genlmsg_end(msg, hdr); |
| 11198 | return genlmsg_reply(msg, info); |
| 11199 | |
| 11200 | nla_put_failure: |
| 11201 | nlmsg_free(msg); |
| 11202 | return -ENOBUFS; |
| 11203 | } |
| 11204 | |
| 11205 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11206 | struct genl_info *info) |
| 11207 | { |
| 11208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11209 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11210 | u64 cookie; |
| 11211 | |
| 11212 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11213 | return -EOPNOTSUPP; |
| 11214 | |
| 11215 | if (!wdev->nan_started) |
| 11216 | return -ENOTCONN; |
| 11217 | |
| 11218 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11219 | return -EINVAL; |
| 11220 | |
| 11221 | if (wdev->owner_nlportid && |
| 11222 | wdev->owner_nlportid != info->snd_portid) |
| 11223 | return -ENOTCONN; |
| 11224 | |
| 11225 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11226 | |
| 11227 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11228 | |
| 11229 | return 0; |
| 11230 | } |
| 11231 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11232 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11233 | struct genl_info *info) |
| 11234 | { |
| 11235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11236 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11237 | struct cfg80211_nan_conf conf = {}; |
| 11238 | u32 changed = 0; |
| 11239 | |
| 11240 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11241 | return -EOPNOTSUPP; |
| 11242 | |
| 11243 | if (!wdev->nan_started) |
| 11244 | return -ENOTCONN; |
| 11245 | |
| 11246 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11247 | conf.master_pref = |
| 11248 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11249 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11250 | return -EINVAL; |
| 11251 | |
| 11252 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11253 | } |
| 11254 | |
| 11255 | if (info->attrs[NL80211_ATTR_NAN_DUAL]) { |
| 11256 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 11257 | changed |= CFG80211_NAN_CONF_CHANGED_DUAL; |
| 11258 | } |
| 11259 | |
| 11260 | if (!changed) |
| 11261 | return -EINVAL; |
| 11262 | |
| 11263 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11264 | } |
| 11265 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11266 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11267 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11268 | { |
| 11269 | struct wiphy *wiphy = wdev->wiphy; |
| 11270 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11271 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11272 | struct sk_buff *msg; |
| 11273 | void *hdr; |
| 11274 | |
| 11275 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11276 | return; |
| 11277 | |
| 11278 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11279 | if (!msg) |
| 11280 | return; |
| 11281 | |
| 11282 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11283 | if (!hdr) { |
| 11284 | nlmsg_free(msg); |
| 11285 | return; |
| 11286 | } |
| 11287 | |
| 11288 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11289 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11290 | wdev->netdev->ifindex)) || |
| 11291 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11292 | NL80211_ATTR_PAD)) |
| 11293 | goto nla_put_failure; |
| 11294 | |
| 11295 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11296 | NL80211_ATTR_PAD) || |
| 11297 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11298 | goto nla_put_failure; |
| 11299 | |
| 11300 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11301 | if (!match_attr) |
| 11302 | goto nla_put_failure; |
| 11303 | |
| 11304 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11305 | if (!local_func_attr) |
| 11306 | goto nla_put_failure; |
| 11307 | |
| 11308 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11309 | goto nla_put_failure; |
| 11310 | |
| 11311 | nla_nest_end(msg, local_func_attr); |
| 11312 | |
| 11313 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11314 | if (!peer_func_attr) |
| 11315 | goto nla_put_failure; |
| 11316 | |
| 11317 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11318 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11319 | goto nla_put_failure; |
| 11320 | |
| 11321 | if (match->info && match->info_len && |
| 11322 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11323 | match->info)) |
| 11324 | goto nla_put_failure; |
| 11325 | |
| 11326 | nla_nest_end(msg, peer_func_attr); |
| 11327 | nla_nest_end(msg, match_attr); |
| 11328 | genlmsg_end(msg, hdr); |
| 11329 | |
| 11330 | if (!wdev->owner_nlportid) |
| 11331 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11332 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11333 | else |
| 11334 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11335 | wdev->owner_nlportid); |
| 11336 | |
| 11337 | return; |
| 11338 | |
| 11339 | nla_put_failure: |
| 11340 | nlmsg_free(msg); |
| 11341 | } |
| 11342 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11343 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11344 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11345 | u8 inst_id, |
| 11346 | enum nl80211_nan_func_term_reason reason, |
| 11347 | u64 cookie, gfp_t gfp) |
| 11348 | { |
| 11349 | struct wiphy *wiphy = wdev->wiphy; |
| 11350 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11351 | struct sk_buff *msg; |
| 11352 | struct nlattr *func_attr; |
| 11353 | void *hdr; |
| 11354 | |
| 11355 | if (WARN_ON(!inst_id)) |
| 11356 | return; |
| 11357 | |
| 11358 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11359 | if (!msg) |
| 11360 | return; |
| 11361 | |
| 11362 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11363 | if (!hdr) { |
| 11364 | nlmsg_free(msg); |
| 11365 | return; |
| 11366 | } |
| 11367 | |
| 11368 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11369 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11370 | wdev->netdev->ifindex)) || |
| 11371 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11372 | NL80211_ATTR_PAD)) |
| 11373 | goto nla_put_failure; |
| 11374 | |
| 11375 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11376 | NL80211_ATTR_PAD)) |
| 11377 | goto nla_put_failure; |
| 11378 | |
| 11379 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11380 | if (!func_attr) |
| 11381 | goto nla_put_failure; |
| 11382 | |
| 11383 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11384 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11385 | goto nla_put_failure; |
| 11386 | |
| 11387 | nla_nest_end(msg, func_attr); |
| 11388 | genlmsg_end(msg, hdr); |
| 11389 | |
| 11390 | if (!wdev->owner_nlportid) |
| 11391 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11392 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11393 | else |
| 11394 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11395 | wdev->owner_nlportid); |
| 11396 | |
| 11397 | return; |
| 11398 | |
| 11399 | nla_put_failure: |
| 11400 | nlmsg_free(msg); |
| 11401 | } |
| 11402 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11403 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11404 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11405 | struct genl_info *info) |
| 11406 | { |
| 11407 | void *hdr; |
| 11408 | struct sk_buff *msg; |
| 11409 | |
| 11410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11411 | if (!msg) |
| 11412 | return -ENOMEM; |
| 11413 | |
| 11414 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11415 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11416 | if (!hdr) |
| 11417 | goto nla_put_failure; |
| 11418 | |
| 11419 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11420 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11421 | goto nla_put_failure; |
| 11422 | |
| 11423 | genlmsg_end(msg, hdr); |
| 11424 | return genlmsg_reply(msg, info); |
| 11425 | |
| 11426 | nla_put_failure: |
| 11427 | kfree_skb(msg); |
| 11428 | return -ENOBUFS; |
| 11429 | } |
| 11430 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11431 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11432 | { |
| 11433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11434 | struct cfg80211_update_ft_ies_params ft_params; |
| 11435 | struct net_device *dev = info->user_ptr[1]; |
| 11436 | |
| 11437 | if (!rdev->ops->update_ft_ies) |
| 11438 | return -EOPNOTSUPP; |
| 11439 | |
| 11440 | if (!info->attrs[NL80211_ATTR_MDID] || |
Arunk Khandavalli | 1a648fb | 2018-08-21 14:20:20 +0530 | [diff] [blame^] | 11441 | !info->attrs[NL80211_ATTR_IE] || |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11442 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11443 | return -EINVAL; |
| 11444 | |
| 11445 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11446 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11447 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11448 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11449 | |
| 11450 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11451 | } |
| 11452 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11453 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11454 | struct genl_info *info) |
| 11455 | { |
| 11456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11457 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11458 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11459 | u16 duration; |
| 11460 | int ret; |
| 11461 | |
| 11462 | if (!rdev->ops->crit_proto_start) |
| 11463 | return -EOPNOTSUPP; |
| 11464 | |
| 11465 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11466 | return -EINVAL; |
| 11467 | |
| 11468 | if (rdev->crit_proto_nlportid) |
| 11469 | return -EBUSY; |
| 11470 | |
| 11471 | /* determine protocol if provided */ |
| 11472 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11473 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11474 | |
| 11475 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11476 | return -EINVAL; |
| 11477 | |
| 11478 | /* timeout must be provided */ |
| 11479 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11480 | return -EINVAL; |
| 11481 | |
| 11482 | duration = |
| 11483 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11484 | |
| 11485 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11486 | return -ERANGE; |
| 11487 | |
| 11488 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11489 | if (!ret) |
| 11490 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11491 | |
| 11492 | return ret; |
| 11493 | } |
| 11494 | |
| 11495 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11496 | struct genl_info *info) |
| 11497 | { |
| 11498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11499 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11500 | |
| 11501 | if (!rdev->ops->crit_proto_stop) |
| 11502 | return -EOPNOTSUPP; |
| 11503 | |
| 11504 | if (rdev->crit_proto_nlportid) { |
| 11505 | rdev->crit_proto_nlportid = 0; |
| 11506 | rdev_crit_proto_stop(rdev, wdev); |
| 11507 | } |
| 11508 | return 0; |
| 11509 | } |
| 11510 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11511 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11512 | { |
| 11513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11514 | struct wireless_dev *wdev = |
| 11515 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11516 | int i, err; |
| 11517 | u32 vid, subcmd; |
| 11518 | |
| 11519 | if (!rdev->wiphy.vendor_commands) |
| 11520 | return -EOPNOTSUPP; |
| 11521 | |
| 11522 | if (IS_ERR(wdev)) { |
| 11523 | err = PTR_ERR(wdev); |
| 11524 | if (err != -EINVAL) |
| 11525 | return err; |
| 11526 | wdev = NULL; |
| 11527 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11528 | return -EINVAL; |
| 11529 | } |
| 11530 | |
| 11531 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11532 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11533 | return -EINVAL; |
| 11534 | |
| 11535 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11536 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11537 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11538 | const struct wiphy_vendor_command *vcmd; |
| 11539 | void *data = NULL; |
| 11540 | int len = 0; |
| 11541 | |
| 11542 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11543 | |
| 11544 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11545 | continue; |
| 11546 | |
| 11547 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11548 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11549 | if (!wdev) |
| 11550 | return -EINVAL; |
| 11551 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11552 | !wdev->netdev) |
| 11553 | return -EINVAL; |
| 11554 | |
| 11555 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 11556 | if (wdev->netdev && |
| 11557 | !netif_running(wdev->netdev)) |
| 11558 | return -ENETDOWN; |
| 11559 | if (!wdev->netdev && !wdev->p2p_started) |
| 11560 | return -ENETDOWN; |
| 11561 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11562 | |
| 11563 | if (!vcmd->doit) |
| 11564 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11565 | } else { |
| 11566 | wdev = NULL; |
| 11567 | } |
| 11568 | |
| 11569 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11570 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11571 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11572 | } |
| 11573 | |
| 11574 | rdev->cur_cmd_info = info; |
| 11575 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11576 | data, len); |
| 11577 | rdev->cur_cmd_info = NULL; |
| 11578 | return err; |
| 11579 | } |
| 11580 | |
| 11581 | return -EOPNOTSUPP; |
| 11582 | } |
| 11583 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11584 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11585 | struct netlink_callback *cb, |
| 11586 | struct cfg80211_registered_device **rdev, |
| 11587 | struct wireless_dev **wdev) |
| 11588 | { |
| 11589 | u32 vid, subcmd; |
| 11590 | unsigned int i; |
| 11591 | int vcmd_idx = -1; |
| 11592 | int err; |
| 11593 | void *data = NULL; |
| 11594 | unsigned int data_len = 0; |
| 11595 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11596 | if (cb->args[0]) { |
| 11597 | /* subtract the 1 again here */ |
| 11598 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11599 | struct wireless_dev *tmp; |
| 11600 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11601 | if (!wiphy) |
| 11602 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11603 | *rdev = wiphy_to_rdev(wiphy); |
| 11604 | *wdev = NULL; |
| 11605 | |
| 11606 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11607 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11608 | if (tmp->identifier == cb->args[1] - 1) { |
| 11609 | *wdev = tmp; |
| 11610 | break; |
| 11611 | } |
| 11612 | } |
| 11613 | } |
| 11614 | |
| 11615 | /* keep rtnl locked in successful case */ |
| 11616 | return 0; |
| 11617 | } |
| 11618 | |
| 11619 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 11620 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 11621 | nl80211_policy); |
| 11622 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11623 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11624 | |
| 11625 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11626 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11627 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11628 | |
| 11629 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 11630 | nl80211_fam.attrbuf); |
| 11631 | if (IS_ERR(*wdev)) |
| 11632 | *wdev = NULL; |
| 11633 | |
| 11634 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 11635 | nl80211_fam.attrbuf); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11636 | if (IS_ERR(*rdev)) |
| 11637 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11638 | |
| 11639 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11640 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11641 | |
| 11642 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11643 | const struct wiphy_vendor_command *vcmd; |
| 11644 | |
| 11645 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11646 | |
| 11647 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11648 | continue; |
| 11649 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11650 | if (!vcmd->dumpit) |
| 11651 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11652 | |
| 11653 | vcmd_idx = i; |
| 11654 | break; |
| 11655 | } |
| 11656 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11657 | if (vcmd_idx < 0) |
| 11658 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11659 | |
| 11660 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11661 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11662 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11663 | } |
| 11664 | |
| 11665 | /* 0 is the first index - add 1 to parse only once */ |
| 11666 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11667 | /* add 1 to know if it was NULL */ |
| 11668 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11669 | cb->args[2] = vcmd_idx; |
| 11670 | cb->args[3] = (unsigned long)data; |
| 11671 | cb->args[4] = data_len; |
| 11672 | |
| 11673 | /* keep rtnl locked in successful case */ |
| 11674 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11675 | } |
| 11676 | |
| 11677 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11678 | struct netlink_callback *cb) |
| 11679 | { |
| 11680 | struct cfg80211_registered_device *rdev; |
| 11681 | struct wireless_dev *wdev; |
| 11682 | unsigned int vcmd_idx; |
| 11683 | const struct wiphy_vendor_command *vcmd; |
| 11684 | void *data; |
| 11685 | int data_len; |
| 11686 | int err; |
| 11687 | struct nlattr *vendor_data; |
| 11688 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11689 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11690 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11691 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11692 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11693 | |
| 11694 | vcmd_idx = cb->args[2]; |
| 11695 | data = (void *)cb->args[3]; |
| 11696 | data_len = cb->args[4]; |
| 11697 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11698 | |
| 11699 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11700 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11701 | if (!wdev) { |
| 11702 | err = -EINVAL; |
| 11703 | goto out; |
| 11704 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11705 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11706 | !wdev->netdev) { |
| 11707 | err = -EINVAL; |
| 11708 | goto out; |
| 11709 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11710 | |
| 11711 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 11712 | if (wdev->netdev && |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11713 | !netif_running(wdev->netdev)) { |
| 11714 | err = -ENETDOWN; |
| 11715 | goto out; |
| 11716 | } |
| 11717 | if (!wdev->netdev && !wdev->p2p_started) { |
| 11718 | err = -ENETDOWN; |
| 11719 | goto out; |
| 11720 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11721 | } |
| 11722 | } |
| 11723 | |
| 11724 | while (1) { |
| 11725 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11726 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11727 | NL80211_CMD_VENDOR); |
| 11728 | if (!hdr) |
| 11729 | break; |
| 11730 | |
| 11731 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11732 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11733 | wdev_id(wdev), |
| 11734 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11735 | genlmsg_cancel(skb, hdr); |
| 11736 | break; |
| 11737 | } |
| 11738 | |
| 11739 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11740 | if (!vendor_data) { |
| 11741 | genlmsg_cancel(skb, hdr); |
| 11742 | break; |
| 11743 | } |
| 11744 | |
| 11745 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11746 | (unsigned long *)&cb->args[5]); |
| 11747 | nla_nest_end(skb, vendor_data); |
| 11748 | |
| 11749 | if (err == -ENOBUFS || err == -ENOENT) { |
| 11750 | genlmsg_cancel(skb, hdr); |
| 11751 | break; |
| 11752 | } else if (err) { |
| 11753 | genlmsg_cancel(skb, hdr); |
| 11754 | goto out; |
| 11755 | } |
| 11756 | |
| 11757 | genlmsg_end(skb, hdr); |
| 11758 | } |
| 11759 | |
| 11760 | err = skb->len; |
| 11761 | out: |
| 11762 | rtnl_unlock(); |
| 11763 | return err; |
| 11764 | } |
| 11765 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11766 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 11767 | enum nl80211_commands cmd, |
| 11768 | enum nl80211_attrs attr, |
| 11769 | int approxlen) |
| 11770 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11771 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11772 | |
| 11773 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 11774 | return NULL; |
| 11775 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 11776 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11777 | rdev->cur_cmd_info->snd_portid, |
| 11778 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 11779 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11780 | } |
| 11781 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 11782 | |
| 11783 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 11784 | { |
| 11785 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 11786 | void *hdr = ((void **)skb->cb)[1]; |
| 11787 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 11788 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 11789 | /* clear CB data for netlink core to own from now on */ |
| 11790 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 11791 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11792 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 11793 | kfree_skb(skb); |
| 11794 | return -EINVAL; |
| 11795 | } |
| 11796 | |
| 11797 | nla_nest_end(skb, data); |
| 11798 | genlmsg_end(skb, hdr); |
| 11799 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 11800 | } |
| 11801 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 11802 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11803 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 11804 | struct genl_info *info) |
| 11805 | { |
| 11806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11807 | struct cfg80211_qos_map *qos_map = NULL; |
| 11808 | struct net_device *dev = info->user_ptr[1]; |
| 11809 | u8 *pos, len, num_des, des_len, des; |
| 11810 | int ret; |
| 11811 | |
| 11812 | if (!rdev->ops->set_qos_map) |
| 11813 | return -EOPNOTSUPP; |
| 11814 | |
| 11815 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 11816 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11817 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11818 | |
| 11819 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 11820 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 11821 | return -EINVAL; |
| 11822 | |
| 11823 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 11824 | if (!qos_map) |
| 11825 | return -ENOMEM; |
| 11826 | |
| 11827 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 11828 | if (num_des) { |
| 11829 | des_len = num_des * |
| 11830 | sizeof(struct cfg80211_dscp_exception); |
| 11831 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 11832 | qos_map->num_des = num_des; |
| 11833 | for (des = 0; des < num_des; des++) { |
| 11834 | if (qos_map->dscp_exception[des].up > 7) { |
| 11835 | kfree(qos_map); |
| 11836 | return -EINVAL; |
| 11837 | } |
| 11838 | } |
| 11839 | pos += des_len; |
| 11840 | } |
| 11841 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 11842 | } |
| 11843 | |
| 11844 | wdev_lock(dev->ieee80211_ptr); |
| 11845 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 11846 | if (!ret) |
| 11847 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 11848 | wdev_unlock(dev->ieee80211_ptr); |
| 11849 | |
| 11850 | kfree(qos_map); |
| 11851 | return ret; |
| 11852 | } |
| 11853 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11854 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11855 | { |
| 11856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11857 | struct net_device *dev = info->user_ptr[1]; |
| 11858 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11859 | const u8 *peer; |
| 11860 | u8 tsid, up; |
| 11861 | u16 admitted_time = 0; |
| 11862 | int err; |
| 11863 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11864 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11865 | return -EOPNOTSUPP; |
| 11866 | |
| 11867 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 11868 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 11869 | return -EINVAL; |
| 11870 | |
| 11871 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11872 | if (tsid >= IEEE80211_NUM_TIDS) |
| 11873 | return -EINVAL; |
| 11874 | |
| 11875 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 11876 | if (up >= IEEE80211_NUM_UPS) |
| 11877 | return -EINVAL; |
| 11878 | |
| 11879 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11880 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11881 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11882 | * need more attributes for that (e.g. BA session requirement); |
| 11883 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11884 | */ |
| 11885 | return -EINVAL; |
| 11886 | } |
| 11887 | |
| 11888 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11889 | |
| 11890 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 11891 | admitted_time = |
| 11892 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 11893 | if (!admitted_time) |
| 11894 | return -EINVAL; |
| 11895 | } |
| 11896 | |
| 11897 | wdev_lock(wdev); |
| 11898 | switch (wdev->iftype) { |
| 11899 | case NL80211_IFTYPE_STATION: |
| 11900 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11901 | if (wdev->current_bss) |
| 11902 | break; |
| 11903 | err = -ENOTCONN; |
| 11904 | goto out; |
| 11905 | default: |
| 11906 | err = -EOPNOTSUPP; |
| 11907 | goto out; |
| 11908 | } |
| 11909 | |
| 11910 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 11911 | |
| 11912 | out: |
| 11913 | wdev_unlock(wdev); |
| 11914 | return err; |
| 11915 | } |
| 11916 | |
| 11917 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11918 | { |
| 11919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11920 | struct net_device *dev = info->user_ptr[1]; |
| 11921 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11922 | const u8 *peer; |
| 11923 | u8 tsid; |
| 11924 | int err; |
| 11925 | |
| 11926 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 11927 | return -EINVAL; |
| 11928 | |
| 11929 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11930 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11931 | |
| 11932 | wdev_lock(wdev); |
| 11933 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 11934 | wdev_unlock(wdev); |
| 11935 | |
| 11936 | return err; |
| 11937 | } |
| 11938 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11939 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 11940 | struct genl_info *info) |
| 11941 | { |
| 11942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11943 | struct net_device *dev = info->user_ptr[1]; |
| 11944 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11945 | struct cfg80211_chan_def chandef = {}; |
| 11946 | const u8 *addr; |
| 11947 | u8 oper_class; |
| 11948 | int err; |
| 11949 | |
| 11950 | if (!rdev->ops->tdls_channel_switch || |
| 11951 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11952 | return -EOPNOTSUPP; |
| 11953 | |
| 11954 | switch (dev->ieee80211_ptr->iftype) { |
| 11955 | case NL80211_IFTYPE_STATION: |
| 11956 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11957 | break; |
| 11958 | default: |
| 11959 | return -EOPNOTSUPP; |
| 11960 | } |
| 11961 | |
| 11962 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 11963 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 11964 | return -EINVAL; |
| 11965 | |
| 11966 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11967 | if (err) |
| 11968 | return err; |
| 11969 | |
| 11970 | /* |
| 11971 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 11972 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 11973 | * specification is not defined for them. |
| 11974 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 11975 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11976 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 11977 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 11978 | return -EINVAL; |
| 11979 | |
| 11980 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 11981 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 11982 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11983 | return -EINVAL; |
| 11984 | |
| 11985 | /* don't allow switching to DFS channels */ |
| 11986 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 11987 | return -EINVAL; |
| 11988 | |
| 11989 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11990 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 11991 | |
| 11992 | wdev_lock(wdev); |
| 11993 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 11994 | wdev_unlock(wdev); |
| 11995 | |
| 11996 | return err; |
| 11997 | } |
| 11998 | |
| 11999 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12000 | struct genl_info *info) |
| 12001 | { |
| 12002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12003 | struct net_device *dev = info->user_ptr[1]; |
| 12004 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12005 | const u8 *addr; |
| 12006 | |
| 12007 | if (!rdev->ops->tdls_channel_switch || |
| 12008 | !rdev->ops->tdls_cancel_channel_switch || |
| 12009 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12010 | return -EOPNOTSUPP; |
| 12011 | |
| 12012 | switch (dev->ieee80211_ptr->iftype) { |
| 12013 | case NL80211_IFTYPE_STATION: |
| 12014 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12015 | break; |
| 12016 | default: |
| 12017 | return -EOPNOTSUPP; |
| 12018 | } |
| 12019 | |
| 12020 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12021 | return -EINVAL; |
| 12022 | |
| 12023 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12024 | |
| 12025 | wdev_lock(wdev); |
| 12026 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12027 | wdev_unlock(wdev); |
| 12028 | |
| 12029 | return 0; |
| 12030 | } |
| 12031 | |
Michael Braun | d757efc | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12032 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12033 | struct genl_info *info) |
| 12034 | { |
| 12035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12036 | struct net_device *dev = info->user_ptr[1]; |
| 12037 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12038 | const struct nlattr *nla; |
| 12039 | bool enabled; |
| 12040 | |
| 12041 | if (netif_running(dev)) |
| 12042 | return -EBUSY; |
| 12043 | |
| 12044 | if (!rdev->ops->set_multicast_to_unicast) |
| 12045 | return -EOPNOTSUPP; |
| 12046 | |
| 12047 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12048 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12049 | return -EOPNOTSUPP; |
| 12050 | |
| 12051 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12052 | enabled = nla_get_flag(nla); |
| 12053 | |
| 12054 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12055 | } |
| 12056 | |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 12057 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 12058 | { |
| 12059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12060 | struct net_device *dev = info->user_ptr[1]; |
| 12061 | struct cfg80211_external_auth_params params; |
| 12062 | |
Srinivas Dasari | 05c8cd3 | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 12063 | if (!rdev->ops->external_auth) |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 12064 | return -EOPNOTSUPP; |
| 12065 | |
| 12066 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 12067 | return -EINVAL; |
| 12068 | |
| 12069 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 12070 | return -EINVAL; |
| 12071 | |
| 12072 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 12073 | return -EINVAL; |
| 12074 | |
| 12075 | memset(¶ms, 0, sizeof(params)); |
| 12076 | |
| 12077 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 12078 | if (params.ssid.ssid_len == 0 || |
| 12079 | params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 12080 | return -EINVAL; |
| 12081 | memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 12082 | params.ssid.ssid_len); |
| 12083 | |
| 12084 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 12085 | ETH_ALEN); |
| 12086 | |
| 12087 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 12088 | |
| 12089 | return rdev_external_auth(rdev, dev, ¶ms); |
| 12090 | } |
| 12091 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12092 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12093 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12094 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12095 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 12096 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 12097 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12098 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12099 | /* 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] | 12100 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 12101 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12102 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12103 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12104 | 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] | 12105 | struct genl_info *info) |
| 12106 | { |
| 12107 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12108 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12109 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12110 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 12111 | |
| 12112 | if (rtnl) |
| 12113 | rtnl_lock(); |
| 12114 | |
| 12115 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 12116 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12117 | if (IS_ERR(rdev)) { |
| 12118 | if (rtnl) |
| 12119 | rtnl_unlock(); |
| 12120 | return PTR_ERR(rdev); |
| 12121 | } |
| 12122 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12123 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 12124 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12125 | ASSERT_RTNL(); |
| 12126 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12127 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 12128 | info->attrs); |
| 12129 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12130 | if (rtnl) |
| 12131 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12132 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12133 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12134 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12135 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12136 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12137 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12138 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 12139 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12140 | if (rtnl) |
| 12141 | rtnl_unlock(); |
| 12142 | return -EINVAL; |
| 12143 | } |
| 12144 | |
| 12145 | info->user_ptr[1] = dev; |
| 12146 | } else { |
| 12147 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12148 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12149 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12150 | if (dev) { |
| 12151 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 12152 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12153 | if (rtnl) |
| 12154 | rtnl_unlock(); |
| 12155 | return -ENETDOWN; |
| 12156 | } |
| 12157 | |
| 12158 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12159 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12160 | if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE && |
| 12161 | !wdev->p2p_started) { |
| 12162 | if (rtnl) |
| 12163 | rtnl_unlock(); |
| 12164 | return -ENETDOWN; |
| 12165 | } |
| 12166 | if (wdev->iftype == NL80211_IFTYPE_NAN && |
| 12167 | !wdev->nan_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12168 | if (rtnl) |
| 12169 | rtnl_unlock(); |
| 12170 | return -ENETDOWN; |
| 12171 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12172 | } |
| 12173 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12174 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12175 | } |
| 12176 | |
| 12177 | return 0; |
| 12178 | } |
| 12179 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12180 | 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] | 12181 | struct genl_info *info) |
| 12182 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12183 | if (info->user_ptr[1]) { |
| 12184 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 12185 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12186 | |
| 12187 | if (wdev->netdev) |
| 12188 | dev_put(wdev->netdev); |
| 12189 | } else { |
| 12190 | dev_put(info->user_ptr[1]); |
| 12191 | } |
| 12192 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12193 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12194 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 12195 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12196 | |
| 12197 | /* If needed, clear the netlink message payload from the SKB |
| 12198 | * as it might contain key data that shouldn't stick around on |
| 12199 | * the heap after the SKB is freed. The netlink message header |
| 12200 | * is still needed for further processing, so leave it intact. |
| 12201 | */ |
| 12202 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 12203 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 12204 | |
| 12205 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 12206 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12207 | } |
| 12208 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 12209 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12210 | { |
| 12211 | .cmd = NL80211_CMD_GET_WIPHY, |
| 12212 | .doit = nl80211_get_wiphy, |
| 12213 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12214 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12215 | .policy = nl80211_policy, |
| 12216 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12217 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12218 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12219 | }, |
| 12220 | { |
| 12221 | .cmd = NL80211_CMD_SET_WIPHY, |
| 12222 | .doit = nl80211_set_wiphy, |
| 12223 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12224 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12225 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12226 | }, |
| 12227 | { |
| 12228 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 12229 | .doit = nl80211_get_interface, |
| 12230 | .dumpit = nl80211_dump_interface, |
| 12231 | .policy = nl80211_policy, |
| 12232 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12233 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12234 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12235 | }, |
| 12236 | { |
| 12237 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 12238 | .doit = nl80211_set_interface, |
| 12239 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12240 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12241 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12242 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12243 | }, |
| 12244 | { |
| 12245 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 12246 | .doit = nl80211_new_interface, |
| 12247 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12248 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12249 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12250 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12251 | }, |
| 12252 | { |
| 12253 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 12254 | .doit = nl80211_del_interface, |
| 12255 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12256 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 12257 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12258 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12259 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12260 | { |
| 12261 | .cmd = NL80211_CMD_GET_KEY, |
| 12262 | .doit = nl80211_get_key, |
| 12263 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12264 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12265 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12266 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12267 | }, |
| 12268 | { |
| 12269 | .cmd = NL80211_CMD_SET_KEY, |
| 12270 | .doit = nl80211_set_key, |
| 12271 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12272 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12273 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12274 | NL80211_FLAG_NEED_RTNL | |
| 12275 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12276 | }, |
| 12277 | { |
| 12278 | .cmd = NL80211_CMD_NEW_KEY, |
| 12279 | .doit = nl80211_new_key, |
| 12280 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12281 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12282 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12283 | NL80211_FLAG_NEED_RTNL | |
| 12284 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12285 | }, |
| 12286 | { |
| 12287 | .cmd = NL80211_CMD_DEL_KEY, |
| 12288 | .doit = nl80211_del_key, |
| 12289 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12290 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12291 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12292 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12293 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12294 | { |
| 12295 | .cmd = NL80211_CMD_SET_BEACON, |
| 12296 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12297 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12298 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12299 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12300 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12301 | }, |
| 12302 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12303 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12304 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12305 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12306 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12307 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12308 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12309 | }, |
| 12310 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12311 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12312 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12313 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12314 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12315 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12316 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12317 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12318 | { |
| 12319 | .cmd = NL80211_CMD_GET_STATION, |
| 12320 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12321 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12322 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12323 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12325 | }, |
| 12326 | { |
| 12327 | .cmd = NL80211_CMD_SET_STATION, |
| 12328 | .doit = nl80211_set_station, |
| 12329 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12330 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12331 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12332 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12333 | }, |
| 12334 | { |
| 12335 | .cmd = NL80211_CMD_NEW_STATION, |
| 12336 | .doit = nl80211_new_station, |
| 12337 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12338 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12340 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12341 | }, |
| 12342 | { |
| 12343 | .cmd = NL80211_CMD_DEL_STATION, |
| 12344 | .doit = nl80211_del_station, |
| 12345 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12346 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12348 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12349 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12350 | { |
| 12351 | .cmd = NL80211_CMD_GET_MPATH, |
| 12352 | .doit = nl80211_get_mpath, |
| 12353 | .dumpit = nl80211_dump_mpath, |
| 12354 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12355 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12357 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12358 | }, |
| 12359 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12360 | .cmd = NL80211_CMD_GET_MPP, |
| 12361 | .doit = nl80211_get_mpp, |
| 12362 | .dumpit = nl80211_dump_mpp, |
| 12363 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12364 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12366 | NL80211_FLAG_NEED_RTNL, |
| 12367 | }, |
| 12368 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12369 | .cmd = NL80211_CMD_SET_MPATH, |
| 12370 | .doit = nl80211_set_mpath, |
| 12371 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12372 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12374 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12375 | }, |
| 12376 | { |
| 12377 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12378 | .doit = nl80211_new_mpath, |
| 12379 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12380 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12382 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12383 | }, |
| 12384 | { |
| 12385 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12386 | .doit = nl80211_del_mpath, |
| 12387 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12388 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12390 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12391 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12392 | { |
| 12393 | .cmd = NL80211_CMD_SET_BSS, |
| 12394 | .doit = nl80211_set_bss, |
| 12395 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12396 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12398 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12399 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12400 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12401 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12402 | .doit = nl80211_get_reg_do, |
| 12403 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12404 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12405 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12406 | /* can be retrieved by unprivileged users */ |
| 12407 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12408 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12409 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12410 | .cmd = NL80211_CMD_SET_REG, |
| 12411 | .doit = nl80211_set_reg, |
| 12412 | .policy = nl80211_policy, |
| 12413 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12414 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12415 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12416 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12417 | { |
| 12418 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12419 | .doit = nl80211_req_set_reg, |
| 12420 | .policy = nl80211_policy, |
| 12421 | .flags = GENL_ADMIN_PERM, |
| 12422 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12423 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12424 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12425 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12426 | .policy = nl80211_policy, |
| 12427 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12429 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12430 | }, |
| 12431 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12432 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12433 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12434 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12435 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12437 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12438 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12439 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12440 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12441 | .doit = nl80211_trigger_scan, |
| 12442 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12443 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12444 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12445 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12446 | }, |
| 12447 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12448 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12449 | .doit = nl80211_abort_scan, |
| 12450 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12451 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12452 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12453 | NL80211_FLAG_NEED_RTNL, |
| 12454 | }, |
| 12455 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12456 | .cmd = NL80211_CMD_GET_SCAN, |
| 12457 | .policy = nl80211_policy, |
| 12458 | .dumpit = nl80211_dump_scan, |
| 12459 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12460 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12461 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12462 | .doit = nl80211_start_sched_scan, |
| 12463 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12464 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12465 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12466 | NL80211_FLAG_NEED_RTNL, |
| 12467 | }, |
| 12468 | { |
| 12469 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12470 | .doit = nl80211_stop_sched_scan, |
| 12471 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12472 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12473 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12474 | NL80211_FLAG_NEED_RTNL, |
| 12475 | }, |
| 12476 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12477 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12478 | .doit = nl80211_authenticate, |
| 12479 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12480 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12482 | NL80211_FLAG_NEED_RTNL | |
| 12483 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12484 | }, |
| 12485 | { |
| 12486 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12487 | .doit = nl80211_associate, |
| 12488 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12489 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12491 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12492 | }, |
| 12493 | { |
| 12494 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12495 | .doit = nl80211_deauthenticate, |
| 12496 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12497 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12498 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12499 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12500 | }, |
| 12501 | { |
| 12502 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12503 | .doit = nl80211_disassociate, |
| 12504 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12505 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12507 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12508 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12509 | { |
| 12510 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12511 | .doit = nl80211_join_ibss, |
| 12512 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12513 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12515 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12516 | }, |
| 12517 | { |
| 12518 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12519 | .doit = nl80211_leave_ibss, |
| 12520 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12521 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12523 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12524 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12525 | #ifdef CONFIG_NL80211_TESTMODE |
| 12526 | { |
| 12527 | .cmd = NL80211_CMD_TESTMODE, |
| 12528 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12529 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12530 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12531 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12532 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12533 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12534 | }, |
| 12535 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12536 | { |
| 12537 | .cmd = NL80211_CMD_CONNECT, |
| 12538 | .doit = nl80211_connect, |
| 12539 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12540 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12542 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12543 | }, |
| 12544 | { |
vamsi krishna | 30da4e8 | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12545 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12546 | .doit = nl80211_update_connect_params, |
| 12547 | .policy = nl80211_policy, |
| 12548 | .flags = GENL_ADMIN_PERM, |
| 12549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12550 | NL80211_FLAG_NEED_RTNL, |
| 12551 | }, |
| 12552 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12553 | .cmd = NL80211_CMD_DISCONNECT, |
| 12554 | .doit = nl80211_disconnect, |
| 12555 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12556 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12558 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12559 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12560 | { |
| 12561 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12562 | .doit = nl80211_wiphy_netns, |
| 12563 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12564 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12565 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12566 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12567 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12568 | { |
| 12569 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12570 | .policy = nl80211_policy, |
| 12571 | .dumpit = nl80211_dump_survey, |
| 12572 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12573 | { |
| 12574 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12575 | .doit = nl80211_setdel_pmksa, |
| 12576 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12577 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12579 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12580 | }, |
| 12581 | { |
| 12582 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12583 | .doit = nl80211_setdel_pmksa, |
| 12584 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12585 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12587 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12588 | }, |
| 12589 | { |
| 12590 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12591 | .doit = nl80211_flush_pmksa, |
| 12592 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12593 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12595 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12596 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12597 | { |
| 12598 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12599 | .doit = nl80211_remain_on_channel, |
| 12600 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12601 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12602 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12603 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12604 | }, |
| 12605 | { |
| 12606 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12607 | .doit = nl80211_cancel_remain_on_channel, |
| 12608 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12609 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12611 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12612 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12613 | { |
| 12614 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12615 | .doit = nl80211_set_tx_bitrate_mask, |
| 12616 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12617 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12618 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12619 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12620 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12621 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12622 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12623 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12624 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12625 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12626 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12627 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12628 | }, |
| 12629 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12630 | .cmd = NL80211_CMD_FRAME, |
| 12631 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12632 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12633 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12634 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12635 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12636 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12637 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12638 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12639 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12640 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12641 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12642 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12643 | NL80211_FLAG_NEED_RTNL, |
| 12644 | }, |
| 12645 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12646 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12647 | .doit = nl80211_set_power_save, |
| 12648 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12649 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12650 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12651 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12652 | }, |
| 12653 | { |
| 12654 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12655 | .doit = nl80211_get_power_save, |
| 12656 | .policy = nl80211_policy, |
| 12657 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12658 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12659 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12660 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12661 | { |
| 12662 | .cmd = NL80211_CMD_SET_CQM, |
| 12663 | .doit = nl80211_set_cqm, |
| 12664 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12665 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12666 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12667 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12668 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12669 | { |
| 12670 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12671 | .doit = nl80211_set_channel, |
| 12672 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12673 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12674 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12675 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12676 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12677 | { |
| 12678 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12679 | .doit = nl80211_set_wds_peer, |
| 12680 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12681 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12682 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12683 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12684 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12685 | { |
| 12686 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12687 | .doit = nl80211_join_mesh, |
| 12688 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12689 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12691 | NL80211_FLAG_NEED_RTNL, |
| 12692 | }, |
| 12693 | { |
| 12694 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12695 | .doit = nl80211_leave_mesh, |
| 12696 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12697 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12699 | NL80211_FLAG_NEED_RTNL, |
| 12700 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12701 | { |
| 12702 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12703 | .doit = nl80211_join_ocb, |
| 12704 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12705 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12706 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12707 | NL80211_FLAG_NEED_RTNL, |
| 12708 | }, |
| 12709 | { |
| 12710 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12711 | .doit = nl80211_leave_ocb, |
| 12712 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12713 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12715 | NL80211_FLAG_NEED_RTNL, |
| 12716 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12717 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12718 | { |
| 12719 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 12720 | .doit = nl80211_get_wowlan, |
| 12721 | .policy = nl80211_policy, |
| 12722 | /* can be retrieved by unprivileged users */ |
| 12723 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12724 | NL80211_FLAG_NEED_RTNL, |
| 12725 | }, |
| 12726 | { |
| 12727 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 12728 | .doit = nl80211_set_wowlan, |
| 12729 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12730 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12731 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12732 | NL80211_FLAG_NEED_RTNL, |
| 12733 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12734 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12735 | { |
| 12736 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 12737 | .doit = nl80211_set_rekey_data, |
| 12738 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12739 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12740 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12741 | NL80211_FLAG_NEED_RTNL | |
| 12742 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12743 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12744 | { |
| 12745 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 12746 | .doit = nl80211_tdls_mgmt, |
| 12747 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12748 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12749 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12750 | NL80211_FLAG_NEED_RTNL, |
| 12751 | }, |
| 12752 | { |
| 12753 | .cmd = NL80211_CMD_TDLS_OPER, |
| 12754 | .doit = nl80211_tdls_oper, |
| 12755 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12756 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12758 | NL80211_FLAG_NEED_RTNL, |
| 12759 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12760 | { |
| 12761 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 12762 | .doit = nl80211_register_unexpected_frame, |
| 12763 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12764 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12765 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12766 | NL80211_FLAG_NEED_RTNL, |
| 12767 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12768 | { |
| 12769 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 12770 | .doit = nl80211_probe_client, |
| 12771 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12772 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12774 | NL80211_FLAG_NEED_RTNL, |
| 12775 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12776 | { |
| 12777 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 12778 | .doit = nl80211_register_beacons, |
| 12779 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12780 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12781 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12782 | NL80211_FLAG_NEED_RTNL, |
| 12783 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12784 | { |
| 12785 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 12786 | .doit = nl80211_set_noack_map, |
| 12787 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12788 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12789 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12790 | NL80211_FLAG_NEED_RTNL, |
| 12791 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12792 | { |
| 12793 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 12794 | .doit = nl80211_start_p2p_device, |
| 12795 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12796 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12797 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12798 | NL80211_FLAG_NEED_RTNL, |
| 12799 | }, |
| 12800 | { |
| 12801 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 12802 | .doit = nl80211_stop_p2p_device, |
| 12803 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12804 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12805 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12806 | NL80211_FLAG_NEED_RTNL, |
| 12807 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12808 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12809 | .cmd = NL80211_CMD_START_NAN, |
| 12810 | .doit = nl80211_start_nan, |
| 12811 | .policy = nl80211_policy, |
| 12812 | .flags = GENL_ADMIN_PERM, |
| 12813 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12814 | NL80211_FLAG_NEED_RTNL, |
| 12815 | }, |
| 12816 | { |
| 12817 | .cmd = NL80211_CMD_STOP_NAN, |
| 12818 | .doit = nl80211_stop_nan, |
| 12819 | .policy = nl80211_policy, |
| 12820 | .flags = GENL_ADMIN_PERM, |
| 12821 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12822 | NL80211_FLAG_NEED_RTNL, |
| 12823 | }, |
| 12824 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12825 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 12826 | .doit = nl80211_nan_add_func, |
| 12827 | .policy = nl80211_policy, |
| 12828 | .flags = GENL_ADMIN_PERM, |
| 12829 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12830 | NL80211_FLAG_NEED_RTNL, |
| 12831 | }, |
| 12832 | { |
| 12833 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 12834 | .doit = nl80211_nan_del_func, |
| 12835 | .policy = nl80211_policy, |
| 12836 | .flags = GENL_ADMIN_PERM, |
| 12837 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12838 | NL80211_FLAG_NEED_RTNL, |
| 12839 | }, |
| 12840 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12841 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 12842 | .doit = nl80211_nan_change_config, |
| 12843 | .policy = nl80211_policy, |
| 12844 | .flags = GENL_ADMIN_PERM, |
| 12845 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12846 | NL80211_FLAG_NEED_RTNL, |
| 12847 | }, |
| 12848 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12849 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 12850 | .doit = nl80211_set_mcast_rate, |
| 12851 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12852 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12853 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12854 | NL80211_FLAG_NEED_RTNL, |
| 12855 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12856 | { |
| 12857 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 12858 | .doit = nl80211_set_mac_acl, |
| 12859 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12860 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12861 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12862 | NL80211_FLAG_NEED_RTNL, |
| 12863 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12864 | { |
| 12865 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 12866 | .doit = nl80211_start_radar_detection, |
| 12867 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12868 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12870 | NL80211_FLAG_NEED_RTNL, |
| 12871 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12872 | { |
| 12873 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 12874 | .doit = nl80211_get_protocol_features, |
| 12875 | .policy = nl80211_policy, |
| 12876 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12877 | { |
| 12878 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 12879 | .doit = nl80211_update_ft_ies, |
| 12880 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12881 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12883 | NL80211_FLAG_NEED_RTNL, |
| 12884 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12885 | { |
| 12886 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 12887 | .doit = nl80211_crit_protocol_start, |
| 12888 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12889 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12890 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12891 | NL80211_FLAG_NEED_RTNL, |
| 12892 | }, |
| 12893 | { |
| 12894 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 12895 | .doit = nl80211_crit_protocol_stop, |
| 12896 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12897 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12898 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12899 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12900 | }, |
| 12901 | { |
| 12902 | .cmd = NL80211_CMD_GET_COALESCE, |
| 12903 | .doit = nl80211_get_coalesce, |
| 12904 | .policy = nl80211_policy, |
| 12905 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12906 | NL80211_FLAG_NEED_RTNL, |
| 12907 | }, |
| 12908 | { |
| 12909 | .cmd = NL80211_CMD_SET_COALESCE, |
| 12910 | .doit = nl80211_set_coalesce, |
| 12911 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12912 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12913 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12914 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12915 | }, |
| 12916 | { |
| 12917 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 12918 | .doit = nl80211_channel_switch, |
| 12919 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12920 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12922 | NL80211_FLAG_NEED_RTNL, |
| 12923 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12924 | { |
| 12925 | .cmd = NL80211_CMD_VENDOR, |
| 12926 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12927 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12928 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12929 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12930 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12931 | NL80211_FLAG_NEED_RTNL, |
| 12932 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12933 | { |
| 12934 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 12935 | .doit = nl80211_set_qos_map, |
| 12936 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12937 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12939 | NL80211_FLAG_NEED_RTNL, |
| 12940 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12941 | { |
| 12942 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 12943 | .doit = nl80211_add_tx_ts, |
| 12944 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12945 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12947 | NL80211_FLAG_NEED_RTNL, |
| 12948 | }, |
| 12949 | { |
| 12950 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 12951 | .doit = nl80211_del_tx_ts, |
| 12952 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12953 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12955 | NL80211_FLAG_NEED_RTNL, |
| 12956 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12957 | { |
| 12958 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 12959 | .doit = nl80211_tdls_channel_switch, |
| 12960 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12961 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12963 | NL80211_FLAG_NEED_RTNL, |
| 12964 | }, |
| 12965 | { |
| 12966 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 12967 | .doit = nl80211_tdls_cancel_channel_switch, |
| 12968 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12969 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12970 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12971 | NL80211_FLAG_NEED_RTNL, |
| 12972 | }, |
Michael Braun | d757efc | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12973 | { |
| 12974 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 12975 | .doit = nl80211_set_multicast_to_unicast, |
| 12976 | .policy = nl80211_policy, |
| 12977 | .flags = GENL_UNS_ADMIN_PERM, |
| 12978 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12979 | NL80211_FLAG_NEED_RTNL, |
| 12980 | }, |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 12981 | { |
| 12982 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
| 12983 | .doit = nl80211_external_auth, |
| 12984 | .policy = nl80211_policy, |
| 12985 | .flags = GENL_ADMIN_PERM, |
| 12986 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12987 | NL80211_FLAG_NEED_RTNL, |
| 12988 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12989 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12990 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12991 | /* notification functions */ |
| 12992 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12993 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 12994 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12995 | { |
| 12996 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12997 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12998 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12999 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13000 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13001 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13003 | if (!msg) |
| 13004 | return; |
| 13005 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13006 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13007 | nlmsg_free(msg); |
| 13008 | return; |
| 13009 | } |
| 13010 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13011 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13012 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13013 | } |
| 13014 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13015 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13016 | struct wireless_dev *wdev, |
| 13017 | enum nl80211_commands cmd) |
| 13018 | { |
| 13019 | struct sk_buff *msg; |
| 13020 | |
| 13021 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13022 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13023 | |
| 13024 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13025 | if (!msg) |
| 13026 | return; |
| 13027 | |
| 13028 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13029 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13030 | nlmsg_free(msg); |
| 13031 | return; |
| 13032 | } |
| 13033 | |
| 13034 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13035 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13036 | } |
| 13037 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13038 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13039 | struct cfg80211_registered_device *rdev) |
| 13040 | { |
| 13041 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13042 | struct nlattr *nest; |
| 13043 | int i; |
| 13044 | |
| 13045 | if (WARN_ON(!req)) |
| 13046 | return 0; |
| 13047 | |
| 13048 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13049 | if (!nest) |
| 13050 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13051 | for (i = 0; i < req->n_ssids; i++) { |
| 13052 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13053 | goto nla_put_failure; |
| 13054 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13055 | nla_nest_end(msg, nest); |
| 13056 | |
| 13057 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13058 | if (!nest) |
| 13059 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13060 | for (i = 0; i < req->n_channels; i++) { |
| 13061 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13062 | goto nla_put_failure; |
| 13063 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13064 | nla_nest_end(msg, nest); |
| 13065 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13066 | if (req->ie && |
| 13067 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 13068 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13069 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13070 | if (req->flags && |
| 13071 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 13072 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 13073 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 13074 | if (req->info.scan_start_tsf && |
| 13075 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 13076 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 13077 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 13078 | req->info.tsf_bssid))) |
| 13079 | goto nla_put_failure; |
| 13080 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13081 | return 0; |
| 13082 | nla_put_failure: |
| 13083 | return -ENOBUFS; |
| 13084 | } |
| 13085 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13086 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 13087 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13088 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13089 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13090 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13091 | { |
| 13092 | void *hdr; |
| 13093 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13094 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13095 | if (!hdr) |
| 13096 | return -1; |
| 13097 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13098 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13099 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13100 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13101 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13102 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13103 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13104 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13105 | /* ignore errors and send incomplete event anyway */ |
| 13106 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13107 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13108 | genlmsg_end(msg, hdr); |
| 13109 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13110 | |
| 13111 | nla_put_failure: |
| 13112 | genlmsg_cancel(msg, hdr); |
| 13113 | return -EMSGSIZE; |
| 13114 | } |
| 13115 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13116 | static int |
| 13117 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 13118 | struct cfg80211_registered_device *rdev, |
| 13119 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13120 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13121 | { |
| 13122 | void *hdr; |
| 13123 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13124 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13125 | if (!hdr) |
| 13126 | return -1; |
| 13127 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13128 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13129 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13130 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13131 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13132 | genlmsg_end(msg, hdr); |
| 13133 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13134 | |
| 13135 | nla_put_failure: |
| 13136 | genlmsg_cancel(msg, hdr); |
| 13137 | return -EMSGSIZE; |
| 13138 | } |
| 13139 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13140 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13141 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13142 | { |
| 13143 | struct sk_buff *msg; |
| 13144 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13146 | if (!msg) |
| 13147 | return; |
| 13148 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13149 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13150 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 13151 | nlmsg_free(msg); |
| 13152 | return; |
| 13153 | } |
| 13154 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13155 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13156 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13157 | } |
| 13158 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13159 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 13160 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13161 | { |
| 13162 | struct sk_buff *msg; |
| 13163 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13164 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13165 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13166 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13167 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13168 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13169 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 13170 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13171 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13172 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13173 | } |
| 13174 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13175 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13176 | } |
| 13177 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13178 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 13179 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13180 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13181 | if (!msg) |
| 13182 | return; |
| 13183 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13184 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13185 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13186 | } |
| 13187 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13188 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 13189 | struct net_device *netdev) |
| 13190 | { |
| 13191 | struct sk_buff *msg; |
| 13192 | |
| 13193 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13194 | if (!msg) |
| 13195 | return; |
| 13196 | |
| 13197 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 13198 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 13199 | nlmsg_free(msg); |
| 13200 | return; |
| 13201 | } |
| 13202 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13203 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13204 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13205 | } |
| 13206 | |
| 13207 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 13208 | struct net_device *netdev, u32 cmd) |
| 13209 | { |
| 13210 | struct sk_buff *msg; |
| 13211 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13213 | if (!msg) |
| 13214 | return; |
| 13215 | |
| 13216 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 13217 | nlmsg_free(msg); |
| 13218 | return; |
| 13219 | } |
| 13220 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13221 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13222 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13223 | } |
| 13224 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13225 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 13226 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13227 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13228 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13229 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 13230 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13231 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13232 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 13233 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13234 | NL80211_REGDOM_TYPE_WORLD)) |
| 13235 | goto nla_put_failure; |
| 13236 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 13237 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13238 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 13239 | goto nla_put_failure; |
| 13240 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 13241 | request->intersect) { |
| 13242 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13243 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 13244 | goto nla_put_failure; |
| 13245 | } else { |
| 13246 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13247 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 13248 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 13249 | request->alpha2)) |
| 13250 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13251 | } |
| 13252 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13253 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 13254 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 13255 | |
| 13256 | if (wiphy && |
| 13257 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 13258 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 13259 | |
| 13260 | if (wiphy && |
| 13261 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 13262 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 13263 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13264 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13265 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13266 | return true; |
| 13267 | |
| 13268 | nla_put_failure: |
| 13269 | return false; |
| 13270 | } |
| 13271 | |
| 13272 | /* |
| 13273 | * This can happen on global regulatory changes or device specific settings |
| 13274 | * based on custom regulatory domains. |
| 13275 | */ |
| 13276 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13277 | struct regulatory_request *request) |
| 13278 | { |
| 13279 | struct sk_buff *msg; |
| 13280 | void *hdr; |
| 13281 | |
| 13282 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13283 | if (!msg) |
| 13284 | return; |
| 13285 | |
| 13286 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13287 | if (!hdr) { |
| 13288 | nlmsg_free(msg); |
| 13289 | return; |
| 13290 | } |
| 13291 | |
| 13292 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13293 | goto nla_put_failure; |
| 13294 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13295 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13296 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13297 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13298 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13299 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13300 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13301 | |
| 13302 | return; |
| 13303 | |
| 13304 | nla_put_failure: |
| 13305 | genlmsg_cancel(msg, hdr); |
| 13306 | nlmsg_free(msg); |
| 13307 | } |
| 13308 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13309 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13310 | struct net_device *netdev, |
| 13311 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13312 | enum nl80211_commands cmd, gfp_t gfp, |
| 13313 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13314 | { |
| 13315 | struct sk_buff *msg; |
| 13316 | void *hdr; |
| 13317 | |
Johannes Berg | 1445972 | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13318 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13319 | if (!msg) |
| 13320 | return; |
| 13321 | |
| 13322 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13323 | if (!hdr) { |
| 13324 | nlmsg_free(msg); |
| 13325 | return; |
| 13326 | } |
| 13327 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13329 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13330 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13331 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13332 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13333 | if (uapsd_queues >= 0) { |
| 13334 | struct nlattr *nla_wmm = |
| 13335 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13336 | if (!nla_wmm) |
| 13337 | goto nla_put_failure; |
| 13338 | |
| 13339 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13340 | uapsd_queues)) |
| 13341 | goto nla_put_failure; |
| 13342 | |
| 13343 | nla_nest_end(msg, nla_wmm); |
| 13344 | } |
| 13345 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13346 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13347 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13348 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13349 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13350 | return; |
| 13351 | |
| 13352 | nla_put_failure: |
| 13353 | genlmsg_cancel(msg, hdr); |
| 13354 | nlmsg_free(msg); |
| 13355 | } |
| 13356 | |
| 13357 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13358 | struct net_device *netdev, const u8 *buf, |
| 13359 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13360 | { |
| 13361 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13362 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13363 | } |
| 13364 | |
| 13365 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13366 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13367 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13368 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13369 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13370 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13371 | } |
| 13372 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13373 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13374 | struct net_device *netdev, const u8 *buf, |
| 13375 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13376 | { |
| 13377 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13378 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13379 | } |
| 13380 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13381 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13382 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13383 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13384 | { |
| 13385 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13386 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13387 | } |
| 13388 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13389 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13390 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13391 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13392 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13393 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13394 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13395 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13396 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13397 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13398 | if (WARN_ON(len < 2)) |
| 13399 | return; |
| 13400 | |
| 13401 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13402 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13403 | else |
| 13404 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13405 | |
| 13406 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13407 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13408 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13409 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13410 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13411 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13412 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13413 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13414 | { |
| 13415 | struct sk_buff *msg; |
| 13416 | void *hdr; |
| 13417 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13418 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13419 | if (!msg) |
| 13420 | return; |
| 13421 | |
| 13422 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13423 | if (!hdr) { |
| 13424 | nlmsg_free(msg); |
| 13425 | return; |
| 13426 | } |
| 13427 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13428 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13429 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13430 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13431 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13432 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13433 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13434 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13435 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13436 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13437 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13438 | return; |
| 13439 | |
| 13440 | nla_put_failure: |
| 13441 | genlmsg_cancel(msg, hdr); |
| 13442 | nlmsg_free(msg); |
| 13443 | } |
| 13444 | |
| 13445 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13446 | struct net_device *netdev, const u8 *addr, |
| 13447 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13448 | { |
| 13449 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13450 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13451 | } |
| 13452 | |
| 13453 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13454 | struct net_device *netdev, const u8 *addr, |
| 13455 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13456 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13457 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13458 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13459 | } |
| 13460 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13461 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 3f1905b | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13462 | struct net_device *netdev, |
| 13463 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | df93506 | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13464 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13465 | { |
| 13466 | struct sk_buff *msg; |
| 13467 | void *hdr; |
| 13468 | |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13469 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 13470 | cr->fils_kek_len + cr->pmk_len + |
| 13471 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13472 | if (!msg) |
| 13473 | return; |
| 13474 | |
| 13475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13476 | if (!hdr) { |
| 13477 | nlmsg_free(msg); |
| 13478 | return; |
| 13479 | } |
| 13480 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13482 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 3f1905b | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13483 | (cr->bssid && |
| 13484 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13485 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 3f1905b | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13486 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13487 | cr->status) || |
| 13488 | (cr->status < 0 && |
Purushottam Kushwaha | df93506 | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13489 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 3f1905b | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13490 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 13491 | cr->timeout_reason))) || |
| 13492 | (cr->req_ie && |
| 13493 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 13494 | (cr->resp_ie && |
| 13495 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | 36eabf6 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13496 | cr->resp_ie)) || |
| 13497 | (cr->update_erp_next_seq_num && |
| 13498 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 13499 | cr->fils_erp_next_seq_num)) || |
| 13500 | (cr->status == WLAN_STATUS_SUCCESS && |
| 13501 | ((cr->fils_kek && |
| 13502 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, |
| 13503 | cr->fils_kek)) || |
| 13504 | (cr->pmk && |
| 13505 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || |
| 13506 | (cr->pmkid && |
| 13507 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13508 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13509 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13510 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13511 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13512 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13513 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13514 | return; |
| 13515 | |
| 13516 | nla_put_failure: |
| 13517 | genlmsg_cancel(msg, hdr); |
| 13518 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13519 | } |
| 13520 | |
| 13521 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 9e841a6 | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13522 | struct net_device *netdev, |
| 13523 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13524 | { |
| 13525 | struct sk_buff *msg; |
| 13526 | void *hdr; |
Avraham Stern | 9e841a6 | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13527 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13528 | |
Avraham Stern | 9e841a6 | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13529 | 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] | 13530 | if (!msg) |
| 13531 | return; |
| 13532 | |
| 13533 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13534 | if (!hdr) { |
| 13535 | nlmsg_free(msg); |
| 13536 | return; |
| 13537 | } |
| 13538 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13539 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13540 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13541 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 9e841a6 | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 13542 | (info->req_ie && |
| 13543 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 13544 | info->req_ie)) || |
| 13545 | (info->resp_ie && |
| 13546 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Avraham Stern | 562be6e | 2017-06-09 13:08:45 +0100 | [diff] [blame] | 13547 | info->resp_ie)) || |
| 13548 | (info->authorized && |
| 13549 | nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13550 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13551 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13552 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13553 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13554 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13555 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13556 | return; |
| 13557 | |
| 13558 | nla_put_failure: |
| 13559 | genlmsg_cancel(msg, hdr); |
| 13560 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13561 | } |
| 13562 | |
| 13563 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13564 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13565 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13566 | { |
| 13567 | struct sk_buff *msg; |
| 13568 | void *hdr; |
| 13569 | |
Johannes Berg | 1445972 | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13570 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13571 | if (!msg) |
| 13572 | return; |
| 13573 | |
| 13574 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13575 | if (!hdr) { |
| 13576 | nlmsg_free(msg); |
| 13577 | return; |
| 13578 | } |
| 13579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13580 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13581 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13582 | (from_ap && reason && |
| 13583 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13584 | (from_ap && |
| 13585 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13586 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13587 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13588 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13589 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13590 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13591 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13592 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13593 | return; |
| 13594 | |
| 13595 | nla_put_failure: |
| 13596 | genlmsg_cancel(msg, hdr); |
| 13597 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13598 | } |
| 13599 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13600 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13601 | struct net_device *netdev, const u8 *bssid, |
| 13602 | gfp_t gfp) |
| 13603 | { |
| 13604 | struct sk_buff *msg; |
| 13605 | void *hdr; |
| 13606 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13607 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13608 | if (!msg) |
| 13609 | return; |
| 13610 | |
| 13611 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13612 | if (!hdr) { |
| 13613 | nlmsg_free(msg); |
| 13614 | return; |
| 13615 | } |
| 13616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13617 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13618 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13619 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13620 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13621 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13622 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13623 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13624 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13625 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13626 | return; |
| 13627 | |
| 13628 | nla_put_failure: |
| 13629 | genlmsg_cancel(msg, hdr); |
| 13630 | nlmsg_free(msg); |
| 13631 | } |
| 13632 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13633 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13634 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13635 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13636 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13637 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13638 | struct sk_buff *msg; |
| 13639 | void *hdr; |
| 13640 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13641 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13642 | return; |
| 13643 | |
| 13644 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13645 | |
Johannes Berg | 1445972 | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13646 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13647 | if (!msg) |
| 13648 | return; |
| 13649 | |
| 13650 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13651 | if (!hdr) { |
| 13652 | nlmsg_free(msg); |
| 13653 | return; |
| 13654 | } |
| 13655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13656 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13657 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13658 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13659 | (ie_len && ie && |
| 13660 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13661 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13662 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13663 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13664 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13665 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13666 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13667 | return; |
| 13668 | |
| 13669 | nla_put_failure: |
| 13670 | genlmsg_cancel(msg, hdr); |
| 13671 | nlmsg_free(msg); |
| 13672 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13673 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13674 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13675 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13676 | struct net_device *netdev, const u8 *addr, |
| 13677 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13678 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13679 | { |
| 13680 | struct sk_buff *msg; |
| 13681 | void *hdr; |
| 13682 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13684 | if (!msg) |
| 13685 | return; |
| 13686 | |
| 13687 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 13688 | if (!hdr) { |
| 13689 | nlmsg_free(msg); |
| 13690 | return; |
| 13691 | } |
| 13692 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13693 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13694 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13695 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 13696 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 13697 | (key_id != -1 && |
| 13698 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 13699 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 13700 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13701 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13702 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13703 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13704 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13705 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13706 | return; |
| 13707 | |
| 13708 | nla_put_failure: |
| 13709 | genlmsg_cancel(msg, hdr); |
| 13710 | nlmsg_free(msg); |
| 13711 | } |
| 13712 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13713 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 13714 | struct ieee80211_channel *channel_before, |
| 13715 | struct ieee80211_channel *channel_after) |
| 13716 | { |
| 13717 | struct sk_buff *msg; |
| 13718 | void *hdr; |
| 13719 | struct nlattr *nl_freq; |
| 13720 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13722 | if (!msg) |
| 13723 | return; |
| 13724 | |
| 13725 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 13726 | if (!hdr) { |
| 13727 | nlmsg_free(msg); |
| 13728 | return; |
| 13729 | } |
| 13730 | |
| 13731 | /* |
| 13732 | * Since we are applying the beacon hint to a wiphy we know its |
| 13733 | * wiphy_idx is valid |
| 13734 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13735 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 13736 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13737 | |
| 13738 | /* Before */ |
| 13739 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 13740 | if (!nl_freq) |
| 13741 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13742 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13743 | goto nla_put_failure; |
| 13744 | nla_nest_end(msg, nl_freq); |
| 13745 | |
| 13746 | /* After */ |
| 13747 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 13748 | if (!nl_freq) |
| 13749 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13750 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13751 | goto nla_put_failure; |
| 13752 | nla_nest_end(msg, nl_freq); |
| 13753 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13754 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13755 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13756 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13757 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13758 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13759 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13760 | |
| 13761 | return; |
| 13762 | |
| 13763 | nla_put_failure: |
| 13764 | genlmsg_cancel(msg, hdr); |
| 13765 | nlmsg_free(msg); |
| 13766 | } |
| 13767 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13768 | static void nl80211_send_remain_on_chan_event( |
| 13769 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13770 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13771 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13772 | unsigned int duration, gfp_t gfp) |
| 13773 | { |
| 13774 | struct sk_buff *msg; |
| 13775 | void *hdr; |
| 13776 | |
| 13777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13778 | if (!msg) |
| 13779 | return; |
| 13780 | |
| 13781 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13782 | if (!hdr) { |
| 13783 | nlmsg_free(msg); |
| 13784 | return; |
| 13785 | } |
| 13786 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13787 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13788 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13789 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13790 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13791 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13792 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13793 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 13794 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13795 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13796 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13797 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13798 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13799 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 13800 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 13801 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13802 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13803 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13804 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13805 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13806 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13807 | return; |
| 13808 | |
| 13809 | nla_put_failure: |
| 13810 | genlmsg_cancel(msg, hdr); |
| 13811 | nlmsg_free(msg); |
| 13812 | } |
| 13813 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13814 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 13815 | struct ieee80211_channel *chan, |
| 13816 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13817 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13818 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13819 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13820 | |
| 13821 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13822 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13823 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13824 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13825 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13826 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13827 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13828 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 13829 | struct ieee80211_channel *chan, |
| 13830 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13831 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13832 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13833 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13834 | |
| 13835 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13836 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13837 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13838 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13839 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13840 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13841 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 13842 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13843 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13844 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13845 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13846 | struct sk_buff *msg; |
| 13847 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13848 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 13849 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13850 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13851 | if (!msg) |
| 13852 | return; |
| 13853 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13854 | 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] | 13855 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13856 | nlmsg_free(msg); |
| 13857 | return; |
| 13858 | } |
| 13859 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13860 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13861 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13862 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13863 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13864 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13865 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 13866 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13867 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13868 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13869 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13870 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13871 | struct station_info empty_sinfo = {}; |
| 13872 | |
| 13873 | if (!sinfo) |
| 13874 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13875 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13876 | trace_cfg80211_del_sta(dev, mac_addr); |
| 13877 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13879 | if (!msg) |
| 13880 | return; |
| 13881 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13882 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 13883 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13884 | nlmsg_free(msg); |
| 13885 | return; |
| 13886 | } |
| 13887 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13889 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13890 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13891 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13892 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13893 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 13894 | enum nl80211_connect_failed_reason reason, |
| 13895 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13896 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13897 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13898 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13899 | struct sk_buff *msg; |
| 13900 | void *hdr; |
| 13901 | |
| 13902 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 13903 | if (!msg) |
| 13904 | return; |
| 13905 | |
| 13906 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 13907 | if (!hdr) { |
| 13908 | nlmsg_free(msg); |
| 13909 | return; |
| 13910 | } |
| 13911 | |
| 13912 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13913 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 13914 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 13915 | goto nla_put_failure; |
| 13916 | |
| 13917 | genlmsg_end(msg, hdr); |
| 13918 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13919 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13920 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13921 | return; |
| 13922 | |
| 13923 | nla_put_failure: |
| 13924 | genlmsg_cancel(msg, hdr); |
| 13925 | nlmsg_free(msg); |
| 13926 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13927 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13928 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13929 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 13930 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13931 | { |
| 13932 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13933 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13934 | struct sk_buff *msg; |
| 13935 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13936 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13937 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13938 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13939 | return false; |
| 13940 | |
| 13941 | msg = nlmsg_new(100, gfp); |
| 13942 | if (!msg) |
| 13943 | return true; |
| 13944 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13945 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13946 | if (!hdr) { |
| 13947 | nlmsg_free(msg); |
| 13948 | return true; |
| 13949 | } |
| 13950 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13951 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13952 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13953 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13954 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13955 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13956 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13957 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13958 | return true; |
| 13959 | |
| 13960 | nla_put_failure: |
| 13961 | genlmsg_cancel(msg, hdr); |
| 13962 | nlmsg_free(msg); |
| 13963 | return true; |
| 13964 | } |
| 13965 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13966 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 13967 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13968 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13969 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13970 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13971 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13972 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 13973 | |
| 13974 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13975 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 13976 | trace_cfg80211_return_bool(false); |
| 13977 | return false; |
| 13978 | } |
| 13979 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 13980 | addr, gfp); |
| 13981 | trace_cfg80211_return_bool(ret); |
| 13982 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13983 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13984 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 13985 | |
| 13986 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 13987 | const u8 *addr, gfp_t gfp) |
| 13988 | { |
| 13989 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13990 | bool ret; |
| 13991 | |
| 13992 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 13993 | |
| 13994 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13995 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 13996 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 13997 | trace_cfg80211_return_bool(false); |
| 13998 | return false; |
| 13999 | } |
| 14000 | ret = __nl80211_unexpected_frame(dev, |
| 14001 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14002 | addr, gfp); |
| 14003 | trace_cfg80211_return_bool(ret); |
| 14004 | return ret; |
| 14005 | } |
| 14006 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14007 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14008 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14009 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14010 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14011 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14012 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14013 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14014 | struct sk_buff *msg; |
| 14015 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14016 | |
Johannes Berg | 1445972 | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14017 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14018 | if (!msg) |
| 14019 | return -ENOMEM; |
| 14020 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14021 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14022 | if (!hdr) { |
| 14023 | nlmsg_free(msg); |
| 14024 | return -ENOMEM; |
| 14025 | } |
| 14026 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14027 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14028 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14029 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14030 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14031 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14032 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14033 | (sig_dbm && |
| 14034 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14035 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14036 | (flags && |
| 14037 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14038 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14039 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14040 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14041 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14042 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14043 | |
| 14044 | nla_put_failure: |
| 14045 | genlmsg_cancel(msg, hdr); |
| 14046 | nlmsg_free(msg); |
| 14047 | return -ENOBUFS; |
| 14048 | } |
| 14049 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14050 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14051 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14052 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14053 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14054 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14055 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14056 | struct sk_buff *msg; |
| 14057 | void *hdr; |
| 14058 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14059 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 14060 | |
Johannes Berg | 1445972 | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14061 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14062 | if (!msg) |
| 14063 | return; |
| 14064 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14065 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14066 | if (!hdr) { |
| 14067 | nlmsg_free(msg); |
| 14068 | return; |
| 14069 | } |
| 14070 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14071 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14072 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14073 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14074 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14075 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14076 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14077 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14078 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14079 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14080 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14081 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14082 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14083 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14084 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14085 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14086 | return; |
| 14087 | |
| 14088 | nla_put_failure: |
| 14089 | genlmsg_cancel(msg, hdr); |
| 14090 | nlmsg_free(msg); |
| 14091 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14092 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14093 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14094 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 14095 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14096 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14097 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14098 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14099 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14100 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14101 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14102 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14103 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14104 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14105 | cb = (void **)msg->cb; |
| 14106 | |
| 14107 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 14108 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14109 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14110 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14111 | } |
| 14112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14113 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14114 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14115 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14116 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14117 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14118 | goto nla_put_failure; |
| 14119 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14120 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 14121 | if (!cb[1]) |
| 14122 | goto nla_put_failure; |
| 14123 | |
| 14124 | cb[2] = rdev; |
| 14125 | |
| 14126 | return msg; |
| 14127 | nla_put_failure: |
| 14128 | nlmsg_free(msg); |
| 14129 | return NULL; |
| 14130 | } |
| 14131 | |
| 14132 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 14133 | { |
| 14134 | void **cb = (void **)msg->cb; |
| 14135 | struct cfg80211_registered_device *rdev = cb[2]; |
| 14136 | |
| 14137 | nla_nest_end(msg, cb[1]); |
| 14138 | genlmsg_end(msg, cb[0]); |
| 14139 | |
| 14140 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 14141 | |
| 14142 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14143 | NL80211_MCGRP_MLME, gfp); |
| 14144 | } |
| 14145 | |
| 14146 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 14147 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 14148 | gfp_t gfp) |
| 14149 | { |
| 14150 | struct sk_buff *msg; |
| 14151 | |
| 14152 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 14153 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14154 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 14155 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 14156 | return; |
| 14157 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14158 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14159 | if (!msg) |
| 14160 | return; |
| 14161 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14162 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 14163 | rssi_event)) |
| 14164 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14165 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14166 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14167 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14168 | return; |
| 14169 | |
| 14170 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14171 | nlmsg_free(msg); |
| 14172 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14173 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14174 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14175 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 14176 | const u8 *peer, u32 num_packets, |
| 14177 | u32 rate, u32 intvl, gfp_t gfp) |
| 14178 | { |
| 14179 | struct sk_buff *msg; |
| 14180 | |
| 14181 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14182 | if (!msg) |
| 14183 | return; |
| 14184 | |
| 14185 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 14186 | goto nla_put_failure; |
| 14187 | |
| 14188 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 14189 | goto nla_put_failure; |
| 14190 | |
| 14191 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 14192 | goto nla_put_failure; |
| 14193 | |
| 14194 | cfg80211_send_cqm(msg, gfp); |
| 14195 | return; |
| 14196 | |
| 14197 | nla_put_failure: |
| 14198 | nlmsg_free(msg); |
| 14199 | } |
| 14200 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 14201 | |
| 14202 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 14203 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 14204 | { |
| 14205 | struct sk_buff *msg; |
| 14206 | |
| 14207 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 14208 | |
| 14209 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14210 | if (!msg) |
| 14211 | return; |
| 14212 | |
| 14213 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 14214 | goto nla_put_failure; |
| 14215 | |
| 14216 | cfg80211_send_cqm(msg, gfp); |
| 14217 | return; |
| 14218 | |
| 14219 | nla_put_failure: |
| 14220 | nlmsg_free(msg); |
| 14221 | } |
| 14222 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 14223 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14224 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 14225 | { |
| 14226 | struct sk_buff *msg; |
| 14227 | |
| 14228 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14229 | if (!msg) |
| 14230 | return; |
| 14231 | |
| 14232 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 14233 | goto nla_put_failure; |
| 14234 | |
| 14235 | cfg80211_send_cqm(msg, gfp); |
| 14236 | return; |
| 14237 | |
| 14238 | nla_put_failure: |
| 14239 | nlmsg_free(msg); |
| 14240 | } |
| 14241 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 14242 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14243 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 14244 | struct net_device *netdev, const u8 *bssid, |
| 14245 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14246 | { |
| 14247 | struct sk_buff *msg; |
| 14248 | struct nlattr *rekey_attr; |
| 14249 | void *hdr; |
| 14250 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14251 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14252 | if (!msg) |
| 14253 | return; |
| 14254 | |
| 14255 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 14256 | if (!hdr) { |
| 14257 | nlmsg_free(msg); |
| 14258 | return; |
| 14259 | } |
| 14260 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14261 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14262 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14263 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14264 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14265 | |
| 14266 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 14267 | if (!rekey_attr) |
| 14268 | goto nla_put_failure; |
| 14269 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14270 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 14271 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 14272 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14273 | |
| 14274 | nla_nest_end(msg, rekey_attr); |
| 14275 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14276 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14277 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14278 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14279 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14280 | return; |
| 14281 | |
| 14282 | nla_put_failure: |
| 14283 | genlmsg_cancel(msg, hdr); |
| 14284 | nlmsg_free(msg); |
| 14285 | } |
| 14286 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14287 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 14288 | const u8 *replay_ctr, gfp_t gfp) |
| 14289 | { |
| 14290 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14291 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14292 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14293 | |
| 14294 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14295 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14296 | } |
| 14297 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14298 | |
| 14299 | static void |
| 14300 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14301 | struct net_device *netdev, int index, |
| 14302 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14303 | { |
| 14304 | struct sk_buff *msg; |
| 14305 | struct nlattr *attr; |
| 14306 | void *hdr; |
| 14307 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14308 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14309 | if (!msg) |
| 14310 | return; |
| 14311 | |
| 14312 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14313 | if (!hdr) { |
| 14314 | nlmsg_free(msg); |
| 14315 | return; |
| 14316 | } |
| 14317 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14318 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14319 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14320 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14321 | |
| 14322 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14323 | if (!attr) |
| 14324 | goto nla_put_failure; |
| 14325 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14326 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14327 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14328 | (preauth && |
| 14329 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14330 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14331 | |
| 14332 | nla_nest_end(msg, attr); |
| 14333 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14334 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14335 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14336 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14337 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14338 | return; |
| 14339 | |
| 14340 | nla_put_failure: |
| 14341 | genlmsg_cancel(msg, hdr); |
| 14342 | nlmsg_free(msg); |
| 14343 | } |
| 14344 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14345 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14346 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14347 | { |
| 14348 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14349 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14350 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14351 | |
| 14352 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14353 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14354 | } |
| 14355 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14356 | |
| 14357 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14358 | struct net_device *netdev, |
| 14359 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14360 | gfp_t gfp, |
| 14361 | enum nl80211_commands notif, |
| 14362 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14363 | { |
| 14364 | struct sk_buff *msg; |
| 14365 | void *hdr; |
| 14366 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14367 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14368 | if (!msg) |
| 14369 | return; |
| 14370 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14371 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14372 | if (!hdr) { |
| 14373 | nlmsg_free(msg); |
| 14374 | return; |
| 14375 | } |
| 14376 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14377 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14378 | goto nla_put_failure; |
| 14379 | |
| 14380 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14381 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14382 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14383 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14384 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14385 | goto nla_put_failure; |
| 14386 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14387 | genlmsg_end(msg, hdr); |
| 14388 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14389 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14390 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14391 | return; |
| 14392 | |
| 14393 | nla_put_failure: |
| 14394 | genlmsg_cancel(msg, hdr); |
| 14395 | nlmsg_free(msg); |
| 14396 | } |
| 14397 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14398 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14399 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14400 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14401 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14402 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14403 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14404 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14405 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14406 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14407 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14408 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14409 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14410 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14411 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14412 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14413 | } |
| 14414 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14415 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14416 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14417 | struct cfg80211_chan_def *chandef, |
| 14418 | u8 count) |
| 14419 | { |
| 14420 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14421 | struct wiphy *wiphy = wdev->wiphy; |
| 14422 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14423 | |
| 14424 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14425 | |
| 14426 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14427 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14428 | } |
| 14429 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14430 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14431 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14432 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14433 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14434 | enum nl80211_radar_event event, |
| 14435 | struct net_device *netdev, gfp_t gfp) |
| 14436 | { |
| 14437 | struct sk_buff *msg; |
| 14438 | void *hdr; |
| 14439 | |
| 14440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14441 | if (!msg) |
| 14442 | return; |
| 14443 | |
| 14444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14445 | if (!hdr) { |
| 14446 | nlmsg_free(msg); |
| 14447 | return; |
| 14448 | } |
| 14449 | |
| 14450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14451 | goto nla_put_failure; |
| 14452 | |
| 14453 | /* NOP and radar events don't need a netdev parameter */ |
| 14454 | if (netdev) { |
| 14455 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14456 | |
| 14457 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14458 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14459 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14460 | goto nla_put_failure; |
| 14461 | } |
| 14462 | |
| 14463 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14464 | goto nla_put_failure; |
| 14465 | |
| 14466 | if (nl80211_send_chandef(msg, chandef)) |
| 14467 | goto nla_put_failure; |
| 14468 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14469 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14470 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14471 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14472 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14473 | return; |
| 14474 | |
| 14475 | nla_put_failure: |
| 14476 | genlmsg_cancel(msg, hdr); |
| 14477 | nlmsg_free(msg); |
| 14478 | } |
| 14479 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14480 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14481 | u64 cookie, bool acked, gfp_t gfp) |
| 14482 | { |
| 14483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14484 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14485 | struct sk_buff *msg; |
| 14486 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14487 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14488 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14489 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14490 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14491 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14492 | if (!msg) |
| 14493 | return; |
| 14494 | |
| 14495 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14496 | if (!hdr) { |
| 14497 | nlmsg_free(msg); |
| 14498 | return; |
| 14499 | } |
| 14500 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14502 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14503 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14504 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14505 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14506 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14507 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14508 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14509 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14510 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14511 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14512 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14513 | return; |
| 14514 | |
| 14515 | nla_put_failure: |
| 14516 | genlmsg_cancel(msg, hdr); |
| 14517 | nlmsg_free(msg); |
| 14518 | } |
| 14519 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14520 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14521 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14522 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14523 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14524 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14526 | struct sk_buff *msg; |
| 14527 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14528 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14529 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14530 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14531 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14532 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14533 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14534 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14535 | if (!msg) { |
| 14536 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14537 | return; |
| 14538 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14539 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14540 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14541 | if (!hdr) |
| 14542 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14543 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14544 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14545 | (freq && |
| 14546 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14547 | (sig_dbm && |
| 14548 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14549 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14550 | goto nla_put_failure; |
| 14551 | |
| 14552 | genlmsg_end(msg, hdr); |
| 14553 | |
| 14554 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14555 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14556 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14557 | return; |
| 14558 | |
| 14559 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14560 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14561 | if (hdr) |
| 14562 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14563 | nlmsg_free(msg); |
| 14564 | } |
| 14565 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14566 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14567 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14568 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14569 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14570 | { |
| 14571 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14572 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14573 | int i, j; |
| 14574 | |
| 14575 | nl_results = nla_nest_start( |
| 14576 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14577 | if (!nl_results) |
| 14578 | return -EMSGSIZE; |
| 14579 | |
| 14580 | for (i = 0; i < nd->n_matches; i++) { |
| 14581 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14582 | |
| 14583 | nl_match = nla_nest_start(msg, i); |
| 14584 | if (!nl_match) |
| 14585 | break; |
| 14586 | |
| 14587 | /* The SSID attribute is optional in nl80211, but for |
| 14588 | * simplicity reasons it's always present in the |
| 14589 | * cfg80211 structure. If a driver can't pass the |
| 14590 | * SSID, that needs to be changed. A zero length SSID |
| 14591 | * is still a valid SSID (wildcard), so it cannot be |
| 14592 | * used for this purpose. |
| 14593 | */ |
| 14594 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14595 | match->ssid.ssid)) { |
| 14596 | nla_nest_cancel(msg, nl_match); |
| 14597 | goto out; |
| 14598 | } |
| 14599 | |
| 14600 | if (match->n_channels) { |
| 14601 | nl_freqs = nla_nest_start( |
| 14602 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14603 | if (!nl_freqs) { |
| 14604 | nla_nest_cancel(msg, nl_match); |
| 14605 | goto out; |
| 14606 | } |
| 14607 | |
| 14608 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14609 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14610 | nla_nest_cancel(msg, nl_freqs); |
| 14611 | nla_nest_cancel(msg, nl_match); |
| 14612 | goto out; |
| 14613 | } |
| 14614 | } |
| 14615 | |
| 14616 | nla_nest_end(msg, nl_freqs); |
| 14617 | } |
| 14618 | |
| 14619 | nla_nest_end(msg, nl_match); |
| 14620 | } |
| 14621 | |
| 14622 | out: |
| 14623 | nla_nest_end(msg, nl_results); |
| 14624 | return 0; |
| 14625 | } |
| 14626 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14627 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14628 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14629 | gfp_t gfp) |
| 14630 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14631 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14632 | struct sk_buff *msg; |
| 14633 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14634 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14635 | |
| 14636 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14637 | |
| 14638 | if (wakeup) |
| 14639 | size += wakeup->packet_present_len; |
| 14640 | |
| 14641 | msg = nlmsg_new(size, gfp); |
| 14642 | if (!msg) |
| 14643 | return; |
| 14644 | |
| 14645 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14646 | if (!hdr) |
| 14647 | goto free_msg; |
| 14648 | |
| 14649 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14650 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14651 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14652 | goto free_msg; |
| 14653 | |
| 14654 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14655 | wdev->netdev->ifindex)) |
| 14656 | goto free_msg; |
| 14657 | |
| 14658 | if (wakeup) { |
| 14659 | struct nlattr *reasons; |
| 14660 | |
| 14661 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14662 | if (!reasons) |
| 14663 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14664 | |
| 14665 | if (wakeup->disconnect && |
| 14666 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14667 | goto free_msg; |
| 14668 | if (wakeup->magic_pkt && |
| 14669 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14670 | goto free_msg; |
| 14671 | if (wakeup->gtk_rekey_failure && |
| 14672 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 14673 | goto free_msg; |
| 14674 | if (wakeup->eap_identity_req && |
| 14675 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 14676 | goto free_msg; |
| 14677 | if (wakeup->four_way_handshake && |
| 14678 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 14679 | goto free_msg; |
| 14680 | if (wakeup->rfkill_release && |
| 14681 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 14682 | goto free_msg; |
| 14683 | |
| 14684 | if (wakeup->pattern_idx >= 0 && |
| 14685 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 14686 | wakeup->pattern_idx)) |
| 14687 | goto free_msg; |
| 14688 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14689 | if (wakeup->tcp_match && |
| 14690 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 14691 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14692 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14693 | if (wakeup->tcp_connlost && |
| 14694 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 14695 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14696 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14697 | if (wakeup->tcp_nomoretokens && |
| 14698 | nla_put_flag(msg, |
| 14699 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 14700 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14701 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14702 | if (wakeup->packet) { |
| 14703 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 14704 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 14705 | |
| 14706 | if (!wakeup->packet_80211) { |
| 14707 | pkt_attr = |
| 14708 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 14709 | len_attr = |
| 14710 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 14711 | } |
| 14712 | |
| 14713 | if (wakeup->packet_len && |
| 14714 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 14715 | goto free_msg; |
| 14716 | |
| 14717 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 14718 | wakeup->packet)) |
| 14719 | goto free_msg; |
| 14720 | } |
| 14721 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14722 | if (wakeup->net_detect && |
| 14723 | cfg80211_net_detect_results(msg, wakeup)) |
| 14724 | goto free_msg; |
| 14725 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14726 | nla_nest_end(msg, reasons); |
| 14727 | } |
| 14728 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14729 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14730 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14731 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14732 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14733 | return; |
| 14734 | |
| 14735 | free_msg: |
| 14736 | nlmsg_free(msg); |
| 14737 | } |
| 14738 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 14739 | #endif |
| 14740 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14741 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 14742 | enum nl80211_tdls_operation oper, |
| 14743 | u16 reason_code, gfp_t gfp) |
| 14744 | { |
| 14745 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14746 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14747 | struct sk_buff *msg; |
| 14748 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14749 | |
| 14750 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 14751 | reason_code); |
| 14752 | |
| 14753 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14754 | if (!msg) |
| 14755 | return; |
| 14756 | |
| 14757 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 14758 | if (!hdr) { |
| 14759 | nlmsg_free(msg); |
| 14760 | return; |
| 14761 | } |
| 14762 | |
| 14763 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14764 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14765 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 14766 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 14767 | (reason_code > 0 && |
| 14768 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 14769 | goto nla_put_failure; |
| 14770 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14771 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14772 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14773 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14774 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14775 | return; |
| 14776 | |
| 14777 | nla_put_failure: |
| 14778 | genlmsg_cancel(msg, hdr); |
| 14779 | nlmsg_free(msg); |
| 14780 | } |
| 14781 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 14782 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14783 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 14784 | unsigned long state, |
| 14785 | void *_notify) |
| 14786 | { |
| 14787 | struct netlink_notify *notify = _notify; |
| 14788 | struct cfg80211_registered_device *rdev; |
| 14789 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14790 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14791 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 14792 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14793 | return NOTIFY_DONE; |
| 14794 | |
| 14795 | rcu_read_lock(); |
| 14796 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14797 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14798 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 14799 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 14800 | rcu_dereference(rdev->sched_scan_req); |
| 14801 | |
| 14802 | if (sched_scan_req && notify->portid && |
Johannes Berg | 0a28f53 | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 14803 | sched_scan_req->owner_nlportid == notify->portid) { |
| 14804 | sched_scan_req->owner_nlportid = 0; |
| 14805 | |
| 14806 | if (rdev->ops->sched_scan_stop && |
| 14807 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 14808 | schedule_work(&rdev->sched_scan_stop_wk); |
| 14809 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14810 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 14811 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14812 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14813 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14814 | if (wdev->owner_nlportid == notify->portid) |
| 14815 | schedule_destroy_work = true; |
Andrzej Zaborowski | 5f3f4d3 | 2018-02-04 21:57:28 +0530 | [diff] [blame] | 14816 | else if (wdev->conn_owner_nlportid == notify->portid) |
| 14817 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14818 | } |
| 14819 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14820 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14821 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 14822 | list) { |
| 14823 | if (reg->nlportid == notify->portid) { |
| 14824 | list_del(®->list); |
| 14825 | kfree(reg); |
| 14826 | break; |
| 14827 | } |
| 14828 | } |
| 14829 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14830 | |
| 14831 | if (schedule_destroy_work) { |
| 14832 | struct cfg80211_iface_destroy *destroy; |
| 14833 | |
| 14834 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 14835 | if (destroy) { |
| 14836 | destroy->nlportid = notify->portid; |
| 14837 | spin_lock(&rdev->destroy_list_lock); |
| 14838 | list_add(&destroy->list, &rdev->destroy_list); |
| 14839 | spin_unlock(&rdev->destroy_list_lock); |
| 14840 | schedule_work(&rdev->destroy_work); |
| 14841 | } |
| 14842 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14843 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14844 | |
| 14845 | rcu_read_unlock(); |
| 14846 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 14847 | /* |
| 14848 | * It is possible that the user space process that is controlling the |
| 14849 | * indoor setting disappeared, so notify the regulatory core. |
| 14850 | */ |
| 14851 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 14852 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14853 | } |
| 14854 | |
| 14855 | static struct notifier_block nl80211_netlink_notifier = { |
| 14856 | .notifier_call = nl80211_netlink_notify, |
| 14857 | }; |
| 14858 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14859 | void cfg80211_ft_event(struct net_device *netdev, |
| 14860 | struct cfg80211_ft_event_params *ft_event) |
| 14861 | { |
| 14862 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14863 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14864 | struct sk_buff *msg; |
| 14865 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14866 | |
| 14867 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 14868 | |
| 14869 | if (!ft_event->target_ap) |
| 14870 | return; |
| 14871 | |
Dedy Lansky | fe06451 | 2018-05-17 13:46:22 +0300 | [diff] [blame] | 14872 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 14873 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14874 | if (!msg) |
| 14875 | return; |
| 14876 | |
| 14877 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14878 | if (!hdr) |
| 14879 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14880 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 14884 | goto out; |
| 14885 | |
| 14886 | if (ft_event->ies && |
| 14887 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 14888 | goto out; |
| 14889 | if (ft_event->ric_ies && |
| 14890 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 14891 | ft_event->ric_ies)) |
| 14892 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14893 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14894 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14895 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14896 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14897 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14898 | return; |
| 14899 | out: |
| 14900 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14901 | } |
| 14902 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 14903 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14904 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 14905 | { |
| 14906 | struct cfg80211_registered_device *rdev; |
| 14907 | struct sk_buff *msg; |
| 14908 | void *hdr; |
| 14909 | u32 nlportid; |
| 14910 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14911 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14912 | if (!rdev->crit_proto_nlportid) |
| 14913 | return; |
| 14914 | |
| 14915 | nlportid = rdev->crit_proto_nlportid; |
| 14916 | rdev->crit_proto_nlportid = 0; |
| 14917 | |
| 14918 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14919 | if (!msg) |
| 14920 | return; |
| 14921 | |
| 14922 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 14923 | if (!hdr) |
| 14924 | goto nla_put_failure; |
| 14925 | |
| 14926 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14927 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14928 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14929 | goto nla_put_failure; |
| 14930 | |
| 14931 | genlmsg_end(msg, hdr); |
| 14932 | |
| 14933 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 14934 | return; |
| 14935 | |
| 14936 | nla_put_failure: |
| 14937 | if (hdr) |
| 14938 | genlmsg_cancel(msg, hdr); |
| 14939 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14940 | } |
| 14941 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 14942 | |
Sameer Thalappil | faa4c4a | 2013-07-05 14:58:32 -0700 | [diff] [blame] | 14943 | void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp) |
| 14944 | { |
| 14945 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14946 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14947 | |
| 14948 | nl80211_send_mlme_event(rdev, netdev, NULL, 0, |
| 14949 | NL80211_CMD_STOP_AP, gfp, -1); |
| 14950 | } |
| 14951 | EXPORT_SYMBOL(cfg80211_ap_stopped); |
| 14952 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14953 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 14954 | { |
| 14955 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14956 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14957 | struct sk_buff *msg; |
| 14958 | void *hdr; |
| 14959 | |
| 14960 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14961 | if (!msg) |
| 14962 | return; |
| 14963 | |
| 14964 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 14965 | if (!hdr) |
| 14966 | goto out; |
| 14967 | |
| 14968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14970 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14971 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14972 | goto out; |
| 14973 | |
| 14974 | genlmsg_end(msg, hdr); |
| 14975 | |
| 14976 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 14977 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 14978 | return; |
| 14979 | out: |
| 14980 | nlmsg_free(msg); |
| 14981 | } |
| 14982 | |
Srinivas Dasari | d041a1a | 2018-02-07 18:32:17 +0530 | [diff] [blame] | 14983 | int cfg80211_external_auth_request(struct net_device *dev, |
| 14984 | struct cfg80211_external_auth_params *params, |
| 14985 | gfp_t gfp) |
| 14986 | { |
| 14987 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14988 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14989 | struct sk_buff *msg; |
| 14990 | void *hdr; |
| 14991 | |
| 14992 | if (!wdev->conn_owner_nlportid) |
| 14993 | return -EINVAL; |
| 14994 | |
| 14995 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14996 | if (!msg) |
| 14997 | return -ENOMEM; |
| 14998 | |
| 14999 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 15000 | if (!hdr) |
| 15001 | goto nla_put_failure; |
| 15002 | |
| 15003 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15004 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15005 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 15006 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 15007 | params->action) || |
| 15008 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 15009 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 15010 | params->ssid.ssid)) |
| 15011 | goto nla_put_failure; |
| 15012 | |
| 15013 | genlmsg_end(msg, hdr); |
| 15014 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 15015 | wdev->conn_owner_nlportid); |
| 15016 | return 0; |
| 15017 | |
| 15018 | nla_put_failure: |
| 15019 | nlmsg_free(msg); |
| 15020 | return -ENOBUFS; |
| 15021 | } |
| 15022 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 15023 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15024 | /* initialisation/exit functions */ |
| 15025 | |
| 15026 | int nl80211_init(void) |
| 15027 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 15028 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15029 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15030 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 15031 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15032 | if (err) |
| 15033 | return err; |
| 15034 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15035 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 15036 | if (err) |
| 15037 | goto err_out; |
| 15038 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15039 | return 0; |
| 15040 | err_out: |
| 15041 | genl_unregister_family(&nl80211_fam); |
| 15042 | return err; |
| 15043 | } |
| 15044 | |
| 15045 | void nl80211_exit(void) |
| 15046 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15047 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15048 | genl_unregister_family(&nl80211_fam); |
| 15049 | } |