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> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 21 | #include <net/genetlink.h> |
| 22 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 23 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 24 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include "core.h" |
| 26 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 27 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 28 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 31 | struct genl_info *info, |
| 32 | struct cfg80211_crypto_settings *settings, |
| 33 | int cipher_limit); |
| 34 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 35 | 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] | 36 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 37 | 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] | 38 | struct genl_info *info); |
| 39 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | /* the netlink family */ |
| 41 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 42 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 43 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 44 | .hdrsize = 0, /* no private header */ |
| 45 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 46 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 47 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 48 | .pre_doit = nl80211_pre_doit, |
| 49 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 52 | /* multicast groups */ |
| 53 | enum nl80211_multicast_groups { |
| 54 | NL80211_MCGRP_CONFIG, |
| 55 | NL80211_MCGRP_SCAN, |
| 56 | NL80211_MCGRP_REGULATORY, |
| 57 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 58 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 59 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 60 | }; |
| 61 | |
| 62 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 63 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 64 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 65 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 66 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 67 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 68 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 69 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 70 | #endif |
| 71 | }; |
| 72 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 73 | /* returns ERR_PTR values */ |
| 74 | static struct wireless_dev * |
| 75 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 77 | struct cfg80211_registered_device *rdev; |
| 78 | struct wireless_dev *result = NULL; |
| 79 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 80 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 81 | u64 wdev_id; |
| 82 | int wiphy_idx = -1; |
| 83 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 84 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 85 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 87 | if (!have_ifidx && !have_wdev_id) |
| 88 | return ERR_PTR(-EINVAL); |
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) |
| 91 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 92 | if (have_wdev_id) { |
| 93 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 94 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 97 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 98 | struct wireless_dev *wdev; |
| 99 | |
| 100 | if (wiphy_net(&rdev->wiphy) != netns) |
| 101 | continue; |
| 102 | |
| 103 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 104 | continue; |
| 105 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 106 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 107 | if (have_ifidx && wdev->netdev && |
| 108 | wdev->netdev->ifindex == ifidx) { |
| 109 | result = wdev; |
| 110 | break; |
| 111 | } |
| 112 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 113 | result = wdev; |
| 114 | break; |
| 115 | } |
| 116 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 117 | |
| 118 | if (result) |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | if (result) |
| 123 | return result; |
| 124 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 127 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 128 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 129 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 130 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 131 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 132 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 133 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 134 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 135 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 136 | !attrs[NL80211_ATTR_IFINDEX] && |
| 137 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 138 | return ERR_PTR(-EINVAL); |
| 139 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 141 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 142 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 143 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 144 | if (attrs[NL80211_ATTR_WDEV]) { |
| 145 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 146 | struct wireless_dev *wdev; |
| 147 | bool found = false; |
| 148 | |
| 149 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 150 | if (tmp) { |
| 151 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 152 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 153 | if (wdev->identifier != (u32)wdev_id) |
| 154 | continue; |
| 155 | found = true; |
| 156 | break; |
| 157 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 158 | |
| 159 | if (!found) |
| 160 | tmp = NULL; |
| 161 | |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | rdev = tmp; |
| 165 | } |
| 166 | } |
| 167 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 168 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 169 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 170 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 171 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 172 | if (netdev) { |
| 173 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 174 | tmp = wiphy_to_rdev( |
| 175 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 176 | else |
| 177 | tmp = NULL; |
| 178 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 179 | /* not wireless device -- return error */ |
| 180 | if (!tmp) |
| 181 | return ERR_PTR(-EINVAL); |
| 182 | |
| 183 | /* mismatch -- return error */ |
| 184 | if (rdev && tmp != rdev) |
| 185 | return ERR_PTR(-EINVAL); |
| 186 | |
| 187 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 188 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 191 | if (!rdev) |
| 192 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 193 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 194 | if (netns != wiphy_net(&rdev->wiphy)) |
| 195 | return ERR_PTR(-ENODEV); |
| 196 | |
| 197 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* |
| 201 | * This function returns a pointer to the driver |
| 202 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | * |
| 204 | * The result of this can be a PTR_ERR and hence must |
| 205 | * be checked with IS_ERR() for errors. |
| 206 | */ |
| 207 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 208 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 210 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 213 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 214 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 215 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 216 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 217 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 219 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 220 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 221 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 222 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 224 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 225 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 226 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 227 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 228 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 229 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 230 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 231 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 232 | |
| 233 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 234 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 235 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 236 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 237 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 238 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 240 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 241 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 242 | .len = WLAN_MAX_KEY_LEN }, |
| 243 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 244 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 245 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 247 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 248 | |
| 249 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 250 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
| 253 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 254 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 255 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 257 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 258 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 259 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 260 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 262 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 264 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 265 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 266 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 267 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 268 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 269 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 271 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 272 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 274 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 275 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 276 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 277 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 278 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 279 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 280 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 281 | |
| 282 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 283 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 284 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 286 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 287 | |
| 288 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_SSID_LEN }, |
| 290 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 291 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_STA_FLAGS2] = { |
| 296 | .len = sizeof(struct nl80211_sta_flag_update), |
| 297 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 298 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 300 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 301 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 302 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 303 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 305 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 307 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 308 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
| 313 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 314 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 319 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 321 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 322 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 327 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 329 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 330 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 331 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
| 334 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 338 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 343 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 345 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 347 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 348 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 349 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 351 | .len = NL80211_HT_CAPABILITY_LEN |
| 352 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 353 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 355 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 356 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 357 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 358 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 359 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 360 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 361 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 362 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 363 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 364 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 365 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 366 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 368 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 369 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 370 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 371 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 372 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 373 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 374 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 375 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 376 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 377 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 378 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 379 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 381 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 382 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 383 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 384 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 385 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 386 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 387 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 388 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 389 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 390 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 391 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 392 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 395 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 396 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 397 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 398 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 399 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 400 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 403 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 404 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 405 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 406 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 407 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 408 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 409 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 410 | }, |
| 411 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 412 | }; |
| 413 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 415 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 416 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 417 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 418 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 419 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 420 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 421 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 422 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 423 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 424 | }; |
| 425 | |
| 426 | /* policy for the key default flags */ |
| 427 | static const struct nla_policy |
| 428 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 429 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 430 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 431 | }; |
| 432 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 433 | /* policy for WoWLAN attributes */ |
| 434 | static const struct nla_policy |
| 435 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 436 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 437 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 438 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 439 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 440 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 441 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 442 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 443 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 444 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 445 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | static const struct nla_policy |
| 449 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 450 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 451 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 452 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 453 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 454 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 455 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 456 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 457 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 458 | }, |
| 459 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 460 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 461 | }, |
| 462 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 463 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 464 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 465 | }; |
| 466 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 467 | /* policy for coalesce rule attributes */ |
| 468 | static const struct nla_policy |
| 469 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 470 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 471 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 472 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 473 | }; |
| 474 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 475 | /* policy for GTK rekey offload attributes */ |
| 476 | static const struct nla_policy |
| 477 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 478 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 479 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 480 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 481 | }; |
| 482 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 483 | static const struct nla_policy |
| 484 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 485 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 486 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 487 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 488 | }; |
| 489 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 490 | static const struct nla_policy |
| 491 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 492 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 493 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 494 | }; |
| 495 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 496 | static const struct nla_policy |
| 497 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 498 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 499 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 500 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 501 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 502 | }, |
| 503 | }; |
| 504 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 505 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 506 | struct netlink_callback *cb, |
| 507 | struct cfg80211_registered_device **rdev, |
| 508 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 509 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 510 | int err; |
| 511 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 512 | rtnl_lock(); |
| 513 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | if (!cb->args[0]) { |
| 515 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 516 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 517 | nl80211_policy); |
| 518 | if (err) |
| 519 | goto out_unlock; |
| 520 | |
| 521 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 522 | nl80211_fam.attrbuf); |
| 523 | if (IS_ERR(*wdev)) { |
| 524 | err = PTR_ERR(*wdev); |
| 525 | goto out_unlock; |
| 526 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 527 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 528 | /* 0 is the first index - add 1 to parse only once */ |
| 529 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 530 | cb->args[1] = (*wdev)->identifier; |
| 531 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 532 | /* subtract the 1 again here */ |
| 533 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 534 | struct wireless_dev *tmp; |
| 535 | |
| 536 | if (!wiphy) { |
| 537 | err = -ENODEV; |
| 538 | goto out_unlock; |
| 539 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 540 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 541 | *wdev = NULL; |
| 542 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 543 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 544 | if (tmp->identifier == cb->args[1]) { |
| 545 | *wdev = tmp; |
| 546 | break; |
| 547 | } |
| 548 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 549 | |
| 550 | if (!*wdev) { |
| 551 | err = -ENODEV; |
| 552 | goto out_unlock; |
| 553 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 556 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 557 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 558 | rtnl_unlock(); |
| 559 | return err; |
| 560 | } |
| 561 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 562 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 563 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 564 | rtnl_unlock(); |
| 565 | } |
| 566 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 567 | /* IE validation */ |
| 568 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 569 | { |
| 570 | const u8 *pos; |
| 571 | int len; |
| 572 | |
| 573 | if (!attr) |
| 574 | return true; |
| 575 | |
| 576 | pos = nla_data(attr); |
| 577 | len = nla_len(attr); |
| 578 | |
| 579 | while (len) { |
| 580 | u8 elemlen; |
| 581 | |
| 582 | if (len < 2) |
| 583 | return false; |
| 584 | len -= 2; |
| 585 | |
| 586 | elemlen = pos[1]; |
| 587 | if (elemlen > len) |
| 588 | return false; |
| 589 | |
| 590 | len -= elemlen; |
| 591 | pos += 2 + elemlen; |
| 592 | } |
| 593 | |
| 594 | return true; |
| 595 | } |
| 596 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 597 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 598 | 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] | 599 | int flags, u8 cmd) |
| 600 | { |
| 601 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 602 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 605 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 606 | struct ieee80211_channel *chan, |
| 607 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 608 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 609 | /* Some channels must be completely excluded from the |
| 610 | * list to protect old user-space tools from breaking |
| 611 | */ |
| 612 | if (!large && chan->flags & |
| 613 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 614 | return 0; |
| 615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 617 | chan->center_freq)) |
| 618 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 619 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 620 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 622 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 623 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 624 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 625 | goto nla_put_failure; |
| 626 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 627 | goto nla_put_failure; |
| 628 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 629 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 630 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 631 | goto nla_put_failure; |
| 632 | if (large) { |
| 633 | u32 time; |
| 634 | |
| 635 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 636 | |
| 637 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 638 | chan->dfs_state)) |
| 639 | goto nla_put_failure; |
| 640 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 641 | time)) |
| 642 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 643 | if (nla_put_u32(msg, |
| 644 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 645 | chan->dfs_cac_ms)) |
| 646 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 647 | } |
| 648 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 649 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 650 | if (large) { |
| 651 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 652 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 653 | goto nla_put_failure; |
| 654 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 655 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 656 | goto nla_put_failure; |
| 657 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 658 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 659 | goto nla_put_failure; |
| 660 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 661 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 662 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 663 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 664 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 665 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 666 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 667 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 668 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 669 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 670 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 671 | goto nla_put_failure; |
| 672 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 673 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 674 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 675 | } |
| 676 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 677 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 678 | DBM_TO_MBM(chan->max_power))) |
| 679 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 680 | |
| 681 | return 0; |
| 682 | |
| 683 | nla_put_failure: |
| 684 | return -ENOBUFS; |
| 685 | } |
| 686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 687 | /* netlink command implementations */ |
| 688 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 689 | struct key_parse { |
| 690 | struct key_params p; |
| 691 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 692 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 693 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 694 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 698 | { |
| 699 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 700 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 701 | nl80211_key_policy); |
| 702 | if (err) |
| 703 | return err; |
| 704 | |
| 705 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 706 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 707 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 708 | if (k->def) { |
| 709 | k->def_uni = true; |
| 710 | k->def_multi = true; |
| 711 | } |
| 712 | if (k->defmgmt) |
| 713 | k->def_multi = true; |
| 714 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 715 | if (tb[NL80211_KEY_IDX]) |
| 716 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 717 | |
| 718 | if (tb[NL80211_KEY_DATA]) { |
| 719 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 720 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 721 | } |
| 722 | |
| 723 | if (tb[NL80211_KEY_SEQ]) { |
| 724 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 725 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 726 | } |
| 727 | |
| 728 | if (tb[NL80211_KEY_CIPHER]) |
| 729 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 730 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 731 | if (tb[NL80211_KEY_TYPE]) { |
| 732 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 733 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 734 | return -EINVAL; |
| 735 | } |
| 736 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 737 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 738 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 739 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 740 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 741 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 742 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 747 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 748 | } |
| 749 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 754 | { |
| 755 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 756 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 757 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 758 | } |
| 759 | |
| 760 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 761 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 762 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 763 | } |
| 764 | |
| 765 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 766 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 767 | |
| 768 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 769 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 770 | |
| 771 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 772 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 773 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 774 | if (k->def) { |
| 775 | k->def_uni = true; |
| 776 | k->def_multi = true; |
| 777 | } |
| 778 | if (k->defmgmt) |
| 779 | k->def_multi = true; |
| 780 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 782 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 783 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 787 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 788 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 789 | int err = nla_parse_nested( |
| 790 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 791 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 792 | nl80211_key_default_policy); |
| 793 | if (err) |
| 794 | return err; |
| 795 | |
| 796 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 797 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 798 | } |
| 799 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 804 | { |
| 805 | int err; |
| 806 | |
| 807 | memset(k, 0, sizeof(*k)); |
| 808 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 809 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 810 | |
| 811 | if (info->attrs[NL80211_ATTR_KEY]) |
| 812 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 813 | else |
| 814 | err = nl80211_parse_key_old(info, k); |
| 815 | |
| 816 | if (err) |
| 817 | return err; |
| 818 | |
| 819 | if (k->def && k->defmgmt) |
| 820 | return -EINVAL; |
| 821 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 822 | if (k->defmgmt) { |
| 823 | if (k->def_uni || !k->def_multi) |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 827 | if (k->idx != -1) { |
| 828 | if (k->defmgmt) { |
| 829 | if (k->idx < 4 || k->idx > 5) |
| 830 | return -EINVAL; |
| 831 | } else if (k->def) { |
| 832 | if (k->idx < 0 || k->idx > 3) |
| 833 | return -EINVAL; |
| 834 | } else { |
| 835 | if (k->idx < 0 || k->idx > 5) |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 843 | static struct cfg80211_cached_keys * |
| 844 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 845 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | { |
| 847 | struct key_parse parse; |
| 848 | struct nlattr *key; |
| 849 | struct cfg80211_cached_keys *result; |
| 850 | int rem, err, def = 0; |
| 851 | |
| 852 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 853 | if (!result) |
| 854 | return ERR_PTR(-ENOMEM); |
| 855 | |
| 856 | result->def = -1; |
| 857 | result->defmgmt = -1; |
| 858 | |
| 859 | nla_for_each_nested(key, keys, rem) { |
| 860 | memset(&parse, 0, sizeof(parse)); |
| 861 | parse.idx = -1; |
| 862 | |
| 863 | err = nl80211_parse_key_new(key, &parse); |
| 864 | if (err) |
| 865 | goto error; |
| 866 | err = -EINVAL; |
| 867 | if (!parse.p.key) |
| 868 | goto error; |
| 869 | if (parse.idx < 0 || parse.idx > 4) |
| 870 | goto error; |
| 871 | if (parse.def) { |
| 872 | if (def) |
| 873 | goto error; |
| 874 | def = 1; |
| 875 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 876 | if (!parse.def_uni || !parse.def_multi) |
| 877 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | } else if (parse.defmgmt) |
| 879 | goto error; |
| 880 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 881 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 882 | if (err) |
| 883 | goto error; |
| 884 | result->params[parse.idx].cipher = parse.p.cipher; |
| 885 | result->params[parse.idx].key_len = parse.p.key_len; |
| 886 | result->params[parse.idx].key = result->data[parse.idx]; |
| 887 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 888 | |
| 889 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 890 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 891 | if (no_ht) |
| 892 | *no_ht = true; |
| 893 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | return result; |
| 897 | error: |
| 898 | kfree(result); |
| 899 | return ERR_PTR(err); |
| 900 | } |
| 901 | |
| 902 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 903 | { |
| 904 | ASSERT_WDEV_LOCK(wdev); |
| 905 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 906 | switch (wdev->iftype) { |
| 907 | case NL80211_IFTYPE_AP: |
| 908 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 909 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 910 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 911 | break; |
| 912 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 913 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 914 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 915 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 916 | return -ENOLINK; |
| 917 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 918 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 919 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 920 | case NL80211_IFTYPE_MONITOR: |
| 921 | case NL80211_IFTYPE_P2P_DEVICE: |
| 922 | case NL80211_IFTYPE_WDS: |
| 923 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 924 | return -EINVAL; |
| 925 | } |
| 926 | |
| 927 | return 0; |
| 928 | } |
| 929 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 930 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 931 | struct nlattr *tb) |
| 932 | { |
| 933 | struct ieee80211_channel *chan; |
| 934 | |
| 935 | if (tb == NULL) |
| 936 | return NULL; |
| 937 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 938 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 939 | return NULL; |
| 940 | return chan; |
| 941 | } |
| 942 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 943 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 944 | { |
| 945 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 946 | int i; |
| 947 | |
| 948 | if (!nl_modes) |
| 949 | goto nla_put_failure; |
| 950 | |
| 951 | i = 0; |
| 952 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 953 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 954 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 955 | ifmodes >>= 1; |
| 956 | i++; |
| 957 | } |
| 958 | |
| 959 | nla_nest_end(msg, nl_modes); |
| 960 | return 0; |
| 961 | |
| 962 | nla_put_failure: |
| 963 | return -ENOBUFS; |
| 964 | } |
| 965 | |
| 966 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 967 | struct sk_buff *msg, |
| 968 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 969 | { |
| 970 | struct nlattr *nl_combis; |
| 971 | int i, j; |
| 972 | |
| 973 | nl_combis = nla_nest_start(msg, |
| 974 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 975 | if (!nl_combis) |
| 976 | goto nla_put_failure; |
| 977 | |
| 978 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 979 | const struct ieee80211_iface_combination *c; |
| 980 | struct nlattr *nl_combi, *nl_limits; |
| 981 | |
| 982 | c = &wiphy->iface_combinations[i]; |
| 983 | |
| 984 | nl_combi = nla_nest_start(msg, i + 1); |
| 985 | if (!nl_combi) |
| 986 | goto nla_put_failure; |
| 987 | |
| 988 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 989 | if (!nl_limits) |
| 990 | goto nla_put_failure; |
| 991 | |
| 992 | for (j = 0; j < c->n_limits; j++) { |
| 993 | struct nlattr *nl_limit; |
| 994 | |
| 995 | nl_limit = nla_nest_start(msg, j + 1); |
| 996 | if (!nl_limit) |
| 997 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 998 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 999 | c->limits[j].max)) |
| 1000 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1001 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1002 | c->limits[j].types)) |
| 1003 | goto nla_put_failure; |
| 1004 | nla_nest_end(msg, nl_limit); |
| 1005 | } |
| 1006 | |
| 1007 | nla_nest_end(msg, nl_limits); |
| 1008 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1009 | if (c->beacon_int_infra_match && |
| 1010 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1011 | goto nla_put_failure; |
| 1012 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1013 | c->num_different_channels) || |
| 1014 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1015 | c->max_interfaces)) |
| 1016 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1017 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1018 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1019 | c->radar_detect_widths) || |
| 1020 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1021 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1022 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1023 | |
| 1024 | nla_nest_end(msg, nl_combi); |
| 1025 | } |
| 1026 | |
| 1027 | nla_nest_end(msg, nl_combis); |
| 1028 | |
| 1029 | return 0; |
| 1030 | nla_put_failure: |
| 1031 | return -ENOBUFS; |
| 1032 | } |
| 1033 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1034 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1035 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1036 | struct sk_buff *msg) |
| 1037 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1038 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1039 | struct nlattr *nl_tcp; |
| 1040 | |
| 1041 | if (!tcp) |
| 1042 | return 0; |
| 1043 | |
| 1044 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1045 | if (!nl_tcp) |
| 1046 | return -ENOBUFS; |
| 1047 | |
| 1048 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1049 | tcp->data_payload_max)) |
| 1050 | return -ENOBUFS; |
| 1051 | |
| 1052 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1053 | tcp->data_payload_max)) |
| 1054 | return -ENOBUFS; |
| 1055 | |
| 1056 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1057 | return -ENOBUFS; |
| 1058 | |
| 1059 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1060 | sizeof(*tcp->tok), tcp->tok)) |
| 1061 | return -ENOBUFS; |
| 1062 | |
| 1063 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1064 | tcp->data_interval_max)) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1068 | tcp->wake_payload_max)) |
| 1069 | return -ENOBUFS; |
| 1070 | |
| 1071 | nla_nest_end(msg, nl_tcp); |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1076 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1077 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | { |
| 1079 | struct nlattr *nl_wowlan; |
| 1080 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1081 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1082 | return 0; |
| 1083 | |
| 1084 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1085 | if (!nl_wowlan) |
| 1086 | return -ENOBUFS; |
| 1087 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1088 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1089 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1090 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1091 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1092 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1093 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1094 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1095 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1096 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1097 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1098 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1099 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1100 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1101 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1102 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1103 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1104 | return -ENOBUFS; |
| 1105 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1106 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1107 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1108 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1109 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1110 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1111 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1112 | }; |
| 1113 | |
| 1114 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1115 | sizeof(pat), &pat)) |
| 1116 | return -ENOBUFS; |
| 1117 | } |
| 1118 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1119 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1120 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1121 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1122 | return -ENOBUFS; |
| 1123 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1124 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1125 | return -ENOBUFS; |
| 1126 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1127 | nla_nest_end(msg, nl_wowlan); |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | #endif |
| 1132 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1133 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1134 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1135 | { |
| 1136 | struct nl80211_coalesce_rule_support rule; |
| 1137 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1138 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1139 | return 0; |
| 1140 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1141 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1142 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1143 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1144 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1145 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1146 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1147 | |
| 1148 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1149 | return -ENOBUFS; |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1154 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1155 | struct ieee80211_supported_band *sband) |
| 1156 | { |
| 1157 | struct nlattr *nl_rates, *nl_rate; |
| 1158 | struct ieee80211_rate *rate; |
| 1159 | int i; |
| 1160 | |
| 1161 | /* add HT info */ |
| 1162 | if (sband->ht_cap.ht_supported && |
| 1163 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1164 | sizeof(sband->ht_cap.mcs), |
| 1165 | &sband->ht_cap.mcs) || |
| 1166 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1167 | sband->ht_cap.cap) || |
| 1168 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1169 | sband->ht_cap.ampdu_factor) || |
| 1170 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1171 | sband->ht_cap.ampdu_density))) |
| 1172 | return -ENOBUFS; |
| 1173 | |
| 1174 | /* add VHT info */ |
| 1175 | if (sband->vht_cap.vht_supported && |
| 1176 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1177 | sizeof(sband->vht_cap.vht_mcs), |
| 1178 | &sband->vht_cap.vht_mcs) || |
| 1179 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1180 | sband->vht_cap.cap))) |
| 1181 | return -ENOBUFS; |
| 1182 | |
| 1183 | /* add bitrates */ |
| 1184 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1185 | if (!nl_rates) |
| 1186 | return -ENOBUFS; |
| 1187 | |
| 1188 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1189 | nl_rate = nla_nest_start(msg, i); |
| 1190 | if (!nl_rate) |
| 1191 | return -ENOBUFS; |
| 1192 | |
| 1193 | rate = &sband->bitrates[i]; |
| 1194 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1195 | rate->bitrate)) |
| 1196 | return -ENOBUFS; |
| 1197 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1198 | nla_put_flag(msg, |
| 1199 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1200 | return -ENOBUFS; |
| 1201 | |
| 1202 | nla_nest_end(msg, nl_rate); |
| 1203 | } |
| 1204 | |
| 1205 | nla_nest_end(msg, nl_rates); |
| 1206 | |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | static int |
| 1211 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1212 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1213 | { |
| 1214 | u16 stypes; |
| 1215 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1216 | enum nl80211_iftype ift; |
| 1217 | int i; |
| 1218 | |
| 1219 | if (!mgmt_stypes) |
| 1220 | return 0; |
| 1221 | |
| 1222 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1223 | if (!nl_ifs) |
| 1224 | return -ENOBUFS; |
| 1225 | |
| 1226 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1227 | nl_ftypes = nla_nest_start(msg, ift); |
| 1228 | if (!nl_ftypes) |
| 1229 | return -ENOBUFS; |
| 1230 | i = 0; |
| 1231 | stypes = mgmt_stypes[ift].tx; |
| 1232 | while (stypes) { |
| 1233 | if ((stypes & 1) && |
| 1234 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1235 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1236 | return -ENOBUFS; |
| 1237 | stypes >>= 1; |
| 1238 | i++; |
| 1239 | } |
| 1240 | nla_nest_end(msg, nl_ftypes); |
| 1241 | } |
| 1242 | |
| 1243 | nla_nest_end(msg, nl_ifs); |
| 1244 | |
| 1245 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1246 | if (!nl_ifs) |
| 1247 | return -ENOBUFS; |
| 1248 | |
| 1249 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1250 | nl_ftypes = nla_nest_start(msg, ift); |
| 1251 | if (!nl_ftypes) |
| 1252 | return -ENOBUFS; |
| 1253 | i = 0; |
| 1254 | stypes = mgmt_stypes[ift].rx; |
| 1255 | while (stypes) { |
| 1256 | if ((stypes & 1) && |
| 1257 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1258 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1259 | return -ENOBUFS; |
| 1260 | stypes >>= 1; |
| 1261 | i++; |
| 1262 | } |
| 1263 | nla_nest_end(msg, nl_ftypes); |
| 1264 | } |
| 1265 | nla_nest_end(msg, nl_ifs); |
| 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1270 | struct nl80211_dump_wiphy_state { |
| 1271 | s64 filter_wiphy; |
| 1272 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1273 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1274 | bool split; |
| 1275 | }; |
| 1276 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1278 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1280 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1281 | { |
| 1282 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1283 | struct nlattr *nl_bands, *nl_band; |
| 1284 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1285 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1286 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1287 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1288 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1289 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1291 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1292 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1293 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | return -ENOBUFS; |
| 1296 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1297 | if (WARN_ON(!state)) |
| 1298 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1299 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1303 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1305 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1306 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1307 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1308 | goto finish; |
| 1309 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1310 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | case 0: |
| 1312 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1317 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1319 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1323 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1325 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1326 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1327 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1331 | rdev->wiphy.max_match_sets) || |
| 1332 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1333 | rdev->wiphy.max_sched_scan_plans) || |
| 1334 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1335 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1336 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1337 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1338 | goto nla_put_failure; |
| 1339 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1340 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1342 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1343 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1345 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1348 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1349 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1351 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1352 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1354 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1355 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1356 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1357 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | state->split_start++; |
| 1359 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | break; |
| 1361 | case 1: |
| 1362 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1363 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1364 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1365 | goto nla_put_failure; |
| 1366 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1369 | goto nla_put_failure; |
| 1370 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1373 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1374 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1376 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1378 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1379 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1380 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1381 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1383 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1385 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1386 | if ((rdev->wiphy.available_antennas_tx || |
| 1387 | rdev->wiphy.available_antennas_rx) && |
| 1388 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1389 | u32 tx_ant = 0, rx_ant = 0; |
| 1390 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1391 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1392 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | if (!res) { |
| 1394 | if (nla_put_u32(msg, |
| 1395 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1396 | tx_ant) || |
| 1397 | nla_put_u32(msg, |
| 1398 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1399 | rx_ant)) |
| 1400 | goto nla_put_failure; |
| 1401 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1404 | state->split_start++; |
| 1405 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | case 2: |
| 1408 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1409 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1411 | state->split_start++; |
| 1412 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | break; |
| 1414 | case 3: |
| 1415 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1416 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1417 | goto nla_put_failure; |
| 1418 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1419 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1420 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | struct ieee80211_supported_band *sband; |
| 1422 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1423 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | |
| 1425 | if (!sband) |
| 1426 | continue; |
| 1427 | |
| 1428 | nl_band = nla_nest_start(msg, band); |
| 1429 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | goto nla_put_failure; |
| 1431 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1432 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | case 0: |
| 1434 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1435 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | state->chan_start++; |
| 1437 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | break; |
| 1439 | default: |
| 1440 | /* add frequencies */ |
| 1441 | nl_freqs = nla_nest_start( |
| 1442 | msg, NL80211_BAND_ATTR_FREQS); |
| 1443 | if (!nl_freqs) |
| 1444 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1445 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1446 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | i < sband->n_channels; |
| 1448 | i++) { |
| 1449 | nl_freq = nla_nest_start(msg, i); |
| 1450 | if (!nl_freq) |
| 1451 | goto nla_put_failure; |
| 1452 | |
| 1453 | chan = &sband->channels[i]; |
| 1454 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | if (nl80211_msg_put_channel( |
| 1456 | msg, chan, |
| 1457 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | goto nla_put_failure; |
| 1459 | |
| 1460 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1461 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1465 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1467 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | nla_nest_end(msg, nl_freqs); |
| 1469 | } |
| 1470 | |
| 1471 | nla_nest_end(msg, nl_band); |
| 1472 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1473 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1475 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | band--; |
| 1477 | break; |
| 1478 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1479 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1481 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1482 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1483 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1485 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1486 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1488 | if (state->band_start == 0 && state->chan_start == 0) |
| 1489 | state->split_start++; |
| 1490 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | break; |
| 1492 | case 4: |
| 1493 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1494 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1495 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | |
| 1497 | i = 0; |
| 1498 | #define CMD(op, n) \ |
| 1499 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1500 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | i++; \ |
| 1502 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1503 | goto nla_put_failure; \ |
| 1504 | } \ |
| 1505 | } while (0) |
| 1506 | |
| 1507 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1508 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1509 | CMD(add_key, NEW_KEY); |
| 1510 | CMD(start_ap, START_AP); |
| 1511 | CMD(add_station, NEW_STATION); |
| 1512 | CMD(add_mpath, NEW_MPATH); |
| 1513 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1514 | CMD(change_bss, SET_BSS); |
| 1515 | CMD(auth, AUTHENTICATE); |
| 1516 | CMD(assoc, ASSOCIATE); |
| 1517 | CMD(deauth, DEAUTHENTICATE); |
| 1518 | CMD(disassoc, DISASSOCIATE); |
| 1519 | CMD(join_ibss, JOIN_IBSS); |
| 1520 | CMD(join_mesh, JOIN_MESH); |
| 1521 | CMD(set_pmksa, SET_PMKSA); |
| 1522 | CMD(del_pmksa, DEL_PMKSA); |
| 1523 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1526 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1527 | CMD(mgmt_tx, FRAME); |
| 1528 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | i++; |
| 1531 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1532 | goto nla_put_failure; |
| 1533 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1535 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | i++; |
| 1537 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1538 | goto nla_put_failure; |
| 1539 | } |
| 1540 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1541 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1543 | CMD(tdls_oper, TDLS_OPER); |
| 1544 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1545 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1547 | CMD(probe_client, PROBE_CLIENT); |
| 1548 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1549 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | i++; |
| 1551 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1552 | goto nla_put_failure; |
| 1553 | } |
| 1554 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1555 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1556 | #ifdef CONFIG_NL80211_TESTMODE |
| 1557 | CMD(testmode_cmd, TESTMODE); |
| 1558 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1560 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1561 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1562 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1563 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1564 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1565 | if (rdev->wiphy.features & |
| 1566 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1567 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1568 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1569 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1570 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1571 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1572 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | i++; |
| 1574 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1575 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1576 | } |
| 1577 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1579 | i++; |
| 1580 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1581 | goto nla_put_failure; |
| 1582 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1583 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1585 | state->split_start++; |
| 1586 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | break; |
| 1588 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | if (rdev->ops->remain_on_channel && |
| 1590 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | nla_put_u32(msg, |
| 1592 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1594 | goto nla_put_failure; |
| 1595 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1596 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1598 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1599 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1601 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1602 | state->split_start++; |
| 1603 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | break; |
| 1605 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1606 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1609 | state->split_start++; |
| 1610 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1611 | break; |
| 1612 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1613 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | #endif |
| 1615 | case 7: |
| 1616 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1617 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1618 | goto nla_put_failure; |
| 1619 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1620 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1623 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1624 | state->split_start++; |
| 1625 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1626 | break; |
| 1627 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1628 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1630 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1631 | goto nla_put_failure; |
| 1632 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1634 | /* |
| 1635 | * We can only add the per-channel limit information if the |
| 1636 | * dump is split, otherwise it makes it too big. Therefore |
| 1637 | * only advertise it in that case. |
| 1638 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1640 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1641 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1642 | goto nla_put_failure; |
| 1643 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1644 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1647 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | goto nla_put_failure; |
| 1649 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1650 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1651 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1653 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1654 | goto nla_put_failure; |
| 1655 | |
| 1656 | /* |
| 1657 | * Any information below this point is only available to |
| 1658 | * applications that can deal with it being split. This |
| 1659 | * helps ensure that newly added capabilities don't break |
| 1660 | * older tools by overrunning their buffers. |
| 1661 | * |
| 1662 | * We still increment split_start so that in the split |
| 1663 | * case we'll continue with more data in the next round, |
| 1664 | * but break unconditionally so unsplit data stops here. |
| 1665 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1666 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1667 | break; |
| 1668 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1669 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1670 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | rdev->wiphy.extended_capabilities_len, |
| 1672 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1673 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1674 | rdev->wiphy.extended_capabilities_len, |
| 1675 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1676 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1677 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1678 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1679 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1680 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1681 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1682 | goto nla_put_failure; |
| 1683 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1684 | state->split_start++; |
| 1685 | break; |
| 1686 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1687 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1688 | goto nla_put_failure; |
| 1689 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1691 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1692 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1693 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1694 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1695 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1696 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1697 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1698 | goto nla_put_failure; |
| 1699 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1700 | state->split_start++; |
| 1701 | break; |
| 1702 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1704 | const struct nl80211_vendor_cmd_info *info; |
| 1705 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1706 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1707 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1708 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1709 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1710 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1711 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1712 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1713 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1714 | goto nla_put_failure; |
| 1715 | } |
| 1716 | nla_nest_end(msg, nested); |
| 1717 | } |
| 1718 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1720 | const struct nl80211_vendor_cmd_info *info; |
| 1721 | struct nlattr *nested; |
| 1722 | |
| 1723 | nested = nla_nest_start(msg, |
| 1724 | NL80211_ATTR_VENDOR_EVENTS); |
| 1725 | if (!nested) |
| 1726 | goto nla_put_failure; |
| 1727 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1728 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1729 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1730 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1731 | goto nla_put_failure; |
| 1732 | } |
| 1733 | nla_nest_end(msg, nested); |
| 1734 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1735 | state->split_start++; |
| 1736 | break; |
| 1737 | case 12: |
| 1738 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1739 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1740 | rdev->wiphy.max_num_csa_counters)) |
| 1741 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1742 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1743 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1744 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1745 | goto nla_put_failure; |
| 1746 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1747 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1748 | sizeof(rdev->wiphy.ext_features), |
| 1749 | rdev->wiphy.ext_features)) |
| 1750 | goto nla_put_failure; |
| 1751 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1752 | if (rdev->wiphy.bss_select_support) { |
| 1753 | struct nlattr *nested; |
| 1754 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1755 | |
| 1756 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1757 | if (!nested) |
| 1758 | goto nla_put_failure; |
| 1759 | |
| 1760 | i = 0; |
| 1761 | while (bss_select_support) { |
| 1762 | if ((bss_select_support & 1) && |
| 1763 | nla_put_flag(msg, i)) |
| 1764 | goto nla_put_failure; |
| 1765 | i++; |
| 1766 | bss_select_support >>= 1; |
| 1767 | } |
| 1768 | nla_nest_end(msg, nested); |
| 1769 | } |
| 1770 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1771 | state->split_start++; |
| 1772 | break; |
| 1773 | case 13: |
| 1774 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1775 | rdev->wiphy.iftype_ext_capab) { |
| 1776 | struct nlattr *nested_ext_capab, *nested; |
| 1777 | |
| 1778 | nested = nla_nest_start(msg, |
| 1779 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1780 | if (!nested) |
| 1781 | goto nla_put_failure; |
| 1782 | |
| 1783 | for (i = state->capa_start; |
| 1784 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1785 | const struct wiphy_iftype_ext_capab *capab; |
| 1786 | |
| 1787 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1788 | |
| 1789 | nested_ext_capab = nla_nest_start(msg, i); |
| 1790 | if (!nested_ext_capab || |
| 1791 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1792 | capab->iftype) || |
| 1793 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1794 | capab->extended_capabilities_len, |
| 1795 | capab->extended_capabilities) || |
| 1796 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1797 | capab->extended_capabilities_len, |
| 1798 | capab->extended_capabilities_mask)) |
| 1799 | goto nla_put_failure; |
| 1800 | |
| 1801 | nla_nest_end(msg, nested_ext_capab); |
| 1802 | if (state->split) |
| 1803 | break; |
| 1804 | } |
| 1805 | nla_nest_end(msg, nested); |
| 1806 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1807 | state->capa_start = i + 1; |
| 1808 | break; |
| 1809 | } |
| 1810 | } |
| 1811 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1812 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1813 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1815 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1816 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1817 | genlmsg_end(msg, hdr); |
| 1818 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | |
| 1820 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1821 | genlmsg_cancel(msg, hdr); |
| 1822 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1825 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1826 | struct netlink_callback *cb, |
| 1827 | struct nl80211_dump_wiphy_state *state) |
| 1828 | { |
| 1829 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1830 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1831 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1832 | /* ignore parse errors for backward compatibility */ |
| 1833 | if (ret) |
| 1834 | return 0; |
| 1835 | |
| 1836 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1837 | if (tb[NL80211_ATTR_WIPHY]) |
| 1838 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1839 | if (tb[NL80211_ATTR_WDEV]) |
| 1840 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1841 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1842 | struct net_device *netdev; |
| 1843 | struct cfg80211_registered_device *rdev; |
| 1844 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1845 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1846 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1847 | if (!netdev) |
| 1848 | return -ENODEV; |
| 1849 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1850 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1851 | netdev->ieee80211_ptr->wiphy); |
| 1852 | state->filter_wiphy = rdev->wiphy_idx; |
| 1853 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1859 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1860 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1861 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1862 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1863 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1864 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1865 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1866 | if (!state) { |
| 1867 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1868 | if (!state) { |
| 1869 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1870 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1871 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1872 | state->filter_wiphy = -1; |
| 1873 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1874 | if (ret) { |
| 1875 | kfree(state); |
| 1876 | rtnl_unlock(); |
| 1877 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1878 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1879 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1882 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1883 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1884 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1885 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1886 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1887 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1888 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1889 | continue; |
| 1890 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1891 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1892 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1893 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1894 | NETLINK_CB(cb->skb).portid, |
| 1895 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1896 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1897 | if (ret < 0) { |
| 1898 | /* |
| 1899 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1900 | * or EMSGSIZE returned), this SKB is still |
| 1901 | * empty (so it's not too big because another |
| 1902 | * wiphy dataset is already in the skb) and |
| 1903 | * we've not tried to adjust the dump allocation |
| 1904 | * yet ... then adjust the alloc size to be |
| 1905 | * bigger, and return 1 but with the empty skb. |
| 1906 | * This results in an empty message being RX'ed |
| 1907 | * in userspace, but that is ignored. |
| 1908 | * |
| 1909 | * We can then retry with the larger buffer. |
| 1910 | */ |
| 1911 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1912 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1913 | cb->min_dump_alloc < 4096) { |
| 1914 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1915 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1916 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1917 | return 1; |
| 1918 | } |
| 1919 | idx--; |
| 1920 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1921 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1922 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1923 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1924 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1925 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1926 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1927 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | |
| 1929 | return skb->len; |
| 1930 | } |
| 1931 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1932 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1933 | { |
| 1934 | kfree((void *)cb->args[0]); |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1938 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1939 | { |
| 1940 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1942 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1943 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1944 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1945 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1946 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1947 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1948 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1949 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1950 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1951 | nlmsg_free(msg); |
| 1952 | return -ENOBUFS; |
| 1953 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1955 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1956 | } |
| 1957 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1958 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1959 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1960 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1961 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1962 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1963 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1964 | }; |
| 1965 | |
| 1966 | static int parse_txq_params(struct nlattr *tb[], |
| 1967 | struct ieee80211_txq_params *txq_params) |
| 1968 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1969 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1970 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1971 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1972 | return -EINVAL; |
| 1973 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1974 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1975 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1976 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1977 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1978 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1979 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1980 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1981 | return -EINVAL; |
| 1982 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1983 | return 0; |
| 1984 | } |
| 1985 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1986 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1987 | { |
| 1988 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1989 | * You can only set the channel explicitly for WDS interfaces, |
| 1990 | * all others have their channel managed via their respective |
| 1991 | * "establish a connection" command (connect, join, ...) |
| 1992 | * |
| 1993 | * For AP/GO and mesh mode, the channel can be set with the |
| 1994 | * channel userspace API, but is only stored and passed to the |
| 1995 | * low-level driver when the AP starts or the mesh is joined. |
| 1996 | * This is for backward compatibility, userspace can also give |
| 1997 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1998 | * |
| 1999 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2000 | * whatever else is going on, so they have their own special |
| 2001 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | */ |
| 2003 | return !wdev || |
| 2004 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2005 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2006 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2007 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2010 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2011 | struct genl_info *info, |
| 2012 | struct cfg80211_chan_def *chandef) |
| 2013 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2014 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2015 | |
| 2016 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2017 | return -EINVAL; |
| 2018 | |
| 2019 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2020 | |
| 2021 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2022 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2023 | chandef->center_freq1 = control_freq; |
| 2024 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2025 | |
| 2026 | /* Primary channel not allowed */ |
| 2027 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2028 | return -EINVAL; |
| 2029 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2030 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2031 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2032 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2033 | chantype = nla_get_u32( |
| 2034 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2035 | |
| 2036 | switch (chantype) { |
| 2037 | case NL80211_CHAN_NO_HT: |
| 2038 | case NL80211_CHAN_HT20: |
| 2039 | case NL80211_CHAN_HT40PLUS: |
| 2040 | case NL80211_CHAN_HT40MINUS: |
| 2041 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2042 | chantype); |
| 2043 | break; |
| 2044 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2045 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2046 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2047 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2048 | chandef->width = |
| 2049 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2050 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2051 | chandef->center_freq1 = |
| 2052 | nla_get_u32( |
| 2053 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2054 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2055 | chandef->center_freq2 = |
| 2056 | nla_get_u32( |
| 2057 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2058 | } |
| 2059 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2060 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2061 | return -EINVAL; |
| 2062 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2063 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2064 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2065 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2066 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2067 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2068 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2069 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2070 | return -EINVAL; |
| 2071 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2072 | return 0; |
| 2073 | } |
| 2074 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2075 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2076 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2077 | struct genl_info *info) |
| 2078 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2079 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2080 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2081 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2082 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2083 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2084 | if (dev) |
| 2085 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2086 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2087 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2088 | if (wdev) |
| 2089 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2090 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2091 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2092 | if (result) |
| 2093 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2094 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2095 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2096 | case NL80211_IFTYPE_AP: |
| 2097 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2098 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2099 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2100 | result = -EINVAL; |
| 2101 | break; |
| 2102 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2103 | if (wdev->beacon_interval) { |
| 2104 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2105 | !(rdev->wiphy.features & |
| 2106 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2107 | result = -EBUSY; |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | /* Only allow dynamic channel width changes */ |
| 2112 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2113 | result = -EBUSY; |
| 2114 | break; |
| 2115 | } |
| 2116 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2117 | if (result) |
| 2118 | break; |
| 2119 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2120 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2121 | result = 0; |
| 2122 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2123 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2124 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2125 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2126 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2127 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2128 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2129 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2130 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2131 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2132 | |
| 2133 | return result; |
| 2134 | } |
| 2135 | |
| 2136 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2139 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2140 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2141 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2142 | } |
| 2143 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2144 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2145 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2147 | struct net_device *dev = info->user_ptr[1]; |
| 2148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2149 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2150 | |
| 2151 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2152 | return -EINVAL; |
| 2153 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2154 | if (netif_running(dev)) |
| 2155 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2156 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2157 | if (!rdev->ops->set_wds_peer) |
| 2158 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2159 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2160 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2161 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2162 | |
| 2163 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2164 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2167 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2168 | { |
| 2169 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2170 | struct net_device *netdev = NULL; |
| 2171 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2172 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2173 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2174 | u32 changed; |
| 2175 | u8 retry_short = 0, retry_long = 0; |
| 2176 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2177 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2178 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2179 | ASSERT_RTNL(); |
| 2180 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2181 | /* |
| 2182 | * Try to find the wiphy and netdev. Normally this |
| 2183 | * function shouldn't need the netdev, but this is |
| 2184 | * done for backward compatibility -- previously |
| 2185 | * setting the channel was done per wiphy, but now |
| 2186 | * it is per netdev. Previous userland like hostapd |
| 2187 | * also passed a netdev to set_wiphy, so that it is |
| 2188 | * possible to let that go to the right netdev! |
| 2189 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2190 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2191 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2192 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2193 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2194 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2195 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2196 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2197 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2198 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2201 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2202 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2203 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2204 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2205 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2206 | wdev = NULL; |
| 2207 | netdev = NULL; |
| 2208 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2209 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2210 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2211 | |
| 2212 | /* |
| 2213 | * end workaround code, by now the rdev is available |
| 2214 | * and locked, and wdev may or may not be NULL. |
| 2215 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2216 | |
| 2217 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2218 | result = cfg80211_dev_rename( |
| 2219 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2220 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2221 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2222 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2223 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2224 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2225 | struct ieee80211_txq_params txq_params; |
| 2226 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2227 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2228 | if (!rdev->ops->set_txq_params) |
| 2229 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2230 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2231 | if (!netdev) |
| 2232 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2233 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2234 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2235 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2236 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2237 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2238 | if (!netif_running(netdev)) |
| 2239 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2240 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2241 | nla_for_each_nested(nl_txq_params, |
| 2242 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2243 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2244 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2245 | nla_data(nl_txq_params), |
| 2246 | nla_len(nl_txq_params), |
| 2247 | txq_params_policy); |
| 2248 | if (result) |
| 2249 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2250 | result = parse_txq_params(tb, &txq_params); |
| 2251 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2252 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2253 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2254 | result = rdev_set_txq_params(rdev, netdev, |
| 2255 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2256 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2257 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2261 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2262 | result = __nl80211_set_channel( |
| 2263 | rdev, |
| 2264 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2265 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2266 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2267 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2268 | } |
| 2269 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2270 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2271 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2272 | enum nl80211_tx_power_setting type; |
| 2273 | int idx, mbm = 0; |
| 2274 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2275 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2276 | txp_wdev = NULL; |
| 2277 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2278 | if (!rdev->ops->set_tx_power) |
| 2279 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2280 | |
| 2281 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2282 | type = nla_get_u32(info->attrs[idx]); |
| 2283 | |
| 2284 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2285 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2286 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2287 | |
| 2288 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2289 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2290 | mbm = nla_get_u32(info->attrs[idx]); |
| 2291 | } |
| 2292 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2293 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2294 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2295 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2296 | } |
| 2297 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2298 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2299 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2300 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2301 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2302 | if ((!rdev->wiphy.available_antennas_tx && |
| 2303 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2304 | !rdev->ops->set_antenna) |
| 2305 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2306 | |
| 2307 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2308 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2309 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2310 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2311 | * available antenna masks, except for the "all" mask */ |
| 2312 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2313 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2314 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2315 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2316 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2317 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2318 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2319 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2320 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2321 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2322 | } |
| 2323 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2324 | changed = 0; |
| 2325 | |
| 2326 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2327 | retry_short = nla_get_u8( |
| 2328 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | if (retry_short == 0) |
| 2330 | return -EINVAL; |
| 2331 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2332 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2333 | } |
| 2334 | |
| 2335 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2336 | retry_long = nla_get_u8( |
| 2337 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2338 | if (retry_long == 0) |
| 2339 | return -EINVAL; |
| 2340 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2341 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2342 | } |
| 2343 | |
| 2344 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2345 | frag_threshold = nla_get_u32( |
| 2346 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2347 | if (frag_threshold < 256) |
| 2348 | return -EINVAL; |
| 2349 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2350 | if (frag_threshold != (u32) -1) { |
| 2351 | /* |
| 2352 | * Fragments (apart from the last one) are required to |
| 2353 | * have even length. Make the fragmentation code |
| 2354 | * simpler by stripping LSB should someone try to use |
| 2355 | * odd threshold value. |
| 2356 | */ |
| 2357 | frag_threshold &= ~0x1; |
| 2358 | } |
| 2359 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2360 | } |
| 2361 | |
| 2362 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2363 | rts_threshold = nla_get_u32( |
| 2364 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2365 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2366 | } |
| 2367 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2368 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2369 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2370 | return -EINVAL; |
| 2371 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2372 | coverage_class = nla_get_u8( |
| 2373 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2374 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2375 | } |
| 2376 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2377 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2378 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2379 | return -EOPNOTSUPP; |
| 2380 | |
| 2381 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2382 | } |
| 2383 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2384 | if (changed) { |
| 2385 | u8 old_retry_short, old_retry_long; |
| 2386 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2387 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2388 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2389 | if (!rdev->ops->set_wiphy_params) |
| 2390 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2391 | |
| 2392 | old_retry_short = rdev->wiphy.retry_short; |
| 2393 | old_retry_long = rdev->wiphy.retry_long; |
| 2394 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2395 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2396 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2397 | |
| 2398 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2399 | rdev->wiphy.retry_short = retry_short; |
| 2400 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2401 | rdev->wiphy.retry_long = retry_long; |
| 2402 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2403 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2404 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2405 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2406 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2407 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2408 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2409 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2410 | if (result) { |
| 2411 | rdev->wiphy.retry_short = old_retry_short; |
| 2412 | rdev->wiphy.retry_long = old_retry_long; |
| 2413 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2414 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2415 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2416 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2417 | } |
| 2418 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2419 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2422 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2423 | { |
| 2424 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2425 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2426 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2427 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2428 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2429 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2430 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2431 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2432 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2433 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2435 | chandef->chan->center_freq)) |
| 2436 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2437 | switch (chandef->width) { |
| 2438 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2439 | case NL80211_CHAN_WIDTH_20: |
| 2440 | case NL80211_CHAN_WIDTH_40: |
| 2441 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2442 | cfg80211_get_chandef_type(chandef))) |
| 2443 | return -ENOBUFS; |
| 2444 | break; |
| 2445 | default: |
| 2446 | break; |
| 2447 | } |
| 2448 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2449 | return -ENOBUFS; |
| 2450 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2451 | return -ENOBUFS; |
| 2452 | if (chandef->center_freq2 && |
| 2453 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2454 | return -ENOBUFS; |
| 2455 | return 0; |
| 2456 | } |
| 2457 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2458 | 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] | 2459 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2460 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2461 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2462 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2463 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2464 | void *hdr; |
| 2465 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2466 | if (removal) |
| 2467 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2468 | |
| 2469 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2470 | if (!hdr) |
| 2471 | return -1; |
| 2472 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2473 | if (dev && |
| 2474 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2475 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2476 | goto nla_put_failure; |
| 2477 | |
| 2478 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2479 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2480 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2481 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2482 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2483 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2484 | rdev->devlist_generation ^ |
| 2485 | (cfg80211_rdev_list_generation << 2))) |
| 2486 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2487 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2488 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2489 | int ret; |
| 2490 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2491 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2492 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2493 | if (ret == 0) { |
| 2494 | if (nl80211_send_chandef(msg, &chandef)) |
| 2495 | goto nla_put_failure; |
| 2496 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2497 | } |
| 2498 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2499 | if (rdev->ops->get_tx_power) { |
| 2500 | int dbm, ret; |
| 2501 | |
| 2502 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2503 | if (ret == 0 && |
| 2504 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2505 | DBM_TO_MBM(dbm))) |
| 2506 | goto nla_put_failure; |
| 2507 | } |
| 2508 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2509 | if (wdev->ssid_len) { |
| 2510 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2511 | goto nla_put_failure; |
| 2512 | } |
| 2513 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2514 | genlmsg_end(msg, hdr); |
| 2515 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | |
| 2517 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2518 | genlmsg_cancel(msg, hdr); |
| 2519 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2523 | { |
| 2524 | int wp_idx = 0; |
| 2525 | int if_idx = 0; |
| 2526 | int wp_start = cb->args[0]; |
| 2527 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2528 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2529 | struct wireless_dev *wdev; |
| 2530 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2531 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2532 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2533 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2534 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2535 | if (wp_idx < wp_start) { |
| 2536 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2537 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2538 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2539 | if_idx = 0; |
| 2540 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2541 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2542 | if (if_idx < if_start) { |
| 2543 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2544 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2545 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2546 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2547 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2548 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2549 | goto out; |
| 2550 | } |
| 2551 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2552 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2553 | |
| 2554 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2555 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2556 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2557 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2558 | |
| 2559 | cb->args[0] = wp_idx; |
| 2560 | cb->args[1] = if_idx; |
| 2561 | |
| 2562 | return skb->len; |
| 2563 | } |
| 2564 | |
| 2565 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2566 | { |
| 2567 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2569 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2570 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2572 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2574 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2575 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2576 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2577 | nlmsg_free(msg); |
| 2578 | return -ENOBUFS; |
| 2579 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2580 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2581 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2582 | } |
| 2583 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2584 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2585 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2586 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2587 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2588 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2589 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2590 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2594 | { |
| 2595 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2596 | int flag; |
| 2597 | |
| 2598 | *mntrflags = 0; |
| 2599 | |
| 2600 | if (!nla) |
| 2601 | return -EINVAL; |
| 2602 | |
| 2603 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2604 | nla, mntr_flags_policy)) |
| 2605 | return -EINVAL; |
| 2606 | |
| 2607 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2608 | if (flags[flag]) |
| 2609 | *mntrflags |= (1<<flag); |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2614 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2615 | struct net_device *netdev, u8 use_4addr, |
| 2616 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2617 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2618 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2619 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2620 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2621 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2622 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2623 | |
| 2624 | switch (iftype) { |
| 2625 | case NL80211_IFTYPE_AP_VLAN: |
| 2626 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2627 | return 0; |
| 2628 | break; |
| 2629 | case NL80211_IFTYPE_STATION: |
| 2630 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2631 | return 0; |
| 2632 | break; |
| 2633 | default: |
| 2634 | break; |
| 2635 | } |
| 2636 | |
| 2637 | return -EOPNOTSUPP; |
| 2638 | } |
| 2639 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2640 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2641 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2643 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2644 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2645 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2646 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2647 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2648 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2649 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2650 | memset(¶ms, 0, sizeof(params)); |
| 2651 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2652 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2653 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2654 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2655 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2656 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2657 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2658 | if (ntype > NL80211_IFTYPE_MAX) |
| 2659 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2660 | } |
| 2661 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2662 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2663 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2666 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2667 | if (netif_running(dev)) |
| 2668 | return -EBUSY; |
| 2669 | |
| 2670 | wdev_lock(wdev); |
| 2671 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2672 | IEEE80211_MAX_MESH_ID_LEN); |
| 2673 | wdev->mesh_id_up_len = |
| 2674 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2675 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2676 | wdev->mesh_id_up_len); |
| 2677 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2680 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2681 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2682 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2683 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2684 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2685 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2686 | } else { |
| 2687 | params.use_4addr = -1; |
| 2688 | } |
| 2689 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2690 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2692 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2693 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2694 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2695 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2696 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2697 | |
| 2698 | flags = &_flags; |
| 2699 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2700 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2701 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2702 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2703 | const u8 *mumimo_groups; |
| 2704 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2705 | |
| 2706 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2707 | return -EOPNOTSUPP; |
| 2708 | |
| 2709 | mumimo_groups = |
| 2710 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2711 | |
| 2712 | /* bits 0 and 63 are reserved and must be zero */ |
| 2713 | if ((mumimo_groups[0] & BIT(7)) || |
| 2714 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2715 | return -EINVAL; |
| 2716 | |
| 2717 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2718 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2719 | change = true; |
| 2720 | } |
| 2721 | |
| 2722 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2723 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2724 | |
| 2725 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2726 | return -EOPNOTSUPP; |
| 2727 | |
| 2728 | nla_memcpy(params.macaddr, |
| 2729 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2730 | ETH_ALEN); |
| 2731 | change = true; |
| 2732 | } |
| 2733 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2734 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2735 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2736 | return -EOPNOTSUPP; |
| 2737 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2738 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2739 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2740 | else |
| 2741 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2742 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2743 | if (!err && params.use_4addr != -1) |
| 2744 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2745 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2746 | return err; |
| 2747 | } |
| 2748 | |
| 2749 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2750 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2752 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2753 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2754 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2755 | int err; |
| 2756 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2757 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2758 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2759 | /* to avoid failing a new interface creation due to pending removal */ |
| 2760 | cfg80211_destroy_ifaces(rdev); |
| 2761 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2762 | memset(¶ms, 0, sizeof(params)); |
| 2763 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2764 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2765 | return -EINVAL; |
| 2766 | |
| 2767 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2768 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2769 | if (type > NL80211_IFTYPE_MAX) |
| 2770 | return -EINVAL; |
| 2771 | } |
| 2772 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2773 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2775 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2776 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2777 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2778 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2779 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2780 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2781 | ETH_ALEN); |
| 2782 | if (!is_valid_ether_addr(params.macaddr)) |
| 2783 | return -EADDRNOTAVAIL; |
| 2784 | } |
| 2785 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2786 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2787 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2788 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2789 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2790 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2791 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2792 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2793 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2794 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2795 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2796 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2797 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2798 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2799 | return -EOPNOTSUPP; |
| 2800 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2802 | if (!msg) |
| 2803 | return -ENOMEM; |
| 2804 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2805 | wdev = rdev_add_virtual_intf(rdev, |
| 2806 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2807 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2808 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2809 | if (WARN_ON(!wdev)) { |
| 2810 | nlmsg_free(msg); |
| 2811 | return -EPROTO; |
| 2812 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2813 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2814 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2815 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2816 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2817 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2818 | wdev->owner_nlportid = info->snd_portid; |
| 2819 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2820 | switch (type) { |
| 2821 | case NL80211_IFTYPE_MESH_POINT: |
| 2822 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2823 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2824 | wdev_lock(wdev); |
| 2825 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2826 | IEEE80211_MAX_MESH_ID_LEN); |
| 2827 | wdev->mesh_id_up_len = |
| 2828 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2829 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2830 | wdev->mesh_id_up_len); |
| 2831 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2832 | break; |
| 2833 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2834 | /* |
| 2835 | * P2P Device doesn't have a netdev, so doesn't go |
| 2836 | * through the netdev notifier and must be added here |
| 2837 | */ |
| 2838 | mutex_init(&wdev->mtx); |
| 2839 | INIT_LIST_HEAD(&wdev->event_list); |
| 2840 | spin_lock_init(&wdev->event_lock); |
| 2841 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2842 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2843 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2844 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2845 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2846 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2847 | break; |
| 2848 | default: |
| 2849 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2850 | } |
| 2851 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2852 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2853 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2854 | nlmsg_free(msg); |
| 2855 | return -ENOBUFS; |
| 2856 | } |
| 2857 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2858 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2859 | if (event) { |
| 2860 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2861 | rdev, wdev, false) < 0) { |
| 2862 | nlmsg_free(event); |
| 2863 | goto out; |
| 2864 | } |
| 2865 | |
| 2866 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2867 | event, 0, NL80211_MCGRP_CONFIG, |
| 2868 | GFP_KERNEL); |
| 2869 | } |
| 2870 | |
| 2871 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2872 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2876 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2878 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2879 | struct sk_buff *msg; |
| 2880 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2882 | if (!rdev->ops->del_virtual_intf) |
| 2883 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2884 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2886 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2887 | nlmsg_free(msg); |
| 2888 | msg = NULL; |
| 2889 | } |
| 2890 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2891 | /* |
| 2892 | * If we remove a wireless device without a netdev then clear |
| 2893 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2894 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2895 | * since the wdev has been freed, unlike with a netdev where |
| 2896 | * we need the dev_put() for the netdev to really be freed. |
| 2897 | */ |
| 2898 | if (!wdev->netdev) |
| 2899 | info->user_ptr[1] = NULL; |
| 2900 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2901 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2902 | if (status >= 0 && msg) |
| 2903 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2904 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2905 | GFP_KERNEL); |
| 2906 | else |
| 2907 | nlmsg_free(msg); |
| 2908 | |
| 2909 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2910 | } |
| 2911 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2912 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2913 | { |
| 2914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2915 | struct net_device *dev = info->user_ptr[1]; |
| 2916 | u16 noack_map; |
| 2917 | |
| 2918 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2919 | return -EINVAL; |
| 2920 | |
| 2921 | if (!rdev->ops->set_noack_map) |
| 2922 | return -EOPNOTSUPP; |
| 2923 | |
| 2924 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2925 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2926 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | struct get_key_cookie { |
| 2930 | struct sk_buff *msg; |
| 2931 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2932 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2933 | }; |
| 2934 | |
| 2935 | static void get_key_callback(void *c, struct key_params *params) |
| 2936 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2937 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2938 | struct get_key_cookie *cookie = c; |
| 2939 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2940 | if ((params->key && |
| 2941 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2942 | params->key_len, params->key)) || |
| 2943 | (params->seq && |
| 2944 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2945 | params->seq_len, params->seq)) || |
| 2946 | (params->cipher && |
| 2947 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2948 | params->cipher))) |
| 2949 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2950 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2951 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2952 | if (!key) |
| 2953 | goto nla_put_failure; |
| 2954 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2955 | if ((params->key && |
| 2956 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2957 | params->key_len, params->key)) || |
| 2958 | (params->seq && |
| 2959 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2960 | params->seq_len, params->seq)) || |
| 2961 | (params->cipher && |
| 2962 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2963 | params->cipher))) |
| 2964 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2965 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2966 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2967 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2968 | |
| 2969 | nla_nest_end(cookie->msg, key); |
| 2970 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2971 | return; |
| 2972 | nla_put_failure: |
| 2973 | cookie->error = 1; |
| 2974 | } |
| 2975 | |
| 2976 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2977 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2979 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2980 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2981 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2982 | const u8 *mac_addr = NULL; |
| 2983 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2984 | struct get_key_cookie cookie = { |
| 2985 | .error = 0, |
| 2986 | }; |
| 2987 | void *hdr; |
| 2988 | struct sk_buff *msg; |
| 2989 | |
| 2990 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2991 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2992 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2993 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2994 | return -EINVAL; |
| 2995 | |
| 2996 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2997 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2998 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2999 | pairwise = !!mac_addr; |
| 3000 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3001 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3002 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3003 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3004 | return -EINVAL; |
| 3005 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3006 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3007 | return -EINVAL; |
| 3008 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3009 | } |
| 3010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3011 | if (!rdev->ops->get_key) |
| 3012 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3013 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3014 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3015 | return -ENOENT; |
| 3016 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3017 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3018 | if (!msg) |
| 3019 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3020 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3021 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3022 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3023 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3024 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3025 | |
| 3026 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3027 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3028 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3029 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3030 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3031 | goto nla_put_failure; |
| 3032 | if (mac_addr && |
| 3033 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3034 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3035 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3036 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3037 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 | |
| 3039 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3040 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3041 | |
| 3042 | if (cookie.error) |
| 3043 | goto nla_put_failure; |
| 3044 | |
| 3045 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3046 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3047 | |
| 3048 | nla_put_failure: |
| 3049 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3050 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3051 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3052 | return err; |
| 3053 | } |
| 3054 | |
| 3055 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3056 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3058 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3059 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3061 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3062 | err = nl80211_parse_key(info, &key); |
| 3063 | if (err) |
| 3064 | return err; |
| 3065 | |
| 3066 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3067 | return -EINVAL; |
| 3068 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3069 | /* only support setting default key */ |
| 3070 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3071 | return -EINVAL; |
| 3072 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3073 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3074 | |
| 3075 | if (key.def) { |
| 3076 | if (!rdev->ops->set_default_key) { |
| 3077 | err = -EOPNOTSUPP; |
| 3078 | goto out; |
| 3079 | } |
| 3080 | |
| 3081 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3082 | if (err) |
| 3083 | goto out; |
| 3084 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3085 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3086 | key.def_uni, key.def_multi); |
| 3087 | |
| 3088 | if (err) |
| 3089 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3090 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3091 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3092 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3093 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3094 | } else { |
| 3095 | if (key.def_uni || !key.def_multi) { |
| 3096 | err = -EINVAL; |
| 3097 | goto out; |
| 3098 | } |
| 3099 | |
| 3100 | if (!rdev->ops->set_default_mgmt_key) { |
| 3101 | err = -EOPNOTSUPP; |
| 3102 | goto out; |
| 3103 | } |
| 3104 | |
| 3105 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3106 | if (err) |
| 3107 | goto out; |
| 3108 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3109 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3110 | if (err) |
| 3111 | goto out; |
| 3112 | |
| 3113 | #ifdef CONFIG_CFG80211_WEXT |
| 3114 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3115 | #endif |
| 3116 | } |
| 3117 | |
| 3118 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3119 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3120 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3121 | return err; |
| 3122 | } |
| 3123 | |
| 3124 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3125 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3126 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3127 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3128 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3129 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3130 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3131 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3132 | err = nl80211_parse_key(info, &key); |
| 3133 | if (err) |
| 3134 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3135 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3136 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3137 | return -EINVAL; |
| 3138 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3139 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3140 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3141 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3142 | if (key.type == -1) { |
| 3143 | if (mac_addr) |
| 3144 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3145 | else |
| 3146 | key.type = NL80211_KEYTYPE_GROUP; |
| 3147 | } |
| 3148 | |
| 3149 | /* for now */ |
| 3150 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3151 | key.type != NL80211_KEYTYPE_GROUP) |
| 3152 | return -EINVAL; |
| 3153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3154 | if (!rdev->ops->add_key) |
| 3155 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3156 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3157 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3158 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3159 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3160 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3161 | |
| 3162 | wdev_lock(dev->ieee80211_ptr); |
| 3163 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3164 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3165 | err = rdev_add_key(rdev, dev, key.idx, |
| 3166 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3167 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3168 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3169 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3170 | return err; |
| 3171 | } |
| 3172 | |
| 3173 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3174 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3175 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3176 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3177 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3178 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3179 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3180 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3181 | err = nl80211_parse_key(info, &key); |
| 3182 | if (err) |
| 3183 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3184 | |
| 3185 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3186 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3187 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3188 | if (key.type == -1) { |
| 3189 | if (mac_addr) |
| 3190 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3191 | else |
| 3192 | key.type = NL80211_KEYTYPE_GROUP; |
| 3193 | } |
| 3194 | |
| 3195 | /* for now */ |
| 3196 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3197 | key.type != NL80211_KEYTYPE_GROUP) |
| 3198 | return -EINVAL; |
| 3199 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3200 | if (!rdev->ops->del_key) |
| 3201 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3202 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3203 | wdev_lock(dev->ieee80211_ptr); |
| 3204 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3205 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3206 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3207 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3208 | err = -ENOENT; |
| 3209 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3210 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3211 | err = rdev_del_key(rdev, dev, key.idx, |
| 3212 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3213 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3214 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3215 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3216 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3217 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3218 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3219 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3220 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3221 | } |
| 3222 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3223 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3224 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3225 | return err; |
| 3226 | } |
| 3227 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3228 | /* This function returns an error or the number of nested attributes */ |
| 3229 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3230 | { |
| 3231 | struct nlattr *attr; |
| 3232 | int n_entries = 0, tmp; |
| 3233 | |
| 3234 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3235 | if (nla_len(attr) != ETH_ALEN) |
| 3236 | return -EINVAL; |
| 3237 | |
| 3238 | n_entries++; |
| 3239 | } |
| 3240 | |
| 3241 | return n_entries; |
| 3242 | } |
| 3243 | |
| 3244 | /* |
| 3245 | * This function parses ACL information and allocates memory for ACL data. |
| 3246 | * On successful return, the calling function is responsible to free the |
| 3247 | * ACL buffer returned by this function. |
| 3248 | */ |
| 3249 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3250 | struct genl_info *info) |
| 3251 | { |
| 3252 | enum nl80211_acl_policy acl_policy; |
| 3253 | struct nlattr *attr; |
| 3254 | struct cfg80211_acl_data *acl; |
| 3255 | int i = 0, n_entries, tmp; |
| 3256 | |
| 3257 | if (!wiphy->max_acl_mac_addrs) |
| 3258 | return ERR_PTR(-EOPNOTSUPP); |
| 3259 | |
| 3260 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3261 | return ERR_PTR(-EINVAL); |
| 3262 | |
| 3263 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3264 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3265 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3266 | return ERR_PTR(-EINVAL); |
| 3267 | |
| 3268 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3269 | return ERR_PTR(-EINVAL); |
| 3270 | |
| 3271 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3272 | if (n_entries < 0) |
| 3273 | return ERR_PTR(n_entries); |
| 3274 | |
| 3275 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3276 | return ERR_PTR(-ENOTSUPP); |
| 3277 | |
| 3278 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3279 | GFP_KERNEL); |
| 3280 | if (!acl) |
| 3281 | return ERR_PTR(-ENOMEM); |
| 3282 | |
| 3283 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3284 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3285 | i++; |
| 3286 | } |
| 3287 | |
| 3288 | acl->n_acl_entries = n_entries; |
| 3289 | acl->acl_policy = acl_policy; |
| 3290 | |
| 3291 | return acl; |
| 3292 | } |
| 3293 | |
| 3294 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3295 | { |
| 3296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3297 | struct net_device *dev = info->user_ptr[1]; |
| 3298 | struct cfg80211_acl_data *acl; |
| 3299 | int err; |
| 3300 | |
| 3301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3303 | return -EOPNOTSUPP; |
| 3304 | |
| 3305 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3306 | return -EINVAL; |
| 3307 | |
| 3308 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3309 | if (IS_ERR(acl)) |
| 3310 | return PTR_ERR(acl); |
| 3311 | |
| 3312 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3313 | |
| 3314 | kfree(acl); |
| 3315 | |
| 3316 | return err; |
| 3317 | } |
| 3318 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3319 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3320 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3321 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3322 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3323 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3324 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3325 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3326 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3327 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3328 | return -EINVAL; |
| 3329 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3330 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3331 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3332 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3333 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3334 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3335 | if (!bcn->head_len) |
| 3336 | return -EINVAL; |
| 3337 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3338 | } |
| 3339 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3340 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3341 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3342 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3343 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3344 | } |
| 3345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3346 | if (!haveinfo) |
| 3347 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3348 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3349 | if (attrs[NL80211_ATTR_IE]) { |
| 3350 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3351 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3352 | } |
| 3353 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3354 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3355 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3356 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3357 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3358 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3359 | } |
| 3360 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3361 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3362 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3363 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3364 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3365 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3366 | } |
| 3367 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3368 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3369 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3370 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3371 | } |
| 3372 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3373 | return 0; |
| 3374 | } |
| 3375 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3376 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3377 | struct cfg80211_ap_settings *params) |
| 3378 | { |
| 3379 | struct wireless_dev *wdev; |
| 3380 | bool ret = false; |
| 3381 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3382 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3383 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3384 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3385 | continue; |
| 3386 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3387 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3388 | continue; |
| 3389 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3390 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3391 | ret = true; |
| 3392 | break; |
| 3393 | } |
| 3394 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3395 | return ret; |
| 3396 | } |
| 3397 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3398 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3399 | enum nl80211_auth_type auth_type, |
| 3400 | enum nl80211_commands cmd) |
| 3401 | { |
| 3402 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3403 | return false; |
| 3404 | |
| 3405 | switch (cmd) { |
| 3406 | case NL80211_CMD_AUTHENTICATE: |
| 3407 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3408 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3409 | return false; |
| 3410 | return true; |
| 3411 | case NL80211_CMD_CONNECT: |
| 3412 | case NL80211_CMD_START_AP: |
| 3413 | /* SAE not supported yet */ |
| 3414 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3415 | return false; |
| 3416 | return true; |
| 3417 | default: |
| 3418 | return false; |
| 3419 | } |
| 3420 | } |
| 3421 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3422 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3423 | { |
| 3424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3425 | struct net_device *dev = info->user_ptr[1]; |
| 3426 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3427 | struct cfg80211_ap_settings params; |
| 3428 | int err; |
| 3429 | |
| 3430 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3431 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3432 | return -EOPNOTSUPP; |
| 3433 | |
| 3434 | if (!rdev->ops->start_ap) |
| 3435 | return -EOPNOTSUPP; |
| 3436 | |
| 3437 | if (wdev->beacon_interval) |
| 3438 | return -EALREADY; |
| 3439 | |
| 3440 | memset(¶ms, 0, sizeof(params)); |
| 3441 | |
| 3442 | /* these are required for START_AP */ |
| 3443 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3444 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3445 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3446 | return -EINVAL; |
| 3447 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3448 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3449 | if (err) |
| 3450 | return err; |
| 3451 | |
| 3452 | params.beacon_interval = |
| 3453 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3454 | params.dtim_period = |
| 3455 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3456 | |
| 3457 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3458 | if (err) |
| 3459 | return err; |
| 3460 | |
| 3461 | /* |
| 3462 | * In theory, some of these attributes should be required here |
| 3463 | * but since they were not used when the command was originally |
| 3464 | * added, keep them optional for old user space programs to let |
| 3465 | * them continue to work with drivers that do not need the |
| 3466 | * additional information -- drivers must check! |
| 3467 | */ |
| 3468 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3469 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3470 | params.ssid_len = |
| 3471 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3472 | if (params.ssid_len == 0 || |
| 3473 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3474 | return -EINVAL; |
| 3475 | } |
| 3476 | |
| 3477 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3478 | params.hidden_ssid = nla_get_u32( |
| 3479 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3480 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3481 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3482 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3483 | return -EINVAL; |
| 3484 | } |
| 3485 | |
| 3486 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3487 | |
| 3488 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3489 | params.auth_type = nla_get_u32( |
| 3490 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3491 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3492 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3493 | return -EINVAL; |
| 3494 | } else |
| 3495 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3496 | |
| 3497 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3498 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3499 | if (err) |
| 3500 | return err; |
| 3501 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3502 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3503 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3504 | return -EOPNOTSUPP; |
| 3505 | params.inactivity_timeout = nla_get_u16( |
| 3506 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3507 | } |
| 3508 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3509 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3510 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3511 | return -EINVAL; |
| 3512 | params.p2p_ctwindow = |
| 3513 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3514 | if (params.p2p_ctwindow > 127) |
| 3515 | return -EINVAL; |
| 3516 | if (params.p2p_ctwindow != 0 && |
| 3517 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3518 | return -EINVAL; |
| 3519 | } |
| 3520 | |
| 3521 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3522 | u8 tmp; |
| 3523 | |
| 3524 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3525 | return -EINVAL; |
| 3526 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3527 | if (tmp > 1) |
| 3528 | return -EINVAL; |
| 3529 | params.p2p_opp_ps = tmp; |
| 3530 | if (params.p2p_opp_ps != 0 && |
| 3531 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3532 | return -EINVAL; |
| 3533 | } |
| 3534 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3535 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3536 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3537 | if (err) |
| 3538 | return err; |
| 3539 | } else if (wdev->preset_chandef.chan) { |
| 3540 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3541 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3542 | return -EINVAL; |
| 3543 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3544 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3545 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3546 | return -EINVAL; |
| 3547 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3548 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3549 | params.smps_mode = |
| 3550 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3551 | switch (params.smps_mode) { |
| 3552 | case NL80211_SMPS_OFF: |
| 3553 | break; |
| 3554 | case NL80211_SMPS_STATIC: |
| 3555 | if (!(rdev->wiphy.features & |
| 3556 | NL80211_FEATURE_STATIC_SMPS)) |
| 3557 | return -EINVAL; |
| 3558 | break; |
| 3559 | case NL80211_SMPS_DYNAMIC: |
| 3560 | if (!(rdev->wiphy.features & |
| 3561 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3562 | return -EINVAL; |
| 3563 | break; |
| 3564 | default: |
| 3565 | return -EINVAL; |
| 3566 | } |
| 3567 | } else { |
| 3568 | params.smps_mode = NL80211_SMPS_OFF; |
| 3569 | } |
| 3570 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3571 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3572 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3573 | return -EOPNOTSUPP; |
| 3574 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3575 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3576 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3577 | if (IS_ERR(params.acl)) |
| 3578 | return PTR_ERR(params.acl); |
| 3579 | } |
| 3580 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3581 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3582 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3583 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3584 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3585 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3586 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3587 | wdev->ssid_len = params.ssid_len; |
| 3588 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3589 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3590 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3591 | |
| 3592 | kfree(params.acl); |
| 3593 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3594 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3595 | } |
| 3596 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3597 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3598 | { |
| 3599 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3600 | struct net_device *dev = info->user_ptr[1]; |
| 3601 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3602 | struct cfg80211_beacon_data params; |
| 3603 | int err; |
| 3604 | |
| 3605 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3606 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3607 | return -EOPNOTSUPP; |
| 3608 | |
| 3609 | if (!rdev->ops->change_beacon) |
| 3610 | return -EOPNOTSUPP; |
| 3611 | |
| 3612 | if (!wdev->beacon_interval) |
| 3613 | return -EINVAL; |
| 3614 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3615 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3616 | if (err) |
| 3617 | return err; |
| 3618 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3619 | wdev_lock(wdev); |
| 3620 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3621 | wdev_unlock(wdev); |
| 3622 | |
| 3623 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | 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] | 3627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3629 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3630 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3631 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3632 | } |
| 3633 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3634 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3635 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3636 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3637 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3638 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3639 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3640 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3641 | }; |
| 3642 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3643 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3644 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3645 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3646 | { |
| 3647 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3648 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3649 | int flag; |
| 3650 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3651 | /* |
| 3652 | * Try parsing the new attribute first so userspace |
| 3653 | * can specify both for older kernels. |
| 3654 | */ |
| 3655 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3656 | if (nla) { |
| 3657 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3658 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3659 | sta_flags = nla_data(nla); |
| 3660 | params->sta_flags_mask = sta_flags->mask; |
| 3661 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3662 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3663 | if ((params->sta_flags_mask | |
| 3664 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3665 | return -EINVAL; |
| 3666 | return 0; |
| 3667 | } |
| 3668 | |
| 3669 | /* if present, parse the old attribute */ |
| 3670 | |
| 3671 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3672 | if (!nla) |
| 3673 | return 0; |
| 3674 | |
| 3675 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3676 | nla, sta_flags_policy)) |
| 3677 | return -EINVAL; |
| 3678 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3679 | /* |
| 3680 | * Only allow certain flags for interface types so that |
| 3681 | * other attributes are silently ignored. Remember that |
| 3682 | * this is backward compatibility code with old userspace |
| 3683 | * and shouldn't be hit in other cases anyway. |
| 3684 | */ |
| 3685 | switch (iftype) { |
| 3686 | case NL80211_IFTYPE_AP: |
| 3687 | case NL80211_IFTYPE_AP_VLAN: |
| 3688 | case NL80211_IFTYPE_P2P_GO: |
| 3689 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3690 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3691 | BIT(NL80211_STA_FLAG_WME) | |
| 3692 | BIT(NL80211_STA_FLAG_MFP); |
| 3693 | break; |
| 3694 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3695 | case NL80211_IFTYPE_STATION: |
| 3696 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3697 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3698 | break; |
| 3699 | case NL80211_IFTYPE_MESH_POINT: |
| 3700 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3701 | BIT(NL80211_STA_FLAG_MFP) | |
| 3702 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3703 | default: |
| 3704 | return -EINVAL; |
| 3705 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3706 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3707 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3708 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3709 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3710 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3711 | /* no longer support new API additions in old API */ |
| 3712 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3713 | return -EINVAL; |
| 3714 | } |
| 3715 | } |
| 3716 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3717 | return 0; |
| 3718 | } |
| 3719 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3720 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3721 | int attr) |
| 3722 | { |
| 3723 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3724 | u32 bitrate; |
| 3725 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3726 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3727 | |
| 3728 | rate = nla_nest_start(msg, attr); |
| 3729 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3730 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3731 | |
| 3732 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3733 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3734 | /* report 16-bit bitrate only if we can */ |
| 3735 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3736 | if (bitrate > 0 && |
| 3737 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3738 | return false; |
| 3739 | if (bitrate_compat > 0 && |
| 3740 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3741 | return false; |
| 3742 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3743 | switch (info->bw) { |
| 3744 | case RATE_INFO_BW_5: |
| 3745 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3746 | break; |
| 3747 | case RATE_INFO_BW_10: |
| 3748 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3749 | break; |
| 3750 | default: |
| 3751 | WARN_ON(1); |
| 3752 | /* fall through */ |
| 3753 | case RATE_INFO_BW_20: |
| 3754 | rate_flg = 0; |
| 3755 | break; |
| 3756 | case RATE_INFO_BW_40: |
| 3757 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3758 | break; |
| 3759 | case RATE_INFO_BW_80: |
| 3760 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3761 | break; |
| 3762 | case RATE_INFO_BW_160: |
| 3763 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3764 | break; |
| 3765 | } |
| 3766 | |
| 3767 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3768 | return false; |
| 3769 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3770 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3771 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3772 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3773 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3774 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3775 | return false; |
| 3776 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3777 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3778 | return false; |
| 3779 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3780 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3781 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3782 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3783 | return false; |
| 3784 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3785 | |
| 3786 | nla_nest_end(msg, rate); |
| 3787 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3788 | } |
| 3789 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3790 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3791 | int id) |
| 3792 | { |
| 3793 | void *attr; |
| 3794 | int i = 0; |
| 3795 | |
| 3796 | if (!mask) |
| 3797 | return true; |
| 3798 | |
| 3799 | attr = nla_nest_start(msg, id); |
| 3800 | if (!attr) |
| 3801 | return false; |
| 3802 | |
| 3803 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3804 | if (!(mask & BIT(i))) |
| 3805 | continue; |
| 3806 | |
| 3807 | if (nla_put_u8(msg, i, signal[i])) |
| 3808 | return false; |
| 3809 | } |
| 3810 | |
| 3811 | nla_nest_end(msg, attr); |
| 3812 | |
| 3813 | return true; |
| 3814 | } |
| 3815 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3816 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3817 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3818 | struct cfg80211_registered_device *rdev, |
| 3819 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3820 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3821 | { |
| 3822 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3823 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3824 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3825 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3826 | if (!hdr) |
| 3827 | return -1; |
| 3828 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3829 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3830 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3831 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3832 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3833 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3834 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3835 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3836 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3837 | |
| 3838 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3839 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 3840 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3841 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3842 | sinfo->memb)) \ |
| 3843 | goto nla_put_failure; \ |
| 3844 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3845 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 3846 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 3847 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 3848 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 3849 | goto nla_put_failure; \ |
| 3850 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3851 | |
| 3852 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3853 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3854 | |
| 3855 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3856 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3857 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3858 | (u32)sinfo->rx_bytes)) |
| 3859 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3860 | |
| 3861 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3862 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3863 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3864 | (u32)sinfo->tx_bytes)) |
| 3865 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3866 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3867 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 3868 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3869 | PUT_SINFO(LLID, llid, u16); |
| 3870 | PUT_SINFO(PLID, plid, u16); |
| 3871 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3872 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3873 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3874 | switch (rdev->wiphy.signal_type) { |
| 3875 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3876 | PUT_SINFO(SIGNAL, signal, u8); |
| 3877 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3878 | break; |
| 3879 | default: |
| 3880 | break; |
| 3881 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3882 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3883 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3884 | sinfo->chain_signal, |
| 3885 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3886 | goto nla_put_failure; |
| 3887 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3888 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3889 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3890 | sinfo->chain_signal_avg, |
| 3891 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3892 | goto nla_put_failure; |
| 3893 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3894 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3895 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3896 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3897 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3898 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3899 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3900 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3901 | NL80211_STA_INFO_RX_BITRATE)) |
| 3902 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3903 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3904 | |
| 3905 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3906 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3907 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3908 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3909 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3910 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3911 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3912 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3913 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3914 | |
| 3915 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3916 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3917 | if (!bss_param) |
| 3918 | goto nla_put_failure; |
| 3919 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3920 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3921 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3922 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3923 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3924 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3925 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3926 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3927 | sinfo->bss_param.dtim_period) || |
| 3928 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3929 | sinfo->bss_param.beacon_interval)) |
| 3930 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3931 | |
| 3932 | nla_nest_end(msg, bss_param); |
| 3933 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3934 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3935 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3936 | sizeof(struct nl80211_sta_flag_update), |
| 3937 | &sinfo->sta_flags)) |
| 3938 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3939 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3940 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 3941 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 3942 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3943 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3944 | |
| 3945 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3946 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3947 | |
| 3948 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3949 | struct nlattr *tidsattr; |
| 3950 | int tid; |
| 3951 | |
| 3952 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3953 | if (!tidsattr) |
| 3954 | goto nla_put_failure; |
| 3955 | |
| 3956 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3957 | struct cfg80211_tid_stats *tidstats; |
| 3958 | struct nlattr *tidattr; |
| 3959 | |
| 3960 | tidstats = &sinfo->pertid[tid]; |
| 3961 | |
| 3962 | if (!tidstats->filled) |
| 3963 | continue; |
| 3964 | |
| 3965 | tidattr = nla_nest_start(msg, tid + 1); |
| 3966 | if (!tidattr) |
| 3967 | goto nla_put_failure; |
| 3968 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3969 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3970 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3971 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 3972 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3973 | goto nla_put_failure; \ |
| 3974 | } while (0) |
| 3975 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3976 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 3977 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 3978 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 3979 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3980 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3981 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3982 | nla_nest_end(msg, tidattr); |
| 3983 | } |
| 3984 | |
| 3985 | nla_nest_end(msg, tidsattr); |
| 3986 | } |
| 3987 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3988 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3989 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3990 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3991 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3992 | sinfo->assoc_req_ies)) |
| 3993 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3994 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3995 | genlmsg_end(msg, hdr); |
| 3996 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3997 | |
| 3998 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3999 | genlmsg_cancel(msg, hdr); |
| 4000 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4001 | } |
| 4002 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4003 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4004 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4005 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4006 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4007 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4008 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4009 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4010 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4011 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4012 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4013 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4014 | if (err) |
| 4015 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4016 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4017 | if (!wdev->netdev) { |
| 4018 | err = -EINVAL; |
| 4019 | goto out_err; |
| 4020 | } |
| 4021 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4022 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4023 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4024 | goto out_err; |
| 4025 | } |
| 4026 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4027 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4028 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4029 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4030 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4031 | if (err == -ENOENT) |
| 4032 | break; |
| 4033 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4034 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4035 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4036 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4037 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4038 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4039 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4040 | &sinfo) < 0) |
| 4041 | goto out; |
| 4042 | |
| 4043 | sta_idx++; |
| 4044 | } |
| 4045 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4046 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4047 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4048 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4049 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4050 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4051 | |
| 4052 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4053 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4054 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4055 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4056 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4058 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4059 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4060 | struct sk_buff *msg; |
| 4061 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4062 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4063 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4064 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4065 | |
| 4066 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4067 | return -EINVAL; |
| 4068 | |
| 4069 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4071 | if (!rdev->ops->get_station) |
| 4072 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4073 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4074 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4075 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4076 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4077 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4078 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4079 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4080 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4081 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4082 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4083 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4084 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4085 | nlmsg_free(msg); |
| 4086 | return -ENOBUFS; |
| 4087 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4088 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4089 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4092 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4093 | struct station_parameters *params, |
| 4094 | enum cfg80211_station_type statype) |
| 4095 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4096 | if (params->listen_interval != -1 && |
| 4097 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4098 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4099 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4100 | if (params->support_p2p_ps != -1 && |
| 4101 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4102 | return -EINVAL; |
| 4103 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4104 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4105 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4106 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4107 | return -EINVAL; |
| 4108 | |
| 4109 | /* When you run into this, adjust the code below for the new flag */ |
| 4110 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4111 | |
| 4112 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4113 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4114 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4115 | /* |
| 4116 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4117 | * code doesn't have the bug of including TDLS in the |
| 4118 | * mask everywhere. |
| 4119 | */ |
| 4120 | if (params->sta_flags_mask & |
| 4121 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4122 | BIT(NL80211_STA_FLAG_MFP) | |
| 4123 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4124 | return -EINVAL; |
| 4125 | break; |
| 4126 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4127 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4128 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4129 | return -EINVAL; |
| 4130 | /* ignore since it can't change */ |
| 4131 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4132 | break; |
| 4133 | default: |
| 4134 | /* disallow mesh-specific things */ |
| 4135 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4136 | return -EINVAL; |
| 4137 | if (params->local_pm) |
| 4138 | return -EINVAL; |
| 4139 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4140 | return -EINVAL; |
| 4141 | } |
| 4142 | |
| 4143 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4144 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4145 | /* TDLS can't be set, ... */ |
| 4146 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4147 | return -EINVAL; |
| 4148 | /* |
| 4149 | * ... but don't bother the driver with it. This works around |
| 4150 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4151 | * TLDS_PEER flag in the mask even for AP mode. |
| 4152 | */ |
| 4153 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4154 | } |
| 4155 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4156 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4157 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4158 | /* reject other things that can't change */ |
| 4159 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4160 | return -EINVAL; |
| 4161 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4162 | return -EINVAL; |
| 4163 | if (params->supported_rates) |
| 4164 | return -EINVAL; |
| 4165 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4166 | return -EINVAL; |
| 4167 | } |
| 4168 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4169 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4170 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4171 | if (params->vlan) |
| 4172 | return -EINVAL; |
| 4173 | } |
| 4174 | |
| 4175 | switch (statype) { |
| 4176 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4177 | /* Use this only for authorizing/unauthorizing a station */ |
| 4178 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4179 | return -EOPNOTSUPP; |
| 4180 | break; |
| 4181 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4182 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4183 | /* accept only the listed bits */ |
| 4184 | if (params->sta_flags_mask & |
| 4185 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4186 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4187 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4188 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4189 | BIT(NL80211_STA_FLAG_WME) | |
| 4190 | BIT(NL80211_STA_FLAG_MFP))) |
| 4191 | return -EINVAL; |
| 4192 | |
| 4193 | /* but authenticated/associated only if driver handles it */ |
| 4194 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4195 | params->sta_flags_mask & |
| 4196 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4197 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4198 | return -EINVAL; |
| 4199 | break; |
| 4200 | case CFG80211_STA_IBSS: |
| 4201 | case CFG80211_STA_AP_STA: |
| 4202 | /* reject any changes other than AUTHORIZED */ |
| 4203 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4204 | return -EINVAL; |
| 4205 | break; |
| 4206 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4207 | /* reject any changes other than AUTHORIZED or WME */ |
| 4208 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4209 | BIT(NL80211_STA_FLAG_WME))) |
| 4210 | return -EINVAL; |
| 4211 | /* force (at least) rates when authorizing */ |
| 4212 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4213 | !params->supported_rates) |
| 4214 | return -EINVAL; |
| 4215 | break; |
| 4216 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4217 | /* reject any changes */ |
| 4218 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4219 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4220 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4221 | return -EINVAL; |
| 4222 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4223 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4224 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4225 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4226 | return -EINVAL; |
| 4227 | break; |
| 4228 | } |
| 4229 | |
| 4230 | return 0; |
| 4231 | } |
| 4232 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4233 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4234 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4235 | * 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] | 4236 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4237 | static struct net_device *get_vlan(struct genl_info *info, |
| 4238 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4239 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4240 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4241 | struct net_device *v; |
| 4242 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4243 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4244 | if (!vlanattr) |
| 4245 | return NULL; |
| 4246 | |
| 4247 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4248 | if (!v) |
| 4249 | return ERR_PTR(-ENODEV); |
| 4250 | |
| 4251 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4252 | ret = -EINVAL; |
| 4253 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4254 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4255 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4256 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4257 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4258 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4259 | ret = -EINVAL; |
| 4260 | goto error; |
| 4261 | } |
| 4262 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4263 | if (!netif_running(v)) { |
| 4264 | ret = -ENETDOWN; |
| 4265 | goto error; |
| 4266 | } |
| 4267 | |
| 4268 | return v; |
| 4269 | error: |
| 4270 | dev_put(v); |
| 4271 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4274 | static const struct nla_policy |
| 4275 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4276 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4277 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4278 | }; |
| 4279 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4280 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4281 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4282 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4283 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4284 | struct nlattr *nla; |
| 4285 | int err; |
| 4286 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4287 | /* parse WME attributes if present */ |
| 4288 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4289 | return 0; |
| 4290 | |
| 4291 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4292 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4293 | nl80211_sta_wme_policy); |
| 4294 | if (err) |
| 4295 | return err; |
| 4296 | |
| 4297 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4298 | params->uapsd_queues = nla_get_u8( |
| 4299 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4300 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4301 | return -EINVAL; |
| 4302 | |
| 4303 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4304 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4305 | |
| 4306 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4307 | return -EINVAL; |
| 4308 | |
| 4309 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4310 | |
| 4311 | return 0; |
| 4312 | } |
| 4313 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4314 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4315 | struct station_parameters *params) |
| 4316 | { |
| 4317 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4318 | params->supported_channels = |
| 4319 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4320 | params->supported_channels_len = |
| 4321 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4322 | /* |
| 4323 | * Need to include at least one (first channel, number of |
| 4324 | * channels) tuple for each subband, and must have proper |
| 4325 | * tuples for the rest of the data as well. |
| 4326 | */ |
| 4327 | if (params->supported_channels_len < 2) |
| 4328 | return -EINVAL; |
| 4329 | if (params->supported_channels_len % 2) |
| 4330 | return -EINVAL; |
| 4331 | } |
| 4332 | |
| 4333 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4334 | params->supported_oper_classes = |
| 4335 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4336 | params->supported_oper_classes_len = |
| 4337 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4338 | /* |
| 4339 | * The value of the Length field of the Supported Operating |
| 4340 | * Classes element is between 2 and 253. |
| 4341 | */ |
| 4342 | if (params->supported_oper_classes_len < 2 || |
| 4343 | params->supported_oper_classes_len > 253) |
| 4344 | return -EINVAL; |
| 4345 | } |
| 4346 | return 0; |
| 4347 | } |
| 4348 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4349 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4350 | struct station_parameters *params) |
| 4351 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4352 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4353 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4354 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4355 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4356 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4357 | params->ht_capa = |
| 4358 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4359 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4360 | params->vht_capa = |
| 4361 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4362 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4363 | err = nl80211_parse_sta_channel_info(info, params); |
| 4364 | if (err) |
| 4365 | return err; |
| 4366 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4367 | return nl80211_parse_sta_wme(info, params); |
| 4368 | } |
| 4369 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4370 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4371 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4373 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4374 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4375 | u8 *mac_addr; |
| 4376 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4377 | |
| 4378 | memset(¶ms, 0, sizeof(params)); |
| 4379 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4380 | if (!rdev->ops->change_station) |
| 4381 | return -EOPNOTSUPP; |
| 4382 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4383 | /* |
| 4384 | * AID and listen_interval properties can be set only for unassociated |
| 4385 | * station. Include these parameters here and will check them in |
| 4386 | * cfg80211_check_station_change(). |
| 4387 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4388 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4389 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4390 | |
| 4391 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4392 | params.listen_interval = |
| 4393 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4394 | else |
| 4395 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4396 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4397 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4398 | u8 tmp; |
| 4399 | |
| 4400 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4401 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4402 | return -EINVAL; |
| 4403 | |
| 4404 | params.support_p2p_ps = tmp; |
| 4405 | } else { |
| 4406 | params.support_p2p_ps = -1; |
| 4407 | } |
| 4408 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4409 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4410 | return -EINVAL; |
| 4411 | |
| 4412 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4413 | |
| 4414 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4415 | params.supported_rates = |
| 4416 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4417 | params.supported_rates_len = |
| 4418 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4419 | } |
| 4420 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4421 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4422 | params.capability = |
| 4423 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4424 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4425 | } |
| 4426 | |
| 4427 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4428 | params.ext_capab = |
| 4429 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4430 | params.ext_capab_len = |
| 4431 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4432 | } |
| 4433 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4434 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4435 | return -EINVAL; |
| 4436 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4437 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4438 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4439 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4440 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4441 | return -EINVAL; |
| 4442 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4443 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4444 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4445 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4446 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4447 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4448 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4449 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4450 | params.peer_aid = nla_get_u16( |
| 4451 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4452 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4453 | return -EINVAL; |
| 4454 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4455 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4456 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4457 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4458 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4459 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4460 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4461 | |
| 4462 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4463 | pm > NL80211_MESH_POWER_MAX) |
| 4464 | return -EINVAL; |
| 4465 | |
| 4466 | params.local_pm = pm; |
| 4467 | } |
| 4468 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4469 | /* Include parameters for TDLS peer (will check later) */ |
| 4470 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4471 | if (err) |
| 4472 | return err; |
| 4473 | |
| 4474 | params.vlan = get_vlan(info, rdev); |
| 4475 | if (IS_ERR(params.vlan)) |
| 4476 | return PTR_ERR(params.vlan); |
| 4477 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4478 | switch (dev->ieee80211_ptr->iftype) { |
| 4479 | case NL80211_IFTYPE_AP: |
| 4480 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4481 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4482 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4483 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4484 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4485 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4486 | break; |
| 4487 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4488 | err = -EOPNOTSUPP; |
| 4489 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4490 | } |
| 4491 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4492 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4493 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4494 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4495 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4496 | if (params.vlan) |
| 4497 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4498 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4499 | return err; |
| 4500 | } |
| 4501 | |
| 4502 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4505 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4506 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4507 | struct station_parameters params; |
| 4508 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4509 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4510 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4511 | |
| 4512 | memset(¶ms, 0, sizeof(params)); |
| 4513 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4514 | if (!rdev->ops->add_station) |
| 4515 | return -EOPNOTSUPP; |
| 4516 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4517 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4518 | return -EINVAL; |
| 4519 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4520 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4521 | return -EINVAL; |
| 4522 | |
| 4523 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4524 | return -EINVAL; |
| 4525 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4526 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4527 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4528 | return -EINVAL; |
| 4529 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4530 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4531 | params.supported_rates = |
| 4532 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4533 | params.supported_rates_len = |
| 4534 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4535 | params.listen_interval = |
| 4536 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4537 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4538 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4539 | u8 tmp; |
| 4540 | |
| 4541 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4542 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4543 | return -EINVAL; |
| 4544 | |
| 4545 | params.support_p2p_ps = tmp; |
| 4546 | } else { |
| 4547 | /* |
| 4548 | * if not specified, assume it's supported for P2P GO interface, |
| 4549 | * and is NOT supported for AP interface |
| 4550 | */ |
| 4551 | params.support_p2p_ps = |
| 4552 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4553 | } |
| 4554 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4555 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4556 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4557 | else |
| 4558 | 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] | 4559 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4560 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4561 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4562 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4563 | params.capability = |
| 4564 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4565 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4566 | } |
| 4567 | |
| 4568 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4569 | params.ext_capab = |
| 4570 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4571 | params.ext_capab_len = |
| 4572 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4573 | } |
| 4574 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4575 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4576 | params.ht_capa = |
| 4577 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4578 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4579 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4580 | params.vht_capa = |
| 4581 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4582 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4583 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4584 | params.opmode_notif_used = true; |
| 4585 | params.opmode_notif = |
| 4586 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4587 | } |
| 4588 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4589 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4590 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4591 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4592 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4593 | return -EINVAL; |
| 4594 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4595 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4596 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4597 | if (err) |
| 4598 | return err; |
| 4599 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4600 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4601 | if (err) |
| 4602 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4603 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4604 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4605 | return -EINVAL; |
| 4606 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4607 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4608 | * as userspace might just pass through the capabilities from the IEs |
| 4609 | * directly, rather than enforcing this restriction and returning an |
| 4610 | * error in this case. |
| 4611 | */ |
| 4612 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4613 | params.ht_capa = NULL; |
| 4614 | params.vht_capa = NULL; |
| 4615 | } |
| 4616 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4617 | /* When you run into this, adjust the code below for the new flag */ |
| 4618 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4619 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4620 | switch (dev->ieee80211_ptr->iftype) { |
| 4621 | case NL80211_IFTYPE_AP: |
| 4622 | case NL80211_IFTYPE_AP_VLAN: |
| 4623 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4624 | /* ignore WME attributes if iface/sta is not capable */ |
| 4625 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4626 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4627 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4628 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4629 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4630 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4631 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4632 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4633 | /* but don't bother the driver with it */ |
| 4634 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4635 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4636 | /* allow authenticated/associated only if driver handles it */ |
| 4637 | if (!(rdev->wiphy.features & |
| 4638 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4639 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4640 | return -EINVAL; |
| 4641 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4642 | /* Older userspace, or userspace wanting to be compatible with |
| 4643 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 4644 | * and assoc flags in the mask, but assumes the station will be |
| 4645 | * added as associated anyway since this was the required driver |
| 4646 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 4647 | * introduced. |
| 4648 | * In order to not bother drivers with this quirk in the API |
| 4649 | * set the flags in both the mask and set for new stations in |
| 4650 | * this case. |
| 4651 | */ |
| 4652 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 4653 | params.sta_flags_mask |= auth_assoc; |
| 4654 | params.sta_flags_set |= auth_assoc; |
| 4655 | } |
| 4656 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4657 | /* must be last in here for error handling */ |
| 4658 | params.vlan = get_vlan(info, rdev); |
| 4659 | if (IS_ERR(params.vlan)) |
| 4660 | return PTR_ERR(params.vlan); |
| 4661 | break; |
| 4662 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4663 | /* ignore uAPSD data */ |
| 4664 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4665 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4666 | /* associated is disallowed */ |
| 4667 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4668 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4669 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4670 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4671 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4672 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4673 | break; |
| 4674 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4675 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4676 | /* ignore uAPSD data */ |
| 4677 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4678 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4679 | /* these are disallowed */ |
| 4680 | if (params.sta_flags_mask & |
| 4681 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4682 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4683 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4684 | /* Only TDLS peers can be added */ |
| 4685 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4686 | return -EINVAL; |
| 4687 | /* Can only add if TDLS ... */ |
| 4688 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4689 | return -EOPNOTSUPP; |
| 4690 | /* ... with external setup is supported */ |
| 4691 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4692 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4693 | /* |
| 4694 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4695 | * as authorized, but it shouldn't yet be. |
| 4696 | */ |
| 4697 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4698 | break; |
| 4699 | default: |
| 4700 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4701 | } |
| 4702 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4703 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4704 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4705 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4706 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4707 | if (params.vlan) |
| 4708 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4709 | return err; |
| 4710 | } |
| 4711 | |
| 4712 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4715 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4716 | struct station_del_parameters params; |
| 4717 | |
| 4718 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4719 | |
| 4720 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4721 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4722 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4723 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4724 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4725 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4727 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4728 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4729 | if (!rdev->ops->del_station) |
| 4730 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4731 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4732 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4733 | params.subtype = |
| 4734 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4735 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4736 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4737 | return -EINVAL; |
| 4738 | } else { |
| 4739 | /* Default to Deauthentication frame */ |
| 4740 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4741 | } |
| 4742 | |
| 4743 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4744 | params.reason_code = |
| 4745 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4746 | if (params.reason_code == 0) |
| 4747 | return -EINVAL; /* 0 is reserved */ |
| 4748 | } else { |
| 4749 | /* Default to reason code 2 */ |
| 4750 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4751 | } |
| 4752 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4753 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4754 | } |
| 4755 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4756 | 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] | 4757 | int flags, struct net_device *dev, |
| 4758 | u8 *dst, u8 *next_hop, |
| 4759 | struct mpath_info *pinfo) |
| 4760 | { |
| 4761 | void *hdr; |
| 4762 | struct nlattr *pinfoattr; |
| 4763 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4764 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4765 | if (!hdr) |
| 4766 | return -1; |
| 4767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4768 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4769 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4770 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4771 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4772 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4773 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4774 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4775 | if (!pinfoattr) |
| 4776 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4777 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4778 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4779 | pinfo->frame_qlen)) |
| 4780 | goto nla_put_failure; |
| 4781 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4782 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4783 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4784 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4785 | pinfo->metric)) || |
| 4786 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4787 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4788 | pinfo->exptime)) || |
| 4789 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4790 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4791 | pinfo->flags)) || |
| 4792 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4793 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4794 | pinfo->discovery_timeout)) || |
| 4795 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4796 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4797 | pinfo->discovery_retries))) |
| 4798 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4799 | |
| 4800 | nla_nest_end(msg, pinfoattr); |
| 4801 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4802 | genlmsg_end(msg, hdr); |
| 4803 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4804 | |
| 4805 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4806 | genlmsg_cancel(msg, hdr); |
| 4807 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4811 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4812 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4813 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4814 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4815 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4816 | u8 dst[ETH_ALEN]; |
| 4817 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4818 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4819 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4820 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4821 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4822 | if (err) |
| 4823 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4824 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4825 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4826 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4827 | goto out_err; |
| 4828 | } |
| 4829 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4830 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4831 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4832 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4833 | } |
| 4834 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4835 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4836 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4837 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4838 | if (err == -ENOENT) |
| 4839 | break; |
| 4840 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4841 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4842 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4843 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4844 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4845 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4846 | &pinfo) < 0) |
| 4847 | goto out; |
| 4848 | |
| 4849 | path_idx++; |
| 4850 | } |
| 4851 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4852 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4853 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4854 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4855 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4856 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4857 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4861 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4863 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4864 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4865 | struct mpath_info pinfo; |
| 4866 | struct sk_buff *msg; |
| 4867 | u8 *dst = NULL; |
| 4868 | u8 next_hop[ETH_ALEN]; |
| 4869 | |
| 4870 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4871 | |
| 4872 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4873 | return -EINVAL; |
| 4874 | |
| 4875 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4876 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4877 | if (!rdev->ops->get_mpath) |
| 4878 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4879 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4881 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4882 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4883 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4884 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4885 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4886 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4887 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4888 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4889 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4890 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4891 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | dev, dst, next_hop, &pinfo) < 0) { |
| 4893 | nlmsg_free(msg); |
| 4894 | return -ENOBUFS; |
| 4895 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4896 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4897 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4901 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4903 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4904 | u8 *dst = NULL; |
| 4905 | u8 *next_hop = NULL; |
| 4906 | |
| 4907 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4908 | return -EINVAL; |
| 4909 | |
| 4910 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4911 | return -EINVAL; |
| 4912 | |
| 4913 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4914 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4916 | if (!rdev->ops->change_mpath) |
| 4917 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4919 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4920 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4921 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4922 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4923 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4924 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4925 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4926 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4928 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4929 | u8 *dst = NULL; |
| 4930 | u8 *next_hop = NULL; |
| 4931 | |
| 4932 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4933 | return -EINVAL; |
| 4934 | |
| 4935 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4936 | return -EINVAL; |
| 4937 | |
| 4938 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4939 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4940 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4941 | if (!rdev->ops->add_mpath) |
| 4942 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4944 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4945 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4946 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4947 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4951 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4953 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4954 | u8 *dst = NULL; |
| 4955 | |
| 4956 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4957 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4958 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4959 | if (!rdev->ops->del_mpath) |
| 4960 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4961 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4962 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4963 | } |
| 4964 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4965 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4966 | { |
| 4967 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4968 | int err; |
| 4969 | struct net_device *dev = info->user_ptr[1]; |
| 4970 | struct mpath_info pinfo; |
| 4971 | struct sk_buff *msg; |
| 4972 | u8 *dst = NULL; |
| 4973 | u8 mpp[ETH_ALEN]; |
| 4974 | |
| 4975 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4976 | |
| 4977 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4978 | return -EINVAL; |
| 4979 | |
| 4980 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4981 | |
| 4982 | if (!rdev->ops->get_mpp) |
| 4983 | return -EOPNOTSUPP; |
| 4984 | |
| 4985 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4986 | return -EOPNOTSUPP; |
| 4987 | |
| 4988 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4989 | if (err) |
| 4990 | return err; |
| 4991 | |
| 4992 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4993 | if (!msg) |
| 4994 | return -ENOMEM; |
| 4995 | |
| 4996 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4997 | dev, dst, mpp, &pinfo) < 0) { |
| 4998 | nlmsg_free(msg); |
| 4999 | return -ENOBUFS; |
| 5000 | } |
| 5001 | |
| 5002 | return genlmsg_reply(msg, info); |
| 5003 | } |
| 5004 | |
| 5005 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5006 | struct netlink_callback *cb) |
| 5007 | { |
| 5008 | struct mpath_info pinfo; |
| 5009 | struct cfg80211_registered_device *rdev; |
| 5010 | struct wireless_dev *wdev; |
| 5011 | u8 dst[ETH_ALEN]; |
| 5012 | u8 mpp[ETH_ALEN]; |
| 5013 | int path_idx = cb->args[2]; |
| 5014 | int err; |
| 5015 | |
| 5016 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5017 | if (err) |
| 5018 | return err; |
| 5019 | |
| 5020 | if (!rdev->ops->dump_mpp) { |
| 5021 | err = -EOPNOTSUPP; |
| 5022 | goto out_err; |
| 5023 | } |
| 5024 | |
| 5025 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5026 | err = -EOPNOTSUPP; |
| 5027 | goto out_err; |
| 5028 | } |
| 5029 | |
| 5030 | while (1) { |
| 5031 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5032 | mpp, &pinfo); |
| 5033 | if (err == -ENOENT) |
| 5034 | break; |
| 5035 | if (err) |
| 5036 | goto out_err; |
| 5037 | |
| 5038 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5039 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5040 | wdev->netdev, dst, mpp, |
| 5041 | &pinfo) < 0) |
| 5042 | goto out; |
| 5043 | |
| 5044 | path_idx++; |
| 5045 | } |
| 5046 | |
| 5047 | out: |
| 5048 | cb->args[2] = path_idx; |
| 5049 | err = skb->len; |
| 5050 | out_err: |
| 5051 | nl80211_finish_wdev_dump(rdev); |
| 5052 | return err; |
| 5053 | } |
| 5054 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5055 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5056 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5057 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5058 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5059 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5060 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5061 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5062 | |
| 5063 | memset(¶ms, 0, sizeof(params)); |
| 5064 | /* default to not changing parameters */ |
| 5065 | params.use_cts_prot = -1; |
| 5066 | params.use_short_preamble = -1; |
| 5067 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5068 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5069 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5070 | params.p2p_ctwindow = -1; |
| 5071 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5072 | |
| 5073 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5074 | params.use_cts_prot = |
| 5075 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5076 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5077 | params.use_short_preamble = |
| 5078 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5079 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5080 | params.use_short_slot_time = |
| 5081 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5082 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5083 | params.basic_rates = |
| 5084 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5085 | params.basic_rates_len = |
| 5086 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5087 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5088 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5089 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5090 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5091 | params.ht_opmode = |
| 5092 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5093 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5094 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5095 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5096 | return -EINVAL; |
| 5097 | params.p2p_ctwindow = |
| 5098 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5099 | if (params.p2p_ctwindow < 0) |
| 5100 | return -EINVAL; |
| 5101 | if (params.p2p_ctwindow != 0 && |
| 5102 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5103 | return -EINVAL; |
| 5104 | } |
| 5105 | |
| 5106 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5107 | u8 tmp; |
| 5108 | |
| 5109 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5110 | return -EINVAL; |
| 5111 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5112 | if (tmp > 1) |
| 5113 | return -EINVAL; |
| 5114 | params.p2p_opp_ps = tmp; |
| 5115 | if (params.p2p_opp_ps && |
| 5116 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5117 | return -EINVAL; |
| 5118 | } |
| 5119 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5120 | if (!rdev->ops->change_bss) |
| 5121 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5122 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5123 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5124 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5125 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5126 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5127 | wdev_lock(wdev); |
| 5128 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5129 | wdev_unlock(wdev); |
| 5130 | |
| 5131 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5132 | } |
| 5133 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5134 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5135 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5136 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5137 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5138 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5139 | u32 owner_nlportid; |
| 5140 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5141 | /* |
| 5142 | * You should only get this when cfg80211 hasn't yet initialized |
| 5143 | * completely when built-in to the kernel right between the time |
| 5144 | * window between nl80211_init() and regulatory_init(), if that is |
| 5145 | * even possible. |
| 5146 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5147 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5148 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5149 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5150 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5151 | user_reg_hint_type = |
| 5152 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5153 | else |
| 5154 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5155 | |
| 5156 | switch (user_reg_hint_type) { |
| 5157 | case NL80211_USER_REG_HINT_USER: |
| 5158 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5159 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5160 | return -EINVAL; |
| 5161 | |
| 5162 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5163 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5164 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5165 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5166 | owner_nlportid = info->snd_portid; |
| 5167 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5168 | } else { |
| 5169 | owner_nlportid = 0; |
| 5170 | is_indoor = true; |
| 5171 | } |
| 5172 | |
| 5173 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5174 | default: |
| 5175 | return -EINVAL; |
| 5176 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5179 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5180 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5183 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5184 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5185 | struct mesh_config cur_params; |
| 5186 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5187 | void *hdr; |
| 5188 | struct nlattr *pinfoattr; |
| 5189 | struct sk_buff *msg; |
| 5190 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5191 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5192 | return -EOPNOTSUPP; |
| 5193 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5194 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5195 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5196 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5197 | wdev_lock(wdev); |
| 5198 | /* If not connected, get default parameters */ |
| 5199 | if (!wdev->mesh_id_len) |
| 5200 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5201 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5202 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5203 | wdev_unlock(wdev); |
| 5204 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5205 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5206 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5207 | |
| 5208 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5209 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5210 | if (!msg) |
| 5211 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5212 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5213 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5214 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5215 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5216 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5217 | if (!pinfoattr) |
| 5218 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5219 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5220 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5221 | cur_params.dot11MeshRetryTimeout) || |
| 5222 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5223 | cur_params.dot11MeshConfirmTimeout) || |
| 5224 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5225 | cur_params.dot11MeshHoldingTimeout) || |
| 5226 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5227 | cur_params.dot11MeshMaxPeerLinks) || |
| 5228 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5229 | cur_params.dot11MeshMaxRetries) || |
| 5230 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5231 | cur_params.dot11MeshTTL) || |
| 5232 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5233 | cur_params.element_ttl) || |
| 5234 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5235 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5236 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5237 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5238 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5239 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5240 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5241 | cur_params.path_refresh_time) || |
| 5242 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5243 | cur_params.min_discovery_timeout) || |
| 5244 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5245 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5246 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5247 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5248 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5249 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5250 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5251 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5252 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5253 | cur_params.dot11MeshHWMPRootMode) || |
| 5254 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5255 | cur_params.dot11MeshHWMPRannInterval) || |
| 5256 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5257 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5258 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5259 | cur_params.dot11MeshForwarding) || |
| 5260 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5261 | cur_params.rssi_threshold) || |
| 5262 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5263 | cur_params.ht_opmode) || |
| 5264 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5265 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5266 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5267 | cur_params.dot11MeshHWMProotInterval) || |
| 5268 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5269 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5270 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5271 | cur_params.power_mode) || |
| 5272 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5273 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5274 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5275 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5276 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5277 | nla_nest_end(msg, pinfoattr); |
| 5278 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5279 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5280 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5281 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5282 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5283 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5284 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5285 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5288 | 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] | 5289 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5290 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5291 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5292 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5293 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5294 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5295 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5296 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5297 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5298 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5299 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5300 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5301 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5302 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5303 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5304 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5305 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5306 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5307 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5308 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5309 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5310 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5311 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5312 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5313 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5314 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5315 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5316 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5317 | }; |
| 5318 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5319 | static const struct nla_policy |
| 5320 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5321 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5322 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5323 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5324 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5325 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5326 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5327 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5328 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5329 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5330 | }; |
| 5331 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5332 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5333 | { |
| 5334 | u8 val = nla_get_u8(nla); |
| 5335 | if (val < min || val > max) |
| 5336 | return -EINVAL; |
| 5337 | *out = val; |
| 5338 | return 0; |
| 5339 | } |
| 5340 | |
| 5341 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5342 | { |
| 5343 | u8 val = nla_get_u8(nla); |
| 5344 | if (val < min || val > max) |
| 5345 | return -EINVAL; |
| 5346 | *out = val; |
| 5347 | return 0; |
| 5348 | } |
| 5349 | |
| 5350 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5351 | { |
| 5352 | u16 val = nla_get_u16(nla); |
| 5353 | if (val < min || val > max) |
| 5354 | return -EINVAL; |
| 5355 | *out = val; |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
| 5359 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5360 | { |
| 5361 | u32 val = nla_get_u32(nla); |
| 5362 | if (val < min || val > max) |
| 5363 | return -EINVAL; |
| 5364 | *out = val; |
| 5365 | return 0; |
| 5366 | } |
| 5367 | |
| 5368 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5369 | { |
| 5370 | s32 val = nla_get_s32(nla); |
| 5371 | if (val < min || val > max) |
| 5372 | return -EINVAL; |
| 5373 | *out = val; |
| 5374 | return 0; |
| 5375 | } |
| 5376 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5377 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5378 | struct mesh_config *cfg, |
| 5379 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5380 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5381 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5382 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5383 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5384 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5385 | do { \ |
| 5386 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5387 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5388 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5389 | mask |= (1 << (attr - 1)); \ |
| 5390 | } \ |
| 5391 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5392 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5393 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5394 | return -EINVAL; |
| 5395 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5396 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5397 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5398 | return -EINVAL; |
| 5399 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5400 | /* This makes sure that there aren't more than 32 mesh config |
| 5401 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5402 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5403 | |
| 5404 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5405 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5406 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5407 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5408 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5409 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5410 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5411 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5412 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5413 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5414 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5415 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5416 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5417 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5418 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5419 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5420 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5421 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5422 | 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] | 5423 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5424 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5425 | 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] | 5426 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5427 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5428 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5429 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5430 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5431 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5432 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5433 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5434 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5435 | 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] | 5436 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5437 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5438 | 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] | 5439 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5440 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5441 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5442 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5443 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5444 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5445 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5446 | 1, 65535, mask, |
| 5447 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5448 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5449 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5450 | 1, 65535, mask, |
| 5451 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5452 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5453 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5454 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5455 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5456 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5457 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5458 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5459 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5460 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5461 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5462 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5463 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5464 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5465 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5466 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5467 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5468 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5469 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5470 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5471 | 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] | 5472 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5473 | nl80211_check_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5474 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5475 | mask, NL80211_MESHCONF_HT_OPMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5476 | nl80211_check_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5477 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5478 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5479 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5480 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5481 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5482 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5483 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5484 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5485 | dot11MeshHWMPconfirmationInterval, |
| 5486 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5487 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5488 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5489 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5490 | NL80211_MESH_POWER_ACTIVE, |
| 5491 | NL80211_MESH_POWER_MAX, |
| 5492 | mask, NL80211_MESHCONF_POWER_MODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5493 | nl80211_check_u32); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5494 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5495 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5496 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5497 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5498 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5499 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5500 | if (mask_out) |
| 5501 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5502 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5503 | return 0; |
| 5504 | |
| 5505 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5506 | } |
| 5507 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5508 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5509 | struct mesh_setup *setup) |
| 5510 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5512 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5513 | |
| 5514 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5515 | return -EINVAL; |
| 5516 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5517 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5518 | nl80211_mesh_setup_params_policy)) |
| 5519 | return -EINVAL; |
| 5520 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5521 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5522 | setup->sync_method = |
| 5523 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5524 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5525 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5526 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5527 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5528 | setup->path_sel_proto = |
| 5529 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5530 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5531 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5532 | |
| 5533 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5534 | setup->path_metric = |
| 5535 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5536 | IEEE80211_PATH_METRIC_VENDOR : |
| 5537 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5538 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5539 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5540 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5541 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5542 | if (!is_valid_ie_attr(ieattr)) |
| 5543 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5544 | setup->ie = nla_data(ieattr); |
| 5545 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5546 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5547 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5548 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5549 | return -EINVAL; |
| 5550 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5551 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5552 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5553 | if (setup->is_secure) |
| 5554 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5555 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5556 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5557 | if (!setup->user_mpm) |
| 5558 | return -EINVAL; |
| 5559 | setup->auth_id = |
| 5560 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5561 | } |
| 5562 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5563 | return 0; |
| 5564 | } |
| 5565 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5566 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5567 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5568 | { |
| 5569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5570 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5572 | struct mesh_config cfg; |
| 5573 | u32 mask; |
| 5574 | int err; |
| 5575 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5576 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5577 | return -EOPNOTSUPP; |
| 5578 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5579 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5580 | return -EOPNOTSUPP; |
| 5581 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5582 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5583 | if (err) |
| 5584 | return err; |
| 5585 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5586 | wdev_lock(wdev); |
| 5587 | if (!wdev->mesh_id_len) |
| 5588 | err = -ENOLINK; |
| 5589 | |
| 5590 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5591 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5592 | |
| 5593 | wdev_unlock(wdev); |
| 5594 | |
| 5595 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5596 | } |
| 5597 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5598 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5599 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5600 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5601 | struct nlattr *nl_reg_rules; |
| 5602 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5603 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5604 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5605 | (regdom->dfs_region && |
| 5606 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5607 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5608 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5609 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5610 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5611 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5612 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5613 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5614 | struct nlattr *nl_reg_rule; |
| 5615 | const struct ieee80211_reg_rule *reg_rule; |
| 5616 | const struct ieee80211_freq_range *freq_range; |
| 5617 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5618 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5619 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5620 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5621 | freq_range = ®_rule->freq_range; |
| 5622 | power_rule = ®_rule->power_rule; |
| 5623 | |
| 5624 | nl_reg_rule = nla_nest_start(msg, i); |
| 5625 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5626 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5627 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5628 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5629 | if (!max_bandwidth_khz) |
| 5630 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5631 | reg_rule); |
| 5632 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5633 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5634 | reg_rule->flags) || |
| 5635 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5636 | freq_range->start_freq_khz) || |
| 5637 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5638 | freq_range->end_freq_khz) || |
| 5639 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5640 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5641 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5642 | power_rule->max_antenna_gain) || |
| 5643 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5644 | power_rule->max_eirp) || |
| 5645 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5646 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5647 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5648 | |
| 5649 | nla_nest_end(msg, nl_reg_rule); |
| 5650 | } |
| 5651 | |
| 5652 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5653 | return 0; |
| 5654 | |
| 5655 | nla_put_failure: |
| 5656 | return -EMSGSIZE; |
| 5657 | } |
| 5658 | |
| 5659 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5660 | { |
| 5661 | const struct ieee80211_regdomain *regdom = NULL; |
| 5662 | struct cfg80211_registered_device *rdev; |
| 5663 | struct wiphy *wiphy = NULL; |
| 5664 | struct sk_buff *msg; |
| 5665 | void *hdr; |
| 5666 | |
| 5667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5668 | if (!msg) |
| 5669 | return -ENOBUFS; |
| 5670 | |
| 5671 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5672 | NL80211_CMD_GET_REG); |
| 5673 | if (!hdr) |
| 5674 | goto put_failure; |
| 5675 | |
| 5676 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5677 | bool self_managed; |
| 5678 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5679 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5680 | if (IS_ERR(rdev)) { |
| 5681 | nlmsg_free(msg); |
| 5682 | return PTR_ERR(rdev); |
| 5683 | } |
| 5684 | |
| 5685 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5686 | self_managed = wiphy->regulatory_flags & |
| 5687 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5688 | regdom = get_wiphy_regdom(wiphy); |
| 5689 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5690 | /* a self-managed-reg device must have a private regdom */ |
| 5691 | if (WARN_ON(!regdom && self_managed)) { |
| 5692 | nlmsg_free(msg); |
| 5693 | return -EINVAL; |
| 5694 | } |
| 5695 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5696 | if (regdom && |
| 5697 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5698 | goto nla_put_failure; |
| 5699 | } |
| 5700 | |
| 5701 | if (!wiphy && reg_last_request_cell_base() && |
| 5702 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5703 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5704 | goto nla_put_failure; |
| 5705 | |
| 5706 | rcu_read_lock(); |
| 5707 | |
| 5708 | if (!regdom) |
| 5709 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5710 | |
| 5711 | if (nl80211_put_regdom(regdom, msg)) |
| 5712 | goto nla_put_failure_rcu; |
| 5713 | |
| 5714 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5715 | |
| 5716 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5717 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5718 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5719 | nla_put_failure_rcu: |
| 5720 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5721 | nla_put_failure: |
| 5722 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5723 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5724 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5725 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5728 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5729 | u32 seq, int flags, struct wiphy *wiphy, |
| 5730 | const struct ieee80211_regdomain *regdom) |
| 5731 | { |
| 5732 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5733 | NL80211_CMD_GET_REG); |
| 5734 | |
| 5735 | if (!hdr) |
| 5736 | return -1; |
| 5737 | |
| 5738 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5739 | |
| 5740 | if (nl80211_put_regdom(regdom, msg)) |
| 5741 | goto nla_put_failure; |
| 5742 | |
| 5743 | if (!wiphy && reg_last_request_cell_base() && |
| 5744 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5745 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5746 | goto nla_put_failure; |
| 5747 | |
| 5748 | if (wiphy && |
| 5749 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5750 | goto nla_put_failure; |
| 5751 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5752 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5753 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5754 | goto nla_put_failure; |
| 5755 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5756 | genlmsg_end(msg, hdr); |
| 5757 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5758 | |
| 5759 | nla_put_failure: |
| 5760 | genlmsg_cancel(msg, hdr); |
| 5761 | return -EMSGSIZE; |
| 5762 | } |
| 5763 | |
| 5764 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5765 | struct netlink_callback *cb) |
| 5766 | { |
| 5767 | const struct ieee80211_regdomain *regdom = NULL; |
| 5768 | struct cfg80211_registered_device *rdev; |
| 5769 | int err, reg_idx, start = cb->args[2]; |
| 5770 | |
| 5771 | rtnl_lock(); |
| 5772 | |
| 5773 | if (cfg80211_regdomain && start == 0) { |
| 5774 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5775 | NLM_F_MULTI, NULL, |
| 5776 | rtnl_dereference(cfg80211_regdomain)); |
| 5777 | if (err < 0) |
| 5778 | goto out_err; |
| 5779 | } |
| 5780 | |
| 5781 | /* the global regdom is idx 0 */ |
| 5782 | reg_idx = 1; |
| 5783 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5784 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5785 | if (!regdom) |
| 5786 | continue; |
| 5787 | |
| 5788 | if (++reg_idx <= start) |
| 5789 | continue; |
| 5790 | |
| 5791 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5792 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5793 | if (err < 0) { |
| 5794 | reg_idx--; |
| 5795 | break; |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | cb->args[2] = reg_idx; |
| 5800 | err = skb->len; |
| 5801 | out_err: |
| 5802 | rtnl_unlock(); |
| 5803 | return err; |
| 5804 | } |
| 5805 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5806 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 5807 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 5808 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5809 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5810 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5811 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5812 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5813 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5814 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 5815 | }; |
| 5816 | |
| 5817 | static int parse_reg_rule(struct nlattr *tb[], |
| 5818 | struct ieee80211_reg_rule *reg_rule) |
| 5819 | { |
| 5820 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 5821 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 5822 | |
| 5823 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 5824 | return -EINVAL; |
| 5825 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 5826 | return -EINVAL; |
| 5827 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 5828 | return -EINVAL; |
| 5829 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 5830 | return -EINVAL; |
| 5831 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 5832 | return -EINVAL; |
| 5833 | |
| 5834 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 5835 | |
| 5836 | freq_range->start_freq_khz = |
| 5837 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 5838 | freq_range->end_freq_khz = |
| 5839 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 5840 | freq_range->max_bandwidth_khz = |
| 5841 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 5842 | |
| 5843 | power_rule->max_eirp = |
| 5844 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 5845 | |
| 5846 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 5847 | power_rule->max_antenna_gain = |
| 5848 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 5849 | |
| 5850 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 5851 | reg_rule->dfs_cac_ms = |
| 5852 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 5853 | |
| 5854 | return 0; |
| 5855 | } |
| 5856 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5857 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5858 | { |
| 5859 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5860 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5861 | char *alpha2; |
| 5862 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5863 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5864 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5865 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5866 | |
| 5867 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5868 | return -EINVAL; |
| 5869 | |
| 5870 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5871 | return -EINVAL; |
| 5872 | |
| 5873 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5874 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5875 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5876 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5877 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5878 | 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] | 5879 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5880 | num_rules++; |
| 5881 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5882 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5885 | if (!reg_is_valid_request(alpha2)) |
| 5886 | return -EINVAL; |
| 5887 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5888 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5889 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5890 | |
| 5891 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5892 | if (!rd) |
| 5893 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5894 | |
| 5895 | rd->n_reg_rules = num_rules; |
| 5896 | rd->alpha2[0] = alpha2[0]; |
| 5897 | rd->alpha2[1] = alpha2[1]; |
| 5898 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5899 | /* |
| 5900 | * Disable DFS master mode if the DFS region was |
| 5901 | * not supported or known on this kernel. |
| 5902 | */ |
| 5903 | if (reg_supported_dfs_region(dfs_region)) |
| 5904 | rd->dfs_region = dfs_region; |
| 5905 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5906 | 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] | 5907 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5908 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5909 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5910 | reg_rule_policy); |
| 5911 | if (r) |
| 5912 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5913 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5914 | if (r) |
| 5915 | goto bad_reg; |
| 5916 | |
| 5917 | rule_idx++; |
| 5918 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5919 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5920 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5921 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5922 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 5925 | /* set_regdom takes ownership of rd */ |
| 5926 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5927 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5928 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5929 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5930 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5931 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5932 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5933 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5934 | { |
| 5935 | struct nlattr *attr1, *attr2; |
| 5936 | int n_channels = 0, tmp1, tmp2; |
| 5937 | |
| 5938 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5939 | n_channels++; |
| 5940 | /* |
| 5941 | * Some hardware has a limited channel list for |
| 5942 | * scanning, and it is pretty much nonsensical |
| 5943 | * to scan for a channel twice, so disallow that |
| 5944 | * and don't require drivers to check that the |
| 5945 | * channel list they get isn't longer than what |
| 5946 | * they can scan, as long as they can scan all |
| 5947 | * the channels they registered at once. |
| 5948 | */ |
| 5949 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5950 | if (attr1 != attr2 && |
| 5951 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5952 | return 0; |
| 5953 | } |
| 5954 | |
| 5955 | return n_channels; |
| 5956 | } |
| 5957 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5958 | 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] | 5959 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5960 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 5964 | struct cfg80211_bss_selection *bss_select) |
| 5965 | { |
| 5966 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 5967 | struct nlattr *nest; |
| 5968 | int err; |
| 5969 | bool found = false; |
| 5970 | int i; |
| 5971 | |
| 5972 | /* only process one nested attribute */ |
| 5973 | nest = nla_data(nla); |
| 5974 | if (!nla_ok(nest, nla_len(nest))) |
| 5975 | return -EINVAL; |
| 5976 | |
| 5977 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), |
| 5978 | nla_len(nest), nl80211_bss_select_policy); |
| 5979 | if (err) |
| 5980 | return err; |
| 5981 | |
| 5982 | /* only one attribute may be given */ |
| 5983 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 5984 | if (attr[i]) { |
| 5985 | if (found) |
| 5986 | return -EINVAL; |
| 5987 | found = true; |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 5992 | |
| 5993 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 5994 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 5995 | |
| 5996 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 5997 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 5998 | bss_select->param.band_pref = |
| 5999 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6000 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6001 | return -EINVAL; |
| 6002 | } |
| 6003 | |
| 6004 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6005 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6006 | |
| 6007 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6008 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6009 | bss_select->param.adjust.band = adj_param->band; |
| 6010 | bss_select->param.adjust.delta = adj_param->delta; |
| 6011 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6012 | return -EINVAL; |
| 6013 | } |
| 6014 | |
| 6015 | /* user-space did not provide behaviour attribute */ |
| 6016 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6017 | return -EINVAL; |
| 6018 | |
| 6019 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6020 | return -EINVAL; |
| 6021 | |
| 6022 | return 0; |
| 6023 | } |
| 6024 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6025 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6026 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6027 | { |
| 6028 | int i; |
| 6029 | |
| 6030 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6031 | eth_zero_addr(mac_addr); |
| 6032 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6033 | mac_addr[0] = 0x2; |
| 6034 | mac_addr_mask[0] = 0x3; |
| 6035 | |
| 6036 | return 0; |
| 6037 | } |
| 6038 | |
| 6039 | /* need both or none */ |
| 6040 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6041 | return -EINVAL; |
| 6042 | |
| 6043 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6044 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6045 | |
| 6046 | /* don't allow or configure an mcast address */ |
| 6047 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6048 | is_multicast_ether_addr(mac_addr)) |
| 6049 | return -EINVAL; |
| 6050 | |
| 6051 | /* |
| 6052 | * allow users to pass a MAC address that has bits set outside |
| 6053 | * of the mask, but don't bother drivers with having to deal |
| 6054 | * with such bits |
| 6055 | */ |
| 6056 | for (i = 0; i < ETH_ALEN; i++) |
| 6057 | mac_addr[i] &= mac_addr_mask[i]; |
| 6058 | |
| 6059 | return 0; |
| 6060 | } |
| 6061 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6062 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6063 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6065 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6066 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6067 | struct nlattr *attr; |
| 6068 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6069 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6070 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6071 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6072 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6073 | return -EINVAL; |
| 6074 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6075 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6076 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6077 | if (!rdev->ops->scan) |
| 6078 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6079 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6080 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6081 | err = -EBUSY; |
| 6082 | goto unlock; |
| 6083 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6084 | |
| 6085 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6086 | n_channels = validate_scan_freqs( |
| 6087 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6088 | if (!n_channels) { |
| 6089 | err = -EINVAL; |
| 6090 | goto unlock; |
| 6091 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6092 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6093 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6097 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6098 | n_ssids++; |
| 6099 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6100 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6101 | err = -EINVAL; |
| 6102 | goto unlock; |
| 6103 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6104 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6105 | if (info->attrs[NL80211_ATTR_IE]) |
| 6106 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6107 | else |
| 6108 | ie_len = 0; |
| 6109 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6110 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6111 | err = -EINVAL; |
| 6112 | goto unlock; |
| 6113 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6114 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6115 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6116 | + sizeof(*request->ssids) * n_ssids |
| 6117 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6118 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6119 | if (!request) { |
| 6120 | err = -ENOMEM; |
| 6121 | goto unlock; |
| 6122 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6123 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6124 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6125 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6126 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6127 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6128 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6129 | request->ie = (void *)(request->ssids + n_ssids); |
| 6130 | else |
| 6131 | request->ie = (void *)(request->channels + n_channels); |
| 6132 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6133 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6134 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6135 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6136 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6137 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6138 | struct ieee80211_channel *chan; |
| 6139 | |
| 6140 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6141 | |
| 6142 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6143 | err = -EINVAL; |
| 6144 | goto out_free; |
| 6145 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6146 | |
| 6147 | /* ignore disabled channels */ |
| 6148 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6149 | continue; |
| 6150 | |
| 6151 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6152 | i++; |
| 6153 | } |
| 6154 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6155 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6156 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6157 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6158 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6159 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6160 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6161 | if (!wiphy->bands[band]) |
| 6162 | continue; |
| 6163 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6164 | struct ieee80211_channel *chan; |
| 6165 | |
| 6166 | chan = &wiphy->bands[band]->channels[j]; |
| 6167 | |
| 6168 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6169 | continue; |
| 6170 | |
| 6171 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6172 | i++; |
| 6173 | } |
| 6174 | } |
| 6175 | } |
| 6176 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6177 | if (!i) { |
| 6178 | err = -EINVAL; |
| 6179 | goto out_free; |
| 6180 | } |
| 6181 | |
| 6182 | request->n_channels = i; |
| 6183 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6184 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6185 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6186 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6187 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6188 | err = -EINVAL; |
| 6189 | goto out_free; |
| 6190 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6191 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6192 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6193 | i++; |
| 6194 | } |
| 6195 | } |
| 6196 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6197 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6198 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6199 | memcpy((void *)request->ie, |
| 6200 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6201 | request->ie_len); |
| 6202 | } |
| 6203 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6204 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6205 | if (wiphy->bands[i]) |
| 6206 | request->rates[i] = |
| 6207 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6208 | |
| 6209 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6210 | nla_for_each_nested(attr, |
| 6211 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6212 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6213 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6214 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6215 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6216 | err = -EINVAL; |
| 6217 | goto out_free; |
| 6218 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6219 | |
| 6220 | if (!wiphy->bands[band]) |
| 6221 | continue; |
| 6222 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6223 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6224 | nla_data(attr), |
| 6225 | nla_len(attr), |
| 6226 | &request->rates[band]); |
| 6227 | if (err) |
| 6228 | goto out_free; |
| 6229 | } |
| 6230 | } |
| 6231 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6232 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6233 | if (!wiphy_ext_feature_isset(wiphy, |
| 6234 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6235 | err = -EOPNOTSUPP; |
| 6236 | goto out_free; |
| 6237 | } |
| 6238 | |
| 6239 | request->duration = |
| 6240 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6241 | request->duration_mandatory = |
| 6242 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6243 | } |
| 6244 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6245 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6246 | request->flags = nla_get_u32( |
| 6247 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6248 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6249 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6250 | err = -EOPNOTSUPP; |
| 6251 | goto out_free; |
| 6252 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6253 | |
| 6254 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6255 | if (!(wiphy->features & |
| 6256 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6257 | err = -EOPNOTSUPP; |
| 6258 | goto out_free; |
| 6259 | } |
| 6260 | |
| 6261 | if (wdev->current_bss) { |
| 6262 | err = -EOPNOTSUPP; |
| 6263 | goto out_free; |
| 6264 | } |
| 6265 | |
| 6266 | err = nl80211_parse_random_mac(info->attrs, |
| 6267 | request->mac_addr, |
| 6268 | request->mac_addr_mask); |
| 6269 | if (err) |
| 6270 | goto out_free; |
| 6271 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6272 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6273 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6274 | request->no_cck = |
| 6275 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6276 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6277 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6278 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6279 | ETH_ALEN); |
| 6280 | else |
| 6281 | eth_broadcast_addr(request->bssid); |
| 6282 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6283 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6284 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6285 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6286 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6287 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6288 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6289 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6290 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6291 | nl80211_send_scan_start(rdev, wdev); |
| 6292 | if (wdev->netdev) |
| 6293 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6295 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6296 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6297 | kfree(request); |
| 6298 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6299 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6300 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6301 | return err; |
| 6302 | } |
| 6303 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6304 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6305 | { |
| 6306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6307 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6308 | |
| 6309 | if (!rdev->ops->abort_scan) |
| 6310 | return -EOPNOTSUPP; |
| 6311 | |
| 6312 | if (rdev->scan_msg) |
| 6313 | return 0; |
| 6314 | |
| 6315 | if (!rdev->scan_req) |
| 6316 | return -ENOENT; |
| 6317 | |
| 6318 | rdev_abort_scan(rdev, wdev); |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6322 | static int |
| 6323 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6324 | struct cfg80211_sched_scan_request *request, |
| 6325 | struct nlattr **attrs) |
| 6326 | { |
| 6327 | int tmp, err, i = 0; |
| 6328 | struct nlattr *attr; |
| 6329 | |
| 6330 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6331 | u32 interval; |
| 6332 | |
| 6333 | /* |
| 6334 | * If scan plans are not specified, |
| 6335 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6336 | * case one scan plan will be set with the specified scan |
| 6337 | * interval and infinite number of iterations. |
| 6338 | */ |
| 6339 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6340 | return -EINVAL; |
| 6341 | |
| 6342 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6343 | if (!interval) |
| 6344 | return -EINVAL; |
| 6345 | |
| 6346 | request->scan_plans[0].interval = |
| 6347 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6348 | if (!request->scan_plans[0].interval) |
| 6349 | return -EINVAL; |
| 6350 | |
| 6351 | if (request->scan_plans[0].interval > |
| 6352 | wiphy->max_sched_scan_plan_interval) |
| 6353 | request->scan_plans[0].interval = |
| 6354 | wiphy->max_sched_scan_plan_interval; |
| 6355 | |
| 6356 | return 0; |
| 6357 | } |
| 6358 | |
| 6359 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6360 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6361 | |
| 6362 | if (WARN_ON(i >= n_plans)) |
| 6363 | return -EINVAL; |
| 6364 | |
| 6365 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6366 | nla_data(attr), nla_len(attr), |
| 6367 | nl80211_plan_policy); |
| 6368 | if (err) |
| 6369 | return err; |
| 6370 | |
| 6371 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6372 | return -EINVAL; |
| 6373 | |
| 6374 | request->scan_plans[i].interval = |
| 6375 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6376 | if (!request->scan_plans[i].interval || |
| 6377 | request->scan_plans[i].interval > |
| 6378 | wiphy->max_sched_scan_plan_interval) |
| 6379 | return -EINVAL; |
| 6380 | |
| 6381 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6382 | request->scan_plans[i].iterations = |
| 6383 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6384 | if (!request->scan_plans[i].iterations || |
| 6385 | (request->scan_plans[i].iterations > |
| 6386 | wiphy->max_sched_scan_plan_iterations)) |
| 6387 | return -EINVAL; |
| 6388 | } else if (i < n_plans - 1) { |
| 6389 | /* |
| 6390 | * All scan plans but the last one must specify |
| 6391 | * a finite number of iterations |
| 6392 | */ |
| 6393 | return -EINVAL; |
| 6394 | } |
| 6395 | |
| 6396 | i++; |
| 6397 | } |
| 6398 | |
| 6399 | /* |
| 6400 | * The last scan plan must not specify the number of |
| 6401 | * iterations, it is supposed to run infinitely |
| 6402 | */ |
| 6403 | if (request->scan_plans[n_plans - 1].iterations) |
| 6404 | return -EINVAL; |
| 6405 | |
| 6406 | return 0; |
| 6407 | } |
| 6408 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6409 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6410 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6411 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6412 | { |
| 6413 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6414 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6415 | 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] | 6416 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6417 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6418 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6419 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6420 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6421 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6422 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6423 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6424 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6425 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6426 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6427 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6428 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6429 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6430 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6431 | } |
| 6432 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6433 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6434 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6435 | tmp) |
| 6436 | n_ssids++; |
| 6437 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6438 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6439 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6440 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6441 | /* |
| 6442 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6443 | * the old implementation, matchsets containing only the RSSI attribute |
| 6444 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6445 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6446 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6447 | * older userspace that treated a matchset with only the RSSI as the |
| 6448 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6449 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6450 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6451 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6452 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6453 | tmp) { |
| 6454 | struct nlattr *rssi; |
| 6455 | |
| 6456 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6457 | nla_data(attr), nla_len(attr), |
| 6458 | nl80211_match_policy); |
| 6459 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6460 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6461 | /* add other standalone attributes here */ |
| 6462 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6463 | n_match_sets++; |
| 6464 | continue; |
| 6465 | } |
| 6466 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6467 | if (rssi) |
| 6468 | default_match_rssi = nla_get_s32(rssi); |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | /* However, if there's no other matchset, add the RSSI one */ |
| 6473 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6474 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6475 | |
| 6476 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6477 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6478 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6479 | if (attrs[NL80211_ATTR_IE]) |
| 6480 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6481 | else |
| 6482 | ie_len = 0; |
| 6483 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6484 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6485 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6486 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6487 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6488 | /* |
| 6489 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6490 | * each scan plan already specifies its own interval |
| 6491 | */ |
| 6492 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6493 | return ERR_PTR(-EINVAL); |
| 6494 | |
| 6495 | nla_for_each_nested(attr, |
| 6496 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6497 | n_plans++; |
| 6498 | } else { |
| 6499 | /* |
| 6500 | * The scan interval attribute is kept for backward |
| 6501 | * compatibility. If no scan plans are specified and sched scan |
| 6502 | * interval is specified, one scan plan will be set with this |
| 6503 | * scan interval and infinite number of iterations. |
| 6504 | */ |
| 6505 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6506 | return ERR_PTR(-EINVAL); |
| 6507 | |
| 6508 | n_plans = 1; |
| 6509 | } |
| 6510 | |
| 6511 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6512 | return ERR_PTR(-EINVAL); |
| 6513 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6514 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6515 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6516 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6517 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6518 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6519 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6520 | if (!request) |
| 6521 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6522 | |
| 6523 | if (n_ssids) |
| 6524 | request->ssids = (void *)&request->channels[n_channels]; |
| 6525 | request->n_ssids = n_ssids; |
| 6526 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6527 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6528 | request->ie = (void *)(request->ssids + n_ssids); |
| 6529 | else |
| 6530 | request->ie = (void *)(request->channels + n_channels); |
| 6531 | } |
| 6532 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6533 | if (n_match_sets) { |
| 6534 | if (request->ie) |
| 6535 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6536 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6537 | request->match_sets = |
| 6538 | (void *)(request->ssids + n_ssids); |
| 6539 | else |
| 6540 | request->match_sets = |
| 6541 | (void *)(request->channels + n_channels); |
| 6542 | } |
| 6543 | request->n_match_sets = n_match_sets; |
| 6544 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6545 | if (n_match_sets) |
| 6546 | request->scan_plans = (void *)(request->match_sets + |
| 6547 | n_match_sets); |
| 6548 | else if (request->ie) |
| 6549 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6550 | else if (n_ssids) |
| 6551 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6552 | else |
| 6553 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6554 | |
| 6555 | request->n_scan_plans = n_plans; |
| 6556 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6557 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6558 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6559 | /* user specified, bail out if channel not found */ |
| 6560 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6561 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6562 | tmp) { |
| 6563 | struct ieee80211_channel *chan; |
| 6564 | |
| 6565 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6566 | |
| 6567 | if (!chan) { |
| 6568 | err = -EINVAL; |
| 6569 | goto out_free; |
| 6570 | } |
| 6571 | |
| 6572 | /* ignore disabled channels */ |
| 6573 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6574 | continue; |
| 6575 | |
| 6576 | request->channels[i] = chan; |
| 6577 | i++; |
| 6578 | } |
| 6579 | } else { |
| 6580 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6581 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6582 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6583 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6584 | if (!wiphy->bands[band]) |
| 6585 | continue; |
| 6586 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6587 | struct ieee80211_channel *chan; |
| 6588 | |
| 6589 | chan = &wiphy->bands[band]->channels[j]; |
| 6590 | |
| 6591 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6592 | continue; |
| 6593 | |
| 6594 | request->channels[i] = chan; |
| 6595 | i++; |
| 6596 | } |
| 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | if (!i) { |
| 6601 | err = -EINVAL; |
| 6602 | goto out_free; |
| 6603 | } |
| 6604 | |
| 6605 | request->n_channels = i; |
| 6606 | |
| 6607 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6608 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6609 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6610 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6611 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6612 | err = -EINVAL; |
| 6613 | goto out_free; |
| 6614 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6615 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6616 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6617 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6618 | i++; |
| 6619 | } |
| 6620 | } |
| 6621 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6622 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6623 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6624 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6625 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6626 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6627 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6628 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6629 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6630 | nla_data(attr), nla_len(attr), |
| 6631 | nl80211_match_policy); |
| 6632 | if (err) |
| 6633 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6634 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6635 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6636 | if (WARN_ON(i >= n_match_sets)) { |
| 6637 | /* this indicates a programming error, |
| 6638 | * the loop above should have verified |
| 6639 | * things properly |
| 6640 | */ |
| 6641 | err = -EINVAL; |
| 6642 | goto out_free; |
| 6643 | } |
| 6644 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6645 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6646 | err = -EINVAL; |
| 6647 | goto out_free; |
| 6648 | } |
| 6649 | memcpy(request->match_sets[i].ssid.ssid, |
| 6650 | nla_data(ssid), nla_len(ssid)); |
| 6651 | request->match_sets[i].ssid.ssid_len = |
| 6652 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 6653 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6654 | request->match_sets[i].rssi_thold = |
| 6655 | default_match_rssi; |
| 6656 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6657 | if (rssi) |
| 6658 | request->match_sets[i].rssi_thold = |
| 6659 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6660 | } |
| 6661 | i++; |
| 6662 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6663 | |
| 6664 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6665 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6666 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6667 | |
| 6668 | request->min_rssi_thold = INT_MAX; |
| 6669 | for (i = 0; i < n_match_sets; i++) |
| 6670 | request->min_rssi_thold = |
| 6671 | min(request->match_sets[i].rssi_thold, |
| 6672 | request->min_rssi_thold); |
| 6673 | } else { |
| 6674 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6675 | } |
| 6676 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6677 | if (ie_len) { |
| 6678 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6679 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6680 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6681 | request->ie_len); |
| 6682 | } |
| 6683 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6684 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6685 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6686 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6687 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6688 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6689 | err = -EOPNOTSUPP; |
| 6690 | goto out_free; |
| 6691 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6692 | |
| 6693 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6694 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6695 | |
| 6696 | if (!wdev) /* must be net-detect */ |
| 6697 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6698 | |
| 6699 | if (!(wiphy->features & flg)) { |
| 6700 | err = -EOPNOTSUPP; |
| 6701 | goto out_free; |
| 6702 | } |
| 6703 | |
| 6704 | if (wdev && wdev->current_bss) { |
| 6705 | err = -EOPNOTSUPP; |
| 6706 | goto out_free; |
| 6707 | } |
| 6708 | |
| 6709 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6710 | request->mac_addr_mask); |
| 6711 | if (err) |
| 6712 | goto out_free; |
| 6713 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6714 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6715 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6716 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6717 | request->delay = |
| 6718 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6719 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6720 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 6721 | if (err) |
| 6722 | goto out_free; |
| 6723 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6724 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6725 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6726 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6727 | |
| 6728 | out_free: |
| 6729 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6730 | return ERR_PTR(err); |
| 6731 | } |
| 6732 | |
| 6733 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6734 | struct genl_info *info) |
| 6735 | { |
| 6736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6737 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6738 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6739 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6740 | int err; |
| 6741 | |
| 6742 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6743 | !rdev->ops->sched_scan_start) |
| 6744 | return -EOPNOTSUPP; |
| 6745 | |
| 6746 | if (rdev->sched_scan_req) |
| 6747 | return -EINPROGRESS; |
| 6748 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6749 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6750 | info->attrs); |
| 6751 | |
| 6752 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6753 | if (err) |
| 6754 | goto out_err; |
| 6755 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6756 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6757 | if (err) |
| 6758 | goto out_free; |
| 6759 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6760 | sched_scan_req->dev = dev; |
| 6761 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6762 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6763 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6764 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6765 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6766 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6767 | |
| 6768 | nl80211_send_sched_scan(rdev, dev, |
| 6769 | NL80211_CMD_START_SCHED_SCAN); |
| 6770 | return 0; |
| 6771 | |
| 6772 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6773 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6774 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6775 | return err; |
| 6776 | } |
| 6777 | |
| 6778 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6779 | struct genl_info *info) |
| 6780 | { |
| 6781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6782 | |
| 6783 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6784 | !rdev->ops->sched_scan_stop) |
| 6785 | return -EOPNOTSUPP; |
| 6786 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6787 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6788 | } |
| 6789 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6790 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6791 | struct genl_info *info) |
| 6792 | { |
| 6793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6794 | struct net_device *dev = info->user_ptr[1]; |
| 6795 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6796 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6797 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6798 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6799 | int err; |
| 6800 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6801 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6802 | if (dfs_region == NL80211_DFS_UNSET) |
| 6803 | return -EINVAL; |
| 6804 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6805 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6806 | if (err) |
| 6807 | return err; |
| 6808 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6809 | if (netif_carrier_ok(dev)) |
| 6810 | return -EBUSY; |
| 6811 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6812 | if (wdev->cac_started) |
| 6813 | return -EBUSY; |
| 6814 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6815 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6816 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6817 | if (err < 0) |
| 6818 | return err; |
| 6819 | |
| 6820 | if (err == 0) |
| 6821 | return -EINVAL; |
| 6822 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6823 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6824 | return -EINVAL; |
| 6825 | |
| 6826 | if (!rdev->ops->start_radar_detection) |
| 6827 | return -EOPNOTSUPP; |
| 6828 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6829 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6830 | if (WARN_ON(!cac_time_ms)) |
| 6831 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6832 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 6833 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6834 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6835 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6836 | wdev->cac_started = true; |
| 6837 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6838 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6839 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6840 | return err; |
| 6841 | } |
| 6842 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6843 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6844 | { |
| 6845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6846 | struct net_device *dev = info->user_ptr[1]; |
| 6847 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6848 | struct cfg80211_csa_settings params; |
| 6849 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6850 | * function is called under RTNL lock, so this should not be a problem. |
| 6851 | */ |
| 6852 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6853 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6854 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6855 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6856 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6857 | |
| 6858 | if (!rdev->ops->channel_switch || |
| 6859 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6860 | return -EOPNOTSUPP; |
| 6861 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6862 | switch (dev->ieee80211_ptr->iftype) { |
| 6863 | case NL80211_IFTYPE_AP: |
| 6864 | case NL80211_IFTYPE_P2P_GO: |
| 6865 | need_new_beacon = true; |
| 6866 | |
| 6867 | /* useless if AP is not running */ |
| 6868 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6869 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6870 | break; |
| 6871 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6872 | if (!wdev->ssid_len) |
| 6873 | return -ENOTCONN; |
| 6874 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6875 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6876 | if (!wdev->mesh_id_len) |
| 6877 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6878 | break; |
| 6879 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6880 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6881 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6882 | |
| 6883 | memset(¶ms, 0, sizeof(params)); |
| 6884 | |
| 6885 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6886 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6887 | return -EINVAL; |
| 6888 | |
| 6889 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6890 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6891 | return -EINVAL; |
| 6892 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6893 | /* Even though the attribute is u32, the specification says |
| 6894 | * u8, so let's make sure we don't overflow. |
| 6895 | */ |
| 6896 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6897 | if (cs_count > 255) |
| 6898 | return -EINVAL; |
| 6899 | |
| 6900 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6901 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6902 | if (!need_new_beacon) |
| 6903 | goto skip_beacons; |
| 6904 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6905 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6906 | if (err) |
| 6907 | return err; |
| 6908 | |
| 6909 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6910 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6911 | nl80211_policy); |
| 6912 | if (err) |
| 6913 | return err; |
| 6914 | |
| 6915 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6916 | if (err) |
| 6917 | return err; |
| 6918 | |
| 6919 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6920 | return -EINVAL; |
| 6921 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6922 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6923 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6924 | return -EINVAL; |
| 6925 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6926 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6927 | if (rdev->wiphy.max_num_csa_counters && |
| 6928 | (params.n_counter_offsets_beacon > |
| 6929 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6930 | return -EINVAL; |
| 6931 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6932 | params.counter_offsets_beacon = |
| 6933 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6934 | |
| 6935 | /* sanity checks - counters should fit and be the same */ |
| 6936 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6937 | u16 offset = params.counter_offsets_beacon[i]; |
| 6938 | |
| 6939 | if (offset >= params.beacon_csa.tail_len) |
| 6940 | return -EINVAL; |
| 6941 | |
| 6942 | if (params.beacon_csa.tail[offset] != params.count) |
| 6943 | return -EINVAL; |
| 6944 | } |
| 6945 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6946 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6947 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6948 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6949 | return -EINVAL; |
| 6950 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6951 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6952 | if (rdev->wiphy.max_num_csa_counters && |
| 6953 | (params.n_counter_offsets_beacon > |
| 6954 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6955 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6956 | |
| 6957 | params.counter_offsets_presp = |
| 6958 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6959 | |
| 6960 | /* sanity checks - counters should fit and be the same */ |
| 6961 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6962 | u16 offset = params.counter_offsets_presp[i]; |
| 6963 | |
| 6964 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6965 | return -EINVAL; |
| 6966 | |
| 6967 | if (params.beacon_csa.probe_resp[offset] != |
| 6968 | params.count) |
| 6969 | return -EINVAL; |
| 6970 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6971 | } |
| 6972 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6973 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6974 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6975 | if (err) |
| 6976 | return err; |
| 6977 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 6978 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 6979 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6980 | return -EINVAL; |
| 6981 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6982 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6983 | ¶ms.chandef, |
| 6984 | wdev->iftype); |
| 6985 | if (err < 0) |
| 6986 | return err; |
| 6987 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6988 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6989 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6990 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6991 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6992 | params.block_tx = true; |
| 6993 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6994 | wdev_lock(wdev); |
| 6995 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6996 | wdev_unlock(wdev); |
| 6997 | |
| 6998 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6999 | } |
| 7000 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7001 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7002 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7003 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7004 | struct wireless_dev *wdev, |
| 7005 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7006 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7007 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7008 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7009 | void *hdr; |
| 7010 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7011 | |
| 7012 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7013 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7014 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7015 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7016 | if (!hdr) |
| 7017 | return -1; |
| 7018 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7019 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7020 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7021 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7022 | goto nla_put_failure; |
| 7023 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7024 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7025 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7026 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7027 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7028 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7029 | |
| 7030 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7031 | if (!bss) |
| 7032 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7033 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7034 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7035 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7036 | |
| 7037 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7038 | /* indicate whether we have probe response data or not */ |
| 7039 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7040 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7041 | goto fail_unlock_rcu; |
| 7042 | |
| 7043 | /* this pointer prefers to be pointed to probe response data |
| 7044 | * but is always valid |
| 7045 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7046 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7047 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7048 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7049 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7050 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7051 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7052 | ies->len, ies->data)) |
| 7053 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7054 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7055 | |
| 7056 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7057 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7058 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7059 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7060 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7061 | goto fail_unlock_rcu; |
| 7062 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7063 | ies->len, ies->data)) |
| 7064 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7065 | } |
| 7066 | rcu_read_unlock(); |
| 7067 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7068 | if (res->beacon_interval && |
| 7069 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7070 | goto nla_put_failure; |
| 7071 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7072 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7073 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7074 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7075 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7076 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7077 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7078 | if (intbss->parent_tsf && |
| 7079 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7080 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7081 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7082 | intbss->parent_bssid))) |
| 7083 | goto nla_put_failure; |
| 7084 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7085 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7086 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7087 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7088 | goto nla_put_failure; |
| 7089 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7090 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7091 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7092 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7093 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7094 | break; |
| 7095 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7096 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7097 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7098 | break; |
| 7099 | default: |
| 7100 | break; |
| 7101 | } |
| 7102 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7103 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7104 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7105 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7106 | if (intbss == wdev->current_bss && |
| 7107 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7108 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7109 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7110 | break; |
| 7111 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7112 | if (intbss == wdev->current_bss && |
| 7113 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7114 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7115 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7116 | break; |
| 7117 | default: |
| 7118 | break; |
| 7119 | } |
| 7120 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7121 | nla_nest_end(msg, bss); |
| 7122 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7123 | genlmsg_end(msg, hdr); |
| 7124 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7125 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7126 | fail_unlock_rcu: |
| 7127 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7128 | nla_put_failure: |
| 7129 | genlmsg_cancel(msg, hdr); |
| 7130 | return -EMSGSIZE; |
| 7131 | } |
| 7132 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7133 | 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] | 7134 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7135 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7136 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7137 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7138 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7139 | int err; |
| 7140 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7141 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7142 | if (err) |
| 7143 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7144 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7145 | wdev_lock(wdev); |
| 7146 | spin_lock_bh(&rdev->bss_lock); |
| 7147 | cfg80211_bss_expire(rdev); |
| 7148 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7149 | cb->seq = rdev->bss_generation; |
| 7150 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7151 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7152 | if (++idx <= start) |
| 7153 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7154 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7155 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7156 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7157 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7158 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7159 | } |
| 7160 | } |
| 7161 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7162 | spin_unlock_bh(&rdev->bss_lock); |
| 7163 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7164 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7165 | cb->args[2] = idx; |
| 7166 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7167 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7168 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7169 | } |
| 7170 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7171 | 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] | 7172 | int flags, struct net_device *dev, |
| 7173 | bool allow_radio_stats, |
| 7174 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7175 | { |
| 7176 | void *hdr; |
| 7177 | struct nlattr *infoattr; |
| 7178 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7179 | /* skip radio stats if userspace didn't request them */ |
| 7180 | if (!survey->channel && !allow_radio_stats) |
| 7181 | return 0; |
| 7182 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7183 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7184 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7185 | if (!hdr) |
| 7186 | return -ENOMEM; |
| 7187 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7188 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7189 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7190 | |
| 7191 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7192 | if (!infoattr) |
| 7193 | goto nla_put_failure; |
| 7194 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7195 | if (survey->channel && |
| 7196 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7197 | survey->channel->center_freq)) |
| 7198 | goto nla_put_failure; |
| 7199 | |
| 7200 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7201 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7202 | goto nla_put_failure; |
| 7203 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7204 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7205 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7206 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7207 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7208 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7209 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7210 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7211 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7212 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7213 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7214 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7215 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7216 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7217 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7218 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7219 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7220 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7221 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7222 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7223 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7224 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7225 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7226 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7227 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7228 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7229 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7230 | |
| 7231 | nla_nest_end(msg, infoattr); |
| 7232 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7233 | genlmsg_end(msg, hdr); |
| 7234 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7235 | |
| 7236 | nla_put_failure: |
| 7237 | genlmsg_cancel(msg, hdr); |
| 7238 | return -EMSGSIZE; |
| 7239 | } |
| 7240 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7241 | 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] | 7242 | { |
| 7243 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7244 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7245 | struct wireless_dev *wdev; |
| 7246 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7247 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7248 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7249 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7250 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7251 | if (res) |
| 7252 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7253 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7254 | /* prepare_wdev_dump parsed the attributes */ |
| 7255 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 7256 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7257 | if (!wdev->netdev) { |
| 7258 | res = -EINVAL; |
| 7259 | goto out_err; |
| 7260 | } |
| 7261 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7262 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7263 | res = -EOPNOTSUPP; |
| 7264 | goto out_err; |
| 7265 | } |
| 7266 | |
| 7267 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7268 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7269 | if (res == -ENOENT) |
| 7270 | break; |
| 7271 | if (res) |
| 7272 | goto out_err; |
| 7273 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7274 | /* don't send disabled channels, but do send non-channel data */ |
| 7275 | if (survey.channel && |
| 7276 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7277 | survey_idx++; |
| 7278 | continue; |
| 7279 | } |
| 7280 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7281 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7282 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7283 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7284 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7285 | goto out; |
| 7286 | survey_idx++; |
| 7287 | } |
| 7288 | |
| 7289 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7290 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7291 | res = skb->len; |
| 7292 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7293 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7294 | return res; |
| 7295 | } |
| 7296 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7297 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7298 | { |
| 7299 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7300 | NL80211_WPA_VERSION_2)); |
| 7301 | } |
| 7302 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7303 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7304 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7306 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7307 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7308 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 7309 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7310 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7311 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7312 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7313 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7314 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7315 | return -EINVAL; |
| 7316 | |
| 7317 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7318 | return -EINVAL; |
| 7319 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7320 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7321 | return -EINVAL; |
| 7322 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7323 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7324 | return -EINVAL; |
| 7325 | |
| 7326 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7327 | return -EINVAL; |
| 7328 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7329 | err = nl80211_parse_key(info, &key); |
| 7330 | if (err) |
| 7331 | return err; |
| 7332 | |
| 7333 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7334 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7335 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7336 | if (!key.p.key || !key.p.key_len) |
| 7337 | return -EINVAL; |
| 7338 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7339 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7340 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7341 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7342 | return -EINVAL; |
| 7343 | if (key.idx > 4) |
| 7344 | return -EINVAL; |
| 7345 | } else { |
| 7346 | key.p.key_len = 0; |
| 7347 | key.p.key = NULL; |
| 7348 | } |
| 7349 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7350 | if (key.idx >= 0) { |
| 7351 | int i; |
| 7352 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7353 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7354 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7355 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7356 | ok = true; |
| 7357 | break; |
| 7358 | } |
| 7359 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7360 | if (!ok) |
| 7361 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7362 | } |
| 7363 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7364 | if (!rdev->ops->auth) |
| 7365 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7366 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7367 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7368 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7369 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7370 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7371 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7372 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7373 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7374 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7375 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7376 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7377 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7378 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7379 | |
| 7380 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7381 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7382 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7383 | } |
| 7384 | |
| 7385 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7386 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7387 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7388 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7389 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7390 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7391 | return -EINVAL; |
| 7392 | |
| 7393 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7394 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7395 | return -EINVAL; |
| 7396 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7397 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7398 | /* need to include at least Auth Transaction and Status Code */ |
| 7399 | if (sae_data_len < 4) |
| 7400 | return -EINVAL; |
| 7401 | } |
| 7402 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7403 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7404 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7405 | /* |
| 7406 | * Since we no longer track auth state, ignore |
| 7407 | * requests to only change local state. |
| 7408 | */ |
| 7409 | if (local_state_change) |
| 7410 | return 0; |
| 7411 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7412 | wdev_lock(dev->ieee80211_ptr); |
| 7413 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7414 | ssid, ssid_len, ie, ie_len, |
| 7415 | key.p.key, key.p.key_len, key.idx, |
| 7416 | sae_data, sae_data_len); |
| 7417 | wdev_unlock(dev->ieee80211_ptr); |
| 7418 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7419 | } |
| 7420 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7421 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7422 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7423 | struct cfg80211_crypto_settings *settings, |
| 7424 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7425 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7426 | memset(settings, 0, sizeof(*settings)); |
| 7427 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7428 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7429 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7430 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7431 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7432 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7433 | proto = nla_get_u16( |
| 7434 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7435 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7436 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7437 | proto != ETH_P_PAE) |
| 7438 | return -EINVAL; |
| 7439 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7440 | settings->control_port_no_encrypt = true; |
| 7441 | } else |
| 7442 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7443 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7444 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7445 | void *data; |
| 7446 | int len, i; |
| 7447 | |
| 7448 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7449 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7450 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7451 | |
| 7452 | if (len % sizeof(u32)) |
| 7453 | return -EINVAL; |
| 7454 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7455 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7456 | return -EINVAL; |
| 7457 | |
| 7458 | memcpy(settings->ciphers_pairwise, data, len); |
| 7459 | |
| 7460 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7461 | if (!cfg80211_supported_cipher_suite( |
| 7462 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7463 | settings->ciphers_pairwise[i])) |
| 7464 | return -EINVAL; |
| 7465 | } |
| 7466 | |
| 7467 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7468 | settings->cipher_group = |
| 7469 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7470 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7471 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7472 | return -EINVAL; |
| 7473 | } |
| 7474 | |
| 7475 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7476 | settings->wpa_versions = |
| 7477 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7478 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7479 | return -EINVAL; |
| 7480 | } |
| 7481 | |
| 7482 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7483 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7484 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7485 | |
| 7486 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7487 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7488 | settings->n_akm_suites = len / sizeof(u32); |
| 7489 | |
| 7490 | if (len % sizeof(u32)) |
| 7491 | return -EINVAL; |
| 7492 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7493 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7494 | return -EINVAL; |
| 7495 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7496 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | return 0; |
| 7500 | } |
| 7501 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7502 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7505 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7506 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7507 | struct cfg80211_assoc_request req = {}; |
| 7508 | const u8 *bssid, *ssid; |
| 7509 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7510 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7511 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7512 | return -EINVAL; |
| 7513 | |
| 7514 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7515 | !info->attrs[NL80211_ATTR_SSID] || |
| 7516 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7517 | return -EINVAL; |
| 7518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7519 | if (!rdev->ops->assoc) |
| 7520 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7521 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7522 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7523 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7524 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7525 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7526 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7527 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7528 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7529 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7530 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7531 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7532 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7533 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7534 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7535 | |
| 7536 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7537 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7538 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7539 | } |
| 7540 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7541 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7542 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7543 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7544 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7545 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7546 | else if (mfp != NL80211_MFP_NO) |
| 7547 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7548 | } |
| 7549 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7550 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7551 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7552 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7553 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7554 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7555 | |
| 7556 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7557 | memcpy(&req.ht_capa_mask, |
| 7558 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7559 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7560 | |
| 7561 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7562 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7563 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7564 | memcpy(&req.ht_capa, |
| 7565 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7566 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7569 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7570 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7571 | |
| 7572 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7573 | memcpy(&req.vht_capa_mask, |
| 7574 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7575 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7576 | |
| 7577 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7578 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7579 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7580 | memcpy(&req.vht_capa, |
| 7581 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7582 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7583 | } |
| 7584 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7585 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 7586 | if (!((rdev->wiphy.features & |
| 7587 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 7588 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 7589 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 7590 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7591 | return -EINVAL; |
| 7592 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7593 | } |
| 7594 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7595 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7596 | if (!err) { |
| 7597 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7598 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7599 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7600 | wdev_unlock(dev->ieee80211_ptr); |
| 7601 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7602 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7603 | return err; |
| 7604 | } |
| 7605 | |
| 7606 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7609 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7610 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7611 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7612 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7613 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7614 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7615 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7616 | return -EINVAL; |
| 7617 | |
| 7618 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7619 | return -EINVAL; |
| 7620 | |
| 7621 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7622 | return -EINVAL; |
| 7623 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7624 | if (!rdev->ops->deauth) |
| 7625 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7626 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7627 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7628 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7629 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7630 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7631 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7632 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7633 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7634 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7635 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7636 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7637 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7638 | |
| 7639 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7640 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7641 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7642 | } |
| 7643 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7644 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7645 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7646 | wdev_lock(dev->ieee80211_ptr); |
| 7647 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7648 | local_state_change); |
| 7649 | wdev_unlock(dev->ieee80211_ptr); |
| 7650 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7651 | } |
| 7652 | |
| 7653 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7654 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7656 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7657 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7658 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7659 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7660 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7661 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7662 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7663 | return -EINVAL; |
| 7664 | |
| 7665 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7666 | return -EINVAL; |
| 7667 | |
| 7668 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7669 | return -EINVAL; |
| 7670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7671 | if (!rdev->ops->disassoc) |
| 7672 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7673 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7676 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7677 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7678 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7679 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7680 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7681 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7682 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7683 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7684 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7685 | |
| 7686 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7687 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7688 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7689 | } |
| 7690 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7691 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7692 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7693 | wdev_lock(dev->ieee80211_ptr); |
| 7694 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7695 | local_state_change); |
| 7696 | wdev_unlock(dev->ieee80211_ptr); |
| 7697 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7698 | } |
| 7699 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7700 | static bool |
| 7701 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7702 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7703 | int rateval) |
| 7704 | { |
| 7705 | struct wiphy *wiphy = &rdev->wiphy; |
| 7706 | bool found = false; |
| 7707 | int band, i; |
| 7708 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7709 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7710 | struct ieee80211_supported_band *sband; |
| 7711 | |
| 7712 | sband = wiphy->bands[band]; |
| 7713 | if (!sband) |
| 7714 | continue; |
| 7715 | |
| 7716 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7717 | if (sband->bitrates[i].bitrate == rateval) { |
| 7718 | mcast_rate[band] = i + 1; |
| 7719 | found = true; |
| 7720 | break; |
| 7721 | } |
| 7722 | } |
| 7723 | } |
| 7724 | |
| 7725 | return found; |
| 7726 | } |
| 7727 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7728 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7731 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7732 | struct cfg80211_ibss_params ibss; |
| 7733 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7734 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7735 | int err; |
| 7736 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7737 | memset(&ibss, 0, sizeof(ibss)); |
| 7738 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7739 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7740 | return -EINVAL; |
| 7741 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7742 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7743 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7744 | return -EINVAL; |
| 7745 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7746 | ibss.beacon_interval = 100; |
| 7747 | |
| 7748 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7749 | ibss.beacon_interval = |
| 7750 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7751 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7752 | return -EINVAL; |
| 7753 | } |
| 7754 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7755 | if (!rdev->ops->join_ibss) |
| 7756 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7758 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7759 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7760 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7761 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7762 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7763 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7764 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7765 | |
| 7766 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7767 | return -EINVAL; |
| 7768 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7769 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7770 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7771 | |
| 7772 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7773 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7774 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7775 | } |
| 7776 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7777 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7778 | if (err) |
| 7779 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7780 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7781 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7782 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7783 | return -EINVAL; |
| 7784 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7785 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7786 | case NL80211_CHAN_WIDTH_5: |
| 7787 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7788 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7789 | break; |
| 7790 | case NL80211_CHAN_WIDTH_20: |
| 7791 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7792 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7793 | return -EINVAL; |
| 7794 | break; |
| 7795 | case NL80211_CHAN_WIDTH_80: |
| 7796 | case NL80211_CHAN_WIDTH_80P80: |
| 7797 | case NL80211_CHAN_WIDTH_160: |
| 7798 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7799 | return -EINVAL; |
| 7800 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7801 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7802 | return -EINVAL; |
| 7803 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7804 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7805 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7806 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7807 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7808 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7809 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7810 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7811 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7812 | u8 *rates = |
| 7813 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7814 | int n_rates = |
| 7815 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7816 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7817 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7818 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7819 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7820 | &ibss.basic_rates); |
| 7821 | if (err) |
| 7822 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7823 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7824 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7825 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7826 | memcpy(&ibss.ht_capa_mask, |
| 7827 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7828 | sizeof(ibss.ht_capa_mask)); |
| 7829 | |
| 7830 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7831 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7832 | return -EINVAL; |
| 7833 | memcpy(&ibss.ht_capa, |
| 7834 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7835 | sizeof(ibss.ht_capa)); |
| 7836 | } |
| 7837 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7838 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7839 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7840 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7841 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7843 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7844 | bool no_ht = false; |
| 7845 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7846 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7847 | info->attrs[NL80211_ATTR_KEYS], |
| 7848 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7849 | if (IS_ERR(connkeys)) |
| 7850 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7851 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7852 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7853 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 7854 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7855 | return -EINVAL; |
| 7856 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7857 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7858 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7859 | ibss.control_port = |
| 7860 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7861 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7862 | ibss.userspace_handles_dfs = |
| 7863 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7864 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7865 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7866 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7867 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7868 | return err; |
| 7869 | } |
| 7870 | |
| 7871 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7872 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7874 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7876 | if (!rdev->ops->leave_ibss) |
| 7877 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7878 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7880 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7882 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7883 | } |
| 7884 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7885 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7886 | { |
| 7887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7888 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7889 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7890 | u32 nla_rate; |
| 7891 | int err; |
| 7892 | |
| 7893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7894 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7895 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7896 | return -EOPNOTSUPP; |
| 7897 | |
| 7898 | if (!rdev->ops->set_mcast_rate) |
| 7899 | return -EOPNOTSUPP; |
| 7900 | |
| 7901 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7902 | |
| 7903 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7904 | return -EINVAL; |
| 7905 | |
| 7906 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7907 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7908 | return -EINVAL; |
| 7909 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7910 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7911 | |
| 7912 | return err; |
| 7913 | } |
| 7914 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7915 | static struct sk_buff * |
| 7916 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7917 | struct wireless_dev *wdev, int approxlen, |
| 7918 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7919 | enum nl80211_attrs attr, |
| 7920 | const struct nl80211_vendor_cmd_info *info, |
| 7921 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7922 | { |
| 7923 | struct sk_buff *skb; |
| 7924 | void *hdr; |
| 7925 | struct nlattr *data; |
| 7926 | |
| 7927 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7928 | if (!skb) |
| 7929 | return NULL; |
| 7930 | |
| 7931 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7932 | if (!hdr) { |
| 7933 | kfree_skb(skb); |
| 7934 | return NULL; |
| 7935 | } |
| 7936 | |
| 7937 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7938 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7939 | |
| 7940 | if (info) { |
| 7941 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7942 | info->vendor_id)) |
| 7943 | goto nla_put_failure; |
| 7944 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7945 | info->subcmd)) |
| 7946 | goto nla_put_failure; |
| 7947 | } |
| 7948 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7949 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7950 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 7951 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7952 | goto nla_put_failure; |
| 7953 | if (wdev->netdev && |
| 7954 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7955 | wdev->netdev->ifindex)) |
| 7956 | goto nla_put_failure; |
| 7957 | } |
| 7958 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7959 | data = nla_nest_start(skb, attr); |
| 7960 | |
| 7961 | ((void **)skb->cb)[0] = rdev; |
| 7962 | ((void **)skb->cb)[1] = hdr; |
| 7963 | ((void **)skb->cb)[2] = data; |
| 7964 | |
| 7965 | return skb; |
| 7966 | |
| 7967 | nla_put_failure: |
| 7968 | kfree_skb(skb); |
| 7969 | return NULL; |
| 7970 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7971 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7972 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7973 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7974 | enum nl80211_commands cmd, |
| 7975 | enum nl80211_attrs attr, |
| 7976 | int vendor_event_idx, |
| 7977 | int approxlen, gfp_t gfp) |
| 7978 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7979 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7980 | const struct nl80211_vendor_cmd_info *info; |
| 7981 | |
| 7982 | switch (cmd) { |
| 7983 | case NL80211_CMD_TESTMODE: |
| 7984 | if (WARN_ON(vendor_event_idx != -1)) |
| 7985 | return NULL; |
| 7986 | info = NULL; |
| 7987 | break; |
| 7988 | case NL80211_CMD_VENDOR: |
| 7989 | if (WARN_ON(vendor_event_idx < 0 || |
| 7990 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7991 | return NULL; |
| 7992 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7993 | break; |
| 7994 | default: |
| 7995 | WARN_ON(1); |
| 7996 | return NULL; |
| 7997 | } |
| 7998 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7999 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8000 | cmd, attr, info, gfp); |
| 8001 | } |
| 8002 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8003 | |
| 8004 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8005 | { |
| 8006 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8007 | void *hdr = ((void **)skb->cb)[1]; |
| 8008 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8009 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8010 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8011 | /* clear CB data for netlink core to own from now on */ |
| 8012 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8013 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8014 | nla_nest_end(skb, data); |
| 8015 | genlmsg_end(skb, hdr); |
| 8016 | |
| 8017 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8018 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8019 | |
| 8020 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8021 | mcgrp, gfp); |
| 8022 | } |
| 8023 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8024 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8025 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8026 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8027 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8029 | struct wireless_dev *wdev = |
| 8030 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8031 | int err; |
| 8032 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8033 | if (!rdev->ops->testmode_cmd) |
| 8034 | return -EOPNOTSUPP; |
| 8035 | |
| 8036 | if (IS_ERR(wdev)) { |
| 8037 | err = PTR_ERR(wdev); |
| 8038 | if (err != -EINVAL) |
| 8039 | return err; |
| 8040 | wdev = NULL; |
| 8041 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8042 | return -EINVAL; |
| 8043 | } |
| 8044 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8045 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8046 | return -EINVAL; |
| 8047 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8048 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8049 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8050 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8051 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8052 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8053 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8054 | return err; |
| 8055 | } |
| 8056 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8057 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8058 | struct netlink_callback *cb) |
| 8059 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8060 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8061 | int err; |
| 8062 | long phy_idx; |
| 8063 | void *data = NULL; |
| 8064 | int data_len = 0; |
| 8065 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8066 | rtnl_lock(); |
| 8067 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8068 | if (cb->args[0]) { |
| 8069 | /* |
| 8070 | * 0 is a valid index, but not valid for args[0], |
| 8071 | * so we need to offset by 1. |
| 8072 | */ |
| 8073 | phy_idx = cb->args[0] - 1; |
| 8074 | } else { |
| 8075 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 8076 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 8077 | nl80211_policy); |
| 8078 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8079 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8080 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8081 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 8082 | nl80211_fam.attrbuf); |
| 8083 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8084 | err = PTR_ERR(rdev); |
| 8085 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8086 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8087 | phy_idx = rdev->wiphy_idx; |
| 8088 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8089 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8090 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 8091 | cb->args[1] = |
| 8092 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 8093 | } |
| 8094 | |
| 8095 | if (cb->args[1]) { |
| 8096 | data = nla_data((void *)cb->args[1]); |
| 8097 | data_len = nla_len((void *)cb->args[1]); |
| 8098 | } |
| 8099 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8100 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8101 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8102 | err = -ENOENT; |
| 8103 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8104 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8105 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8106 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8107 | err = -EOPNOTSUPP; |
| 8108 | goto out_err; |
| 8109 | } |
| 8110 | |
| 8111 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8112 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8113 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8114 | NL80211_CMD_TESTMODE); |
| 8115 | struct nlattr *tmdata; |
| 8116 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8117 | if (!hdr) |
| 8118 | break; |
| 8119 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8120 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8121 | genlmsg_cancel(skb, hdr); |
| 8122 | break; |
| 8123 | } |
| 8124 | |
| 8125 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8126 | if (!tmdata) { |
| 8127 | genlmsg_cancel(skb, hdr); |
| 8128 | break; |
| 8129 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8130 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8131 | nla_nest_end(skb, tmdata); |
| 8132 | |
| 8133 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8134 | genlmsg_cancel(skb, hdr); |
| 8135 | break; |
| 8136 | } else if (err) { |
| 8137 | genlmsg_cancel(skb, hdr); |
| 8138 | goto out_err; |
| 8139 | } |
| 8140 | |
| 8141 | genlmsg_end(skb, hdr); |
| 8142 | } |
| 8143 | |
| 8144 | err = skb->len; |
| 8145 | /* see above */ |
| 8146 | cb->args[0] = phy_idx + 1; |
| 8147 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8148 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8149 | return err; |
| 8150 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8151 | #endif |
| 8152 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8153 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8154 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8156 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8157 | struct cfg80211_connect_params connect; |
| 8158 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8159 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8160 | int err; |
| 8161 | |
| 8162 | memset(&connect, 0, sizeof(connect)); |
| 8163 | |
| 8164 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8165 | return -EINVAL; |
| 8166 | |
| 8167 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8168 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8169 | return -EINVAL; |
| 8170 | |
| 8171 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8172 | connect.auth_type = |
| 8173 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8174 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8175 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8176 | return -EINVAL; |
| 8177 | } else |
| 8178 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8179 | |
| 8180 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8181 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8182 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8183 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8184 | if (err) |
| 8185 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8186 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8187 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8188 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8189 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8190 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8191 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8192 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8193 | connect.bg_scan_period = -1; |
| 8194 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8195 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8196 | connect.bg_scan_period = |
| 8197 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8198 | } |
| 8199 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8200 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8201 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8202 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8203 | connect.bssid_hint = |
| 8204 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8205 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8206 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8207 | |
| 8208 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8209 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8210 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8211 | } |
| 8212 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8213 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8214 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8215 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8216 | connect.mfp != NL80211_MFP_NO) |
| 8217 | return -EINVAL; |
| 8218 | } else { |
| 8219 | connect.mfp = NL80211_MFP_NO; |
| 8220 | } |
| 8221 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8222 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8223 | connect.prev_bssid = |
| 8224 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8225 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8226 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8227 | connect.channel = nl80211_get_valid_chan( |
| 8228 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8229 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8230 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8231 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8232 | connect.channel_hint = nl80211_get_valid_chan( |
| 8233 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8234 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8235 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8236 | } |
| 8237 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8238 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8239 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8240 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8241 | if (IS_ERR(connkeys)) |
| 8242 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8243 | } |
| 8244 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8245 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8246 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8247 | |
| 8248 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8249 | memcpy(&connect.ht_capa_mask, |
| 8250 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8251 | sizeof(connect.ht_capa_mask)); |
| 8252 | |
| 8253 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8254 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8255 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8256 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8257 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8258 | memcpy(&connect.ht_capa, |
| 8259 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8260 | sizeof(connect.ht_capa)); |
| 8261 | } |
| 8262 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8263 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8264 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8265 | |
| 8266 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8267 | memcpy(&connect.vht_capa_mask, |
| 8268 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8269 | sizeof(connect.vht_capa_mask)); |
| 8270 | |
| 8271 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8272 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8273 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8274 | return -EINVAL; |
| 8275 | } |
| 8276 | memcpy(&connect.vht_capa, |
| 8277 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8278 | sizeof(connect.vht_capa)); |
| 8279 | } |
| 8280 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8281 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8282 | if (!((rdev->wiphy.features & |
| 8283 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8284 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8285 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8286 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8287 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8288 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8289 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8290 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8291 | } |
| 8292 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8293 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8294 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8295 | kzfree(connkeys); |
| 8296 | return -EOPNOTSUPP; |
| 8297 | } |
| 8298 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8299 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8300 | /* bss selection makes no sense if bssid is set */ |
| 8301 | if (connect.bssid) { |
| 8302 | kzfree(connkeys); |
| 8303 | return -EINVAL; |
| 8304 | } |
| 8305 | |
| 8306 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8307 | wiphy, &connect.bss_select); |
| 8308 | if (err) { |
| 8309 | kzfree(connkeys); |
| 8310 | return err; |
| 8311 | } |
| 8312 | } |
| 8313 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8314 | wdev_lock(dev->ieee80211_ptr); |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8315 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8316 | connect.prev_bssid); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8317 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8318 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8319 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8320 | return err; |
| 8321 | } |
| 8322 | |
| 8323 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8324 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8326 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8327 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8328 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8329 | |
| 8330 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8331 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8332 | else |
| 8333 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8334 | |
| 8335 | if (reason == 0) |
| 8336 | return -EINVAL; |
| 8337 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8338 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8339 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8340 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8341 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8342 | wdev_lock(dev->ieee80211_ptr); |
| 8343 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8344 | wdev_unlock(dev->ieee80211_ptr); |
| 8345 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8346 | } |
| 8347 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8348 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8351 | struct net *net; |
| 8352 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8353 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8354 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8355 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8356 | |
| 8357 | net = get_net_ns_by_pid(pid); |
| 8358 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8359 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8360 | |
| 8361 | net = get_net_ns_by_fd(fd); |
| 8362 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8363 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8364 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8365 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8366 | if (IS_ERR(net)) |
| 8367 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8368 | |
| 8369 | err = 0; |
| 8370 | |
| 8371 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8372 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8373 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8374 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8375 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8376 | return err; |
| 8377 | } |
| 8378 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8379 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8380 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8382 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8383 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8384 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8385 | struct cfg80211_pmksa pmksa; |
| 8386 | |
| 8387 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8388 | |
| 8389 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8390 | return -EINVAL; |
| 8391 | |
| 8392 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8393 | return -EINVAL; |
| 8394 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8395 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8396 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8397 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8398 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8399 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8400 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8401 | |
| 8402 | switch (info->genlhdr->cmd) { |
| 8403 | case NL80211_CMD_SET_PMKSA: |
| 8404 | rdev_ops = rdev->ops->set_pmksa; |
| 8405 | break; |
| 8406 | case NL80211_CMD_DEL_PMKSA: |
| 8407 | rdev_ops = rdev->ops->del_pmksa; |
| 8408 | break; |
| 8409 | default: |
| 8410 | WARN_ON(1); |
| 8411 | break; |
| 8412 | } |
| 8413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8414 | if (!rdev_ops) |
| 8415 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8416 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8417 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8418 | } |
| 8419 | |
| 8420 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8421 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8423 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8424 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8425 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8426 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8427 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8428 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8429 | if (!rdev->ops->flush_pmksa) |
| 8430 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8431 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8432 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8433 | } |
| 8434 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8435 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8436 | { |
| 8437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8438 | struct net_device *dev = info->user_ptr[1]; |
| 8439 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8440 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8441 | u16 status_code; |
| 8442 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8443 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8444 | |
| 8445 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8446 | !rdev->ops->tdls_mgmt) |
| 8447 | return -EOPNOTSUPP; |
| 8448 | |
| 8449 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8450 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8451 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8452 | !info->attrs[NL80211_ATTR_IE] || |
| 8453 | !info->attrs[NL80211_ATTR_MAC]) |
| 8454 | return -EINVAL; |
| 8455 | |
| 8456 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8457 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8458 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8459 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8460 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8461 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8462 | peer_capability = |
| 8463 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8464 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8465 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8466 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8467 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8468 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8469 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8470 | } |
| 8471 | |
| 8472 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8473 | { |
| 8474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8475 | struct net_device *dev = info->user_ptr[1]; |
| 8476 | enum nl80211_tdls_operation operation; |
| 8477 | u8 *peer; |
| 8478 | |
| 8479 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8480 | !rdev->ops->tdls_oper) |
| 8481 | return -EOPNOTSUPP; |
| 8482 | |
| 8483 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8484 | !info->attrs[NL80211_ATTR_MAC]) |
| 8485 | return -EINVAL; |
| 8486 | |
| 8487 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8488 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8489 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8490 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8491 | } |
| 8492 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8493 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8494 | struct genl_info *info) |
| 8495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8497 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8498 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8499 | struct sk_buff *msg; |
| 8500 | void *hdr; |
| 8501 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8502 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8503 | int err; |
| 8504 | |
| 8505 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8506 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8507 | return -EINVAL; |
| 8508 | |
| 8509 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8510 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8511 | if (!rdev->ops->remain_on_channel || |
| 8512 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8513 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8514 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8515 | /* |
| 8516 | * We should be on that channel for at least a minimum amount of |
| 8517 | * time (10ms) but no longer than the driver supports. |
| 8518 | */ |
| 8519 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8520 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8521 | return -EINVAL; |
| 8522 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8523 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8524 | if (err) |
| 8525 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8526 | |
| 8527 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8528 | if (!msg) |
| 8529 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8530 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8531 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8532 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8533 | if (!hdr) { |
| 8534 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8535 | goto free_msg; |
| 8536 | } |
| 8537 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8538 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8539 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8540 | |
| 8541 | if (err) |
| 8542 | goto free_msg; |
| 8543 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8544 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8545 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8546 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8547 | |
| 8548 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8549 | |
| 8550 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8551 | |
| 8552 | nla_put_failure: |
| 8553 | err = -ENOBUFS; |
| 8554 | free_msg: |
| 8555 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8556 | return err; |
| 8557 | } |
| 8558 | |
| 8559 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8560 | struct genl_info *info) |
| 8561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8563 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8564 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8565 | |
| 8566 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8567 | return -EINVAL; |
| 8568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8569 | if (!rdev->ops->cancel_remain_on_channel) |
| 8570 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8571 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8572 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8573 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8574 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8575 | } |
| 8576 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8577 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8578 | u8 *rates, u8 rates_len) |
| 8579 | { |
| 8580 | u8 i; |
| 8581 | u32 mask = 0; |
| 8582 | |
| 8583 | for (i = 0; i < rates_len; i++) { |
| 8584 | int rate = (rates[i] & 0x7f) * 5; |
| 8585 | int ridx; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8586 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8587 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8588 | struct ieee80211_rate *srate = |
| 8589 | &sband->bitrates[ridx]; |
| 8590 | if (rate == srate->bitrate) { |
| 8591 | mask |= 1 << ridx; |
| 8592 | break; |
| 8593 | } |
| 8594 | } |
| 8595 | if (ridx == sband->n_bitrates) |
| 8596 | return 0; /* rate not found */ |
| 8597 | } |
| 8598 | |
| 8599 | return mask; |
| 8600 | } |
| 8601 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8602 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8603 | u8 *rates, u8 rates_len, |
| 8604 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8605 | { |
| 8606 | u8 i; |
| 8607 | |
| 8608 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8609 | |
| 8610 | for (i = 0; i < rates_len; i++) { |
| 8611 | int ridx, rbit; |
| 8612 | |
| 8613 | ridx = rates[i] / 8; |
| 8614 | rbit = BIT(rates[i] % 8); |
| 8615 | |
| 8616 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8617 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8618 | return false; |
| 8619 | |
| 8620 | /* check availability */ |
| 8621 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8622 | mcs[ridx] |= rbit; |
| 8623 | else |
| 8624 | return false; |
| 8625 | } |
| 8626 | |
| 8627 | return true; |
| 8628 | } |
| 8629 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8630 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8631 | { |
| 8632 | u16 mcs_mask = 0; |
| 8633 | |
| 8634 | switch (vht_mcs_map) { |
| 8635 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8636 | break; |
| 8637 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8638 | mcs_mask = 0x00FF; |
| 8639 | break; |
| 8640 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8641 | mcs_mask = 0x01FF; |
| 8642 | break; |
| 8643 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8644 | mcs_mask = 0x03FF; |
| 8645 | break; |
| 8646 | default: |
| 8647 | break; |
| 8648 | } |
| 8649 | |
| 8650 | return mcs_mask; |
| 8651 | } |
| 8652 | |
| 8653 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8654 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8655 | { |
| 8656 | u8 nss; |
| 8657 | |
| 8658 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8659 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8660 | vht_mcs_map >>= 2; |
| 8661 | } |
| 8662 | } |
| 8663 | |
| 8664 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8665 | struct nl80211_txrate_vht *txrate, |
| 8666 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8667 | { |
| 8668 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8669 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8670 | u8 i; |
| 8671 | |
| 8672 | if (!sband->vht_cap.vht_supported) |
| 8673 | return false; |
| 8674 | |
| 8675 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8676 | |
| 8677 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8678 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8679 | |
| 8680 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8681 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8682 | mcs[i] = txrate->mcs[i]; |
| 8683 | else |
| 8684 | return false; |
| 8685 | } |
| 8686 | |
| 8687 | return true; |
| 8688 | } |
| 8689 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8690 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8691 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8692 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8693 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8694 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8695 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8696 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8697 | }; |
| 8698 | |
| 8699 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8700 | struct genl_info *info) |
| 8701 | { |
| 8702 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8704 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8705 | int rem, i; |
| 8706 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8707 | struct nlattr *tx_rates; |
| 8708 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8709 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8711 | if (!rdev->ops->set_bitrate_mask) |
| 8712 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8713 | |
| 8714 | memset(&mask, 0, sizeof(mask)); |
| 8715 | /* Default to all rates enabled */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8716 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8717 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8718 | |
| 8719 | if (!sband) |
| 8720 | continue; |
| 8721 | |
| 8722 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8723 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8724 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8725 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8726 | |
| 8727 | if (!sband->vht_cap.vht_supported) |
| 8728 | continue; |
| 8729 | |
| 8730 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8731 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8732 | } |
| 8733 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8734 | /* if no rates are given set it back to the defaults */ |
| 8735 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8736 | goto out; |
| 8737 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8738 | /* |
| 8739 | * The nested attribute uses enum nl80211_band as the index. This maps |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8740 | * directly to the enum nl80211_band values used in cfg80211. |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8741 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8742 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8743 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8744 | enum nl80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8745 | int err; |
| 8746 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8747 | if (band < 0 || band >= NUM_NL80211_BANDS) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8748 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8749 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8750 | if (sband == NULL) |
| 8751 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8752 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8753 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8754 | if (err) |
| 8755 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8756 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8757 | mask.control[band].legacy = rateset_to_mask( |
| 8758 | sband, |
| 8759 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8760 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8761 | if ((mask.control[band].legacy == 0) && |
| 8762 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8763 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8764 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8765 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8766 | if (!ht_rateset_to_mask( |
| 8767 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8768 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8769 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8770 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8771 | return -EINVAL; |
| 8772 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8773 | if (tb[NL80211_TXRATE_VHT]) { |
| 8774 | if (!vht_set_mcs_mask( |
| 8775 | sband, |
| 8776 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8777 | mask.control[band].vht_mcs)) |
| 8778 | return -EINVAL; |
| 8779 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8780 | if (tb[NL80211_TXRATE_GI]) { |
| 8781 | mask.control[band].gi = |
| 8782 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8783 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8784 | return -EINVAL; |
| 8785 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8786 | |
| 8787 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8788 | /* don't allow empty legacy rates if HT or VHT |
| 8789 | * are not even supported. |
| 8790 | */ |
| 8791 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8792 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8793 | return -EINVAL; |
| 8794 | |
| 8795 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8796 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8797 | goto out; |
| 8798 | |
| 8799 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8800 | if (mask.control[band].vht_mcs[i]) |
| 8801 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8802 | |
| 8803 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8804 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8805 | } |
| 8806 | } |
| 8807 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8808 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8809 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8810 | } |
| 8811 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8812 | 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] | 8813 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8815 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8816 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8817 | |
| 8818 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8819 | return -EINVAL; |
| 8820 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8821 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8822 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8823 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8824 | switch (wdev->iftype) { |
| 8825 | case NL80211_IFTYPE_STATION: |
| 8826 | case NL80211_IFTYPE_ADHOC: |
| 8827 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8828 | case NL80211_IFTYPE_AP: |
| 8829 | case NL80211_IFTYPE_AP_VLAN: |
| 8830 | case NL80211_IFTYPE_MESH_POINT: |
| 8831 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8832 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8833 | break; |
| 8834 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8835 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8836 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8837 | |
| 8838 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8839 | if (!rdev->ops->mgmt_tx) |
| 8840 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8841 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8842 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8843 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8844 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8845 | } |
| 8846 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8847 | 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] | 8848 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8850 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8851 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8852 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8853 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8854 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8855 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8856 | struct cfg80211_mgmt_tx_params params = { |
| 8857 | .dont_wait_for_ack = |
| 8858 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8859 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8860 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8861 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8862 | return -EINVAL; |
| 8863 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8864 | if (!rdev->ops->mgmt_tx) |
| 8865 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8866 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8867 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8868 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8869 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8870 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8871 | case NL80211_IFTYPE_STATION: |
| 8872 | case NL80211_IFTYPE_ADHOC: |
| 8873 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8874 | case NL80211_IFTYPE_AP: |
| 8875 | case NL80211_IFTYPE_AP_VLAN: |
| 8876 | case NL80211_IFTYPE_MESH_POINT: |
| 8877 | case NL80211_IFTYPE_P2P_GO: |
| 8878 | break; |
| 8879 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8880 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8881 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8882 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8883 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8884 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8885 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8886 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8887 | |
| 8888 | /* |
| 8889 | * We should wait on the channel for at least a minimum amount |
| 8890 | * of time (10ms) but no longer than the driver supports. |
| 8891 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8892 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8893 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8894 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8895 | } |
| 8896 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8897 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8898 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8899 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8900 | return -EINVAL; |
| 8901 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8902 | 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] | 8903 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8904 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8905 | * the driver. The latter will use the current one |
| 8906 | */ |
| 8907 | chandef.chan = NULL; |
| 8908 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8909 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8910 | if (err) |
| 8911 | return err; |
| 8912 | } |
| 8913 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8914 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8915 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8916 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8917 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8918 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8919 | |
| 8920 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8921 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8922 | int i; |
| 8923 | |
| 8924 | if (len % sizeof(u16)) |
| 8925 | return -EINVAL; |
| 8926 | |
| 8927 | params.n_csa_offsets = len / sizeof(u16); |
| 8928 | params.csa_offsets = |
| 8929 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8930 | |
| 8931 | /* check that all the offsets fit the frame */ |
| 8932 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8933 | if (params.csa_offsets[i] >= params.len) |
| 8934 | return -EINVAL; |
| 8935 | } |
| 8936 | } |
| 8937 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8938 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8940 | if (!msg) |
| 8941 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8942 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8943 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8944 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8945 | if (!hdr) { |
| 8946 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8947 | goto free_msg; |
| 8948 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8949 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8950 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8951 | params.chan = chandef.chan; |
| 8952 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8953 | if (err) |
| 8954 | goto free_msg; |
| 8955 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8956 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8957 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8958 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8959 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8960 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8961 | genlmsg_end(msg, hdr); |
| 8962 | return genlmsg_reply(msg, info); |
| 8963 | } |
| 8964 | |
| 8965 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8966 | |
| 8967 | nla_put_failure: |
| 8968 | err = -ENOBUFS; |
| 8969 | free_msg: |
| 8970 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8971 | return err; |
| 8972 | } |
| 8973 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8974 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8975 | { |
| 8976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8977 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8978 | u64 cookie; |
| 8979 | |
| 8980 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8981 | return -EINVAL; |
| 8982 | |
| 8983 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8984 | return -EOPNOTSUPP; |
| 8985 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8986 | switch (wdev->iftype) { |
| 8987 | case NL80211_IFTYPE_STATION: |
| 8988 | case NL80211_IFTYPE_ADHOC: |
| 8989 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8990 | case NL80211_IFTYPE_AP: |
| 8991 | case NL80211_IFTYPE_AP_VLAN: |
| 8992 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8993 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8994 | break; |
| 8995 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8996 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8997 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8998 | |
| 8999 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9000 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9001 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9002 | } |
| 9003 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9004 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9005 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9007 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9008 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9009 | u8 ps_state; |
| 9010 | bool state; |
| 9011 | int err; |
| 9012 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9013 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9014 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9015 | |
| 9016 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9018 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9019 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9020 | |
| 9021 | wdev = dev->ieee80211_ptr; |
| 9022 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9023 | if (!rdev->ops->set_power_mgmt) |
| 9024 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9025 | |
| 9026 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9027 | |
| 9028 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9029 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9030 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9031 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9032 | if (!err) |
| 9033 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9034 | return err; |
| 9035 | } |
| 9036 | |
| 9037 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9038 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9039 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9040 | enum nl80211_ps_state ps_state; |
| 9041 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9042 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9043 | struct sk_buff *msg; |
| 9044 | void *hdr; |
| 9045 | int err; |
| 9046 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9047 | wdev = dev->ieee80211_ptr; |
| 9048 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9049 | if (!rdev->ops->set_power_mgmt) |
| 9050 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9051 | |
| 9052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9053 | if (!msg) |
| 9054 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9055 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9056 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9057 | NL80211_CMD_GET_POWER_SAVE); |
| 9058 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9059 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9060 | goto free_msg; |
| 9061 | } |
| 9062 | |
| 9063 | if (wdev->ps) |
| 9064 | ps_state = NL80211_PS_ENABLED; |
| 9065 | else |
| 9066 | ps_state = NL80211_PS_DISABLED; |
| 9067 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9068 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9069 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9070 | |
| 9071 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9072 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9073 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9074 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9075 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9076 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9077 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9078 | return err; |
| 9079 | } |
| 9080 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9081 | static const struct nla_policy |
| 9082 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9083 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9084 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9085 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9086 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9087 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9088 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9089 | }; |
| 9090 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9091 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9092 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9093 | { |
| 9094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9095 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9096 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9097 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9098 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9099 | return -EINVAL; |
| 9100 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9101 | if (!rdev->ops->set_cqm_txe_config) |
| 9102 | return -EOPNOTSUPP; |
| 9103 | |
| 9104 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9105 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9106 | return -EOPNOTSUPP; |
| 9107 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9108 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9109 | } |
| 9110 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9111 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9112 | s32 threshold, u32 hysteresis) |
| 9113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9115 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9116 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9117 | |
| 9118 | if (threshold > 0) |
| 9119 | return -EINVAL; |
| 9120 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9121 | /* disabling - hysteresis should also be zero then */ |
| 9122 | if (threshold == 0) |
| 9123 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9124 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9125 | if (!rdev->ops->set_cqm_rssi_config) |
| 9126 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9127 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9128 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9129 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9130 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9131 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9132 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9133 | } |
| 9134 | |
| 9135 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9136 | { |
| 9137 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9138 | struct nlattr *cqm; |
| 9139 | int err; |
| 9140 | |
| 9141 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9142 | if (!cqm) |
| 9143 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9144 | |
| 9145 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9146 | nl80211_attr_cqm_policy); |
| 9147 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9148 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9149 | |
| 9150 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9151 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9152 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9153 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9154 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9155 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9156 | } |
| 9157 | |
| 9158 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9159 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9160 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9161 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9162 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9163 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9164 | |
| 9165 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9166 | } |
| 9167 | |
| 9168 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9169 | } |
| 9170 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9171 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9172 | { |
| 9173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9174 | struct net_device *dev = info->user_ptr[1]; |
| 9175 | struct ocb_setup setup = {}; |
| 9176 | int err; |
| 9177 | |
| 9178 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9179 | if (err) |
| 9180 | return err; |
| 9181 | |
| 9182 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9183 | } |
| 9184 | |
| 9185 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9186 | { |
| 9187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9188 | struct net_device *dev = info->user_ptr[1]; |
| 9189 | |
| 9190 | return cfg80211_leave_ocb(rdev, dev); |
| 9191 | } |
| 9192 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9193 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9194 | { |
| 9195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9196 | struct net_device *dev = info->user_ptr[1]; |
| 9197 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9198 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9199 | int err; |
| 9200 | |
| 9201 | /* start with default */ |
| 9202 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9203 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9204 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9205 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9206 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9207 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9208 | if (err) |
| 9209 | return err; |
| 9210 | } |
| 9211 | |
| 9212 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9213 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9214 | return -EINVAL; |
| 9215 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9216 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9217 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9218 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9219 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9220 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9221 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9222 | return -EINVAL; |
| 9223 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9224 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9225 | setup.beacon_interval = |
| 9226 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 9227 | if (setup.beacon_interval < 10 || |
| 9228 | setup.beacon_interval > 10000) |
| 9229 | return -EINVAL; |
| 9230 | } |
| 9231 | |
| 9232 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9233 | setup.dtim_period = |
| 9234 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9235 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9236 | return -EINVAL; |
| 9237 | } |
| 9238 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9239 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9240 | /* parse additional setup parameters if given */ |
| 9241 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9242 | if (err) |
| 9243 | return err; |
| 9244 | } |
| 9245 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9246 | if (setup.user_mpm) |
| 9247 | cfg.auto_open_plinks = false; |
| 9248 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9249 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9250 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9251 | if (err) |
| 9252 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9253 | } else { |
| 9254 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9255 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9256 | } |
| 9257 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9258 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9259 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9260 | int n_rates = |
| 9261 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9262 | struct ieee80211_supported_band *sband; |
| 9263 | |
| 9264 | if (!setup.chandef.chan) |
| 9265 | return -EINVAL; |
| 9266 | |
| 9267 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9268 | |
| 9269 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9270 | &setup.basic_rates); |
| 9271 | if (err) |
| 9272 | return err; |
| 9273 | } |
| 9274 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9275 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9276 | } |
| 9277 | |
| 9278 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9279 | { |
| 9280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9281 | struct net_device *dev = info->user_ptr[1]; |
| 9282 | |
| 9283 | return cfg80211_leave_mesh(rdev, dev); |
| 9284 | } |
| 9285 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9286 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9287 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9288 | struct cfg80211_registered_device *rdev) |
| 9289 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9290 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9291 | struct nlattr *nl_pats, *nl_pat; |
| 9292 | int i, pat_len; |
| 9293 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9294 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9295 | return 0; |
| 9296 | |
| 9297 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9298 | if (!nl_pats) |
| 9299 | return -ENOBUFS; |
| 9300 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9301 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9302 | nl_pat = nla_nest_start(msg, i + 1); |
| 9303 | if (!nl_pat) |
| 9304 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9305 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9306 | 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] | 9307 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9308 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9309 | wowlan->patterns[i].pattern) || |
| 9310 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9311 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9312 | return -ENOBUFS; |
| 9313 | nla_nest_end(msg, nl_pat); |
| 9314 | } |
| 9315 | nla_nest_end(msg, nl_pats); |
| 9316 | |
| 9317 | return 0; |
| 9318 | } |
| 9319 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9320 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9321 | struct cfg80211_wowlan_tcp *tcp) |
| 9322 | { |
| 9323 | struct nlattr *nl_tcp; |
| 9324 | |
| 9325 | if (!tcp) |
| 9326 | return 0; |
| 9327 | |
| 9328 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9329 | if (!nl_tcp) |
| 9330 | return -ENOBUFS; |
| 9331 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9332 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9333 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9334 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9335 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9336 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9337 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9338 | tcp->payload_len, tcp->payload) || |
| 9339 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9340 | tcp->data_interval) || |
| 9341 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9342 | tcp->wake_len, tcp->wake_data) || |
| 9343 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9344 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9345 | return -ENOBUFS; |
| 9346 | |
| 9347 | if (tcp->payload_seq.len && |
| 9348 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9349 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9350 | return -ENOBUFS; |
| 9351 | |
| 9352 | if (tcp->payload_tok.len && |
| 9353 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9354 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9355 | &tcp->payload_tok)) |
| 9356 | return -ENOBUFS; |
| 9357 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9358 | nla_nest_end(msg, nl_tcp); |
| 9359 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9360 | return 0; |
| 9361 | } |
| 9362 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9363 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9364 | struct cfg80211_sched_scan_request *req) |
| 9365 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9366 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9367 | int i; |
| 9368 | |
| 9369 | if (!req) |
| 9370 | return 0; |
| 9371 | |
| 9372 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9373 | if (!nd) |
| 9374 | return -ENOBUFS; |
| 9375 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9376 | if (req->n_scan_plans == 1 && |
| 9377 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9378 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9379 | return -ENOBUFS; |
| 9380 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9381 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9382 | return -ENOBUFS; |
| 9383 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9384 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9385 | if (!freqs) |
| 9386 | return -ENOBUFS; |
| 9387 | |
| 9388 | for (i = 0; i < req->n_channels; i++) |
| 9389 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 9390 | |
| 9391 | nla_nest_end(msg, freqs); |
| 9392 | |
| 9393 | if (req->n_match_sets) { |
| 9394 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 9395 | for (i = 0; i < req->n_match_sets; i++) { |
| 9396 | match = nla_nest_start(msg, i); |
| 9397 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9398 | req->match_sets[i].ssid.ssid_len, |
| 9399 | req->match_sets[i].ssid.ssid); |
| 9400 | nla_nest_end(msg, match); |
| 9401 | } |
| 9402 | nla_nest_end(msg, matches); |
| 9403 | } |
| 9404 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9405 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9406 | if (!scan_plans) |
| 9407 | return -ENOBUFS; |
| 9408 | |
| 9409 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9410 | scan_plan = nla_nest_start(msg, i + 1); |
| 9411 | if (!scan_plan || |
| 9412 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9413 | req->scan_plans[i].interval) || |
| 9414 | (req->scan_plans[i].iterations && |
| 9415 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9416 | req->scan_plans[i].iterations))) |
| 9417 | return -ENOBUFS; |
| 9418 | nla_nest_end(msg, scan_plan); |
| 9419 | } |
| 9420 | nla_nest_end(msg, scan_plans); |
| 9421 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9422 | nla_nest_end(msg, nd); |
| 9423 | |
| 9424 | return 0; |
| 9425 | } |
| 9426 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9427 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9428 | { |
| 9429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9430 | struct sk_buff *msg; |
| 9431 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9432 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9433 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9434 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9435 | return -EOPNOTSUPP; |
| 9436 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9437 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9438 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9439 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9440 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9441 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9442 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9443 | } |
| 9444 | |
| 9445 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9446 | if (!msg) |
| 9447 | return -ENOMEM; |
| 9448 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9449 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9450 | NL80211_CMD_GET_WOWLAN); |
| 9451 | if (!hdr) |
| 9452 | goto nla_put_failure; |
| 9453 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9454 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9455 | struct nlattr *nl_wowlan; |
| 9456 | |
| 9457 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9458 | if (!nl_wowlan) |
| 9459 | goto nla_put_failure; |
| 9460 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9461 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9462 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9463 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9465 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9466 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9467 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9468 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9469 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9470 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9471 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9472 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9473 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9474 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9475 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9476 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9477 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9478 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9479 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9480 | if (nl80211_send_wowlan_tcp(msg, |
| 9481 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9482 | goto nla_put_failure; |
| 9483 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9484 | if (nl80211_send_wowlan_nd( |
| 9485 | msg, |
| 9486 | rdev->wiphy.wowlan_config->nd_config)) |
| 9487 | goto nla_put_failure; |
| 9488 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9489 | nla_nest_end(msg, nl_wowlan); |
| 9490 | } |
| 9491 | |
| 9492 | genlmsg_end(msg, hdr); |
| 9493 | return genlmsg_reply(msg, info); |
| 9494 | |
| 9495 | nla_put_failure: |
| 9496 | nlmsg_free(msg); |
| 9497 | return -ENOBUFS; |
| 9498 | } |
| 9499 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9500 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9501 | struct nlattr *attr, |
| 9502 | struct cfg80211_wowlan *trig) |
| 9503 | { |
| 9504 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9505 | struct cfg80211_wowlan_tcp *cfg; |
| 9506 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9507 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9508 | u32 size; |
| 9509 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9510 | int err, port; |
| 9511 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9512 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9513 | return -EINVAL; |
| 9514 | |
| 9515 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9516 | nla_data(attr), nla_len(attr), |
| 9517 | nl80211_wowlan_tcp_policy); |
| 9518 | if (err) |
| 9519 | return err; |
| 9520 | |
| 9521 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9522 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9523 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9524 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9525 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9526 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9527 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9528 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9529 | return -EINVAL; |
| 9530 | |
| 9531 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9532 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9533 | return -EINVAL; |
| 9534 | |
| 9535 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9536 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9537 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9538 | return -EINVAL; |
| 9539 | |
| 9540 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9541 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9542 | return -EINVAL; |
| 9543 | |
| 9544 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9545 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9546 | return -EINVAL; |
| 9547 | |
| 9548 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9549 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9550 | |
| 9551 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9552 | tokens_size = tokln - sizeof(*tok); |
| 9553 | |
| 9554 | if (!tok->len || tokens_size % tok->len) |
| 9555 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9556 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9557 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9558 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9559 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9560 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9561 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9562 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9563 | return -EINVAL; |
| 9564 | if (tok->offset + tok->len > data_size) |
| 9565 | return -EINVAL; |
| 9566 | } |
| 9567 | |
| 9568 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9569 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9570 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9571 | return -EINVAL; |
| 9572 | if (seq->len == 0 || seq->len > 4) |
| 9573 | return -EINVAL; |
| 9574 | if (seq->len + seq->offset > data_size) |
| 9575 | return -EINVAL; |
| 9576 | } |
| 9577 | |
| 9578 | size = sizeof(*cfg); |
| 9579 | size += data_size; |
| 9580 | size += wake_size + wake_mask_size; |
| 9581 | size += tokens_size; |
| 9582 | |
| 9583 | cfg = kzalloc(size, GFP_KERNEL); |
| 9584 | if (!cfg) |
| 9585 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9586 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9587 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9588 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9589 | ETH_ALEN); |
| 9590 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9591 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9592 | else |
| 9593 | port = 0; |
| 9594 | #ifdef CONFIG_INET |
| 9595 | /* allocate a socket and port for it and use it */ |
| 9596 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9597 | IPPROTO_TCP, &cfg->sock, 1); |
| 9598 | if (err) { |
| 9599 | kfree(cfg); |
| 9600 | return err; |
| 9601 | } |
| 9602 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9603 | sock_release(cfg->sock); |
| 9604 | kfree(cfg); |
| 9605 | return -EADDRINUSE; |
| 9606 | } |
| 9607 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9608 | #else |
| 9609 | if (!port) { |
| 9610 | kfree(cfg); |
| 9611 | return -EINVAL; |
| 9612 | } |
| 9613 | cfg->src_port = port; |
| 9614 | #endif |
| 9615 | |
| 9616 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9617 | cfg->payload_len = data_size; |
| 9618 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9619 | memcpy((void *)cfg->payload, |
| 9620 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9621 | data_size); |
| 9622 | if (seq) |
| 9623 | cfg->payload_seq = *seq; |
| 9624 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9625 | cfg->wake_len = wake_size; |
| 9626 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9627 | memcpy((void *)cfg->wake_data, |
| 9628 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9629 | wake_size); |
| 9630 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9631 | data_size + wake_size; |
| 9632 | memcpy((void *)cfg->wake_mask, |
| 9633 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9634 | wake_mask_size); |
| 9635 | if (tok) { |
| 9636 | cfg->tokens_size = tokens_size; |
| 9637 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9638 | } |
| 9639 | |
| 9640 | trig->tcp = cfg; |
| 9641 | |
| 9642 | return 0; |
| 9643 | } |
| 9644 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9645 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9646 | const struct wiphy_wowlan_support *wowlan, |
| 9647 | struct nlattr *attr, |
| 9648 | struct cfg80211_wowlan *trig) |
| 9649 | { |
| 9650 | struct nlattr **tb; |
| 9651 | int err; |
| 9652 | |
| 9653 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9654 | if (!tb) |
| 9655 | return -ENOMEM; |
| 9656 | |
| 9657 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9658 | err = -EOPNOTSUPP; |
| 9659 | goto out; |
| 9660 | } |
| 9661 | |
| 9662 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9663 | nla_data(attr), nla_len(attr), |
| 9664 | nl80211_policy); |
| 9665 | if (err) |
| 9666 | goto out; |
| 9667 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9668 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9669 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9670 | if (err) |
| 9671 | trig->nd_config = NULL; |
| 9672 | |
| 9673 | out: |
| 9674 | kfree(tb); |
| 9675 | return err; |
| 9676 | } |
| 9677 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9678 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9679 | { |
| 9680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9681 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9682 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9683 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9684 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9685 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9686 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9687 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9688 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9689 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9690 | return -EOPNOTSUPP; |
| 9691 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9692 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9693 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9694 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9695 | goto set_wakeup; |
| 9696 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9697 | |
| 9698 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9699 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9700 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9701 | nl80211_wowlan_policy); |
| 9702 | if (err) |
| 9703 | return err; |
| 9704 | |
| 9705 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9706 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9707 | return -EINVAL; |
| 9708 | new_triggers.any = true; |
| 9709 | } |
| 9710 | |
| 9711 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9712 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9713 | return -EINVAL; |
| 9714 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9715 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9716 | } |
| 9717 | |
| 9718 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9719 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9720 | return -EINVAL; |
| 9721 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9722 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9723 | } |
| 9724 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9725 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9726 | return -EINVAL; |
| 9727 | |
| 9728 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9729 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9730 | return -EINVAL; |
| 9731 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9732 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9733 | } |
| 9734 | |
| 9735 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9736 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9737 | return -EINVAL; |
| 9738 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9739 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9740 | } |
| 9741 | |
| 9742 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9743 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9744 | return -EINVAL; |
| 9745 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9746 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9747 | } |
| 9748 | |
| 9749 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9750 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9751 | return -EINVAL; |
| 9752 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9753 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9754 | } |
| 9755 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9756 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9757 | struct nlattr *pat; |
| 9758 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9759 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9760 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9761 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9762 | regular = true; |
| 9763 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9764 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9765 | rem) |
| 9766 | n_patterns++; |
| 9767 | if (n_patterns > wowlan->n_patterns) |
| 9768 | return -EINVAL; |
| 9769 | |
| 9770 | new_triggers.patterns = kcalloc(n_patterns, |
| 9771 | sizeof(new_triggers.patterns[0]), |
| 9772 | GFP_KERNEL); |
| 9773 | if (!new_triggers.patterns) |
| 9774 | return -ENOMEM; |
| 9775 | |
| 9776 | new_triggers.n_patterns = n_patterns; |
| 9777 | i = 0; |
| 9778 | |
| 9779 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9780 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9781 | u8 *mask_pat; |
| 9782 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9783 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9784 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9785 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9786 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9787 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9788 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9789 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9790 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9791 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9792 | goto error; |
| 9793 | if (pat_len > wowlan->pattern_max_len || |
| 9794 | pat_len < wowlan->pattern_min_len) |
| 9795 | goto error; |
| 9796 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9797 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9798 | pkt_offset = 0; |
| 9799 | else |
| 9800 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9801 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9802 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9803 | goto error; |
| 9804 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9805 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9806 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9807 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9808 | err = -ENOMEM; |
| 9809 | goto error; |
| 9810 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9811 | new_triggers.patterns[i].mask = mask_pat; |
| 9812 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9813 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9814 | mask_pat += mask_len; |
| 9815 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9816 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9817 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9818 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9819 | pat_len); |
| 9820 | i++; |
| 9821 | } |
| 9822 | } |
| 9823 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9824 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9825 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9826 | err = nl80211_parse_wowlan_tcp( |
| 9827 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9828 | &new_triggers); |
| 9829 | if (err) |
| 9830 | goto error; |
| 9831 | } |
| 9832 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9833 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9834 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9835 | err = nl80211_parse_wowlan_nd( |
| 9836 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9837 | &new_triggers); |
| 9838 | if (err) |
| 9839 | goto error; |
| 9840 | } |
| 9841 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9842 | /* The 'any' trigger means the device continues operating more or less |
| 9843 | * as in its normal operation mode and wakes up the host on most of the |
| 9844 | * normal interrupts (like packet RX, ...) |
| 9845 | * It therefore makes little sense to combine with the more constrained |
| 9846 | * wakeup trigger modes. |
| 9847 | */ |
| 9848 | if (new_triggers.any && regular) { |
| 9849 | err = -EINVAL; |
| 9850 | goto error; |
| 9851 | } |
| 9852 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9853 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9854 | if (!ntrig) { |
| 9855 | err = -ENOMEM; |
| 9856 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9857 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9858 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9859 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9860 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9861 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9862 | if (rdev->ops->set_wakeup && |
| 9863 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9864 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9865 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9866 | return 0; |
| 9867 | error: |
| 9868 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9869 | kfree(new_triggers.patterns[i].mask); |
| 9870 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9871 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9872 | sock_release(new_triggers.tcp->sock); |
| 9873 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 9874 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9875 | return err; |
| 9876 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9877 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9878 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9879 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9880 | struct cfg80211_registered_device *rdev) |
| 9881 | { |
| 9882 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9883 | int i, j, pat_len; |
| 9884 | struct cfg80211_coalesce_rules *rule; |
| 9885 | |
| 9886 | if (!rdev->coalesce->n_rules) |
| 9887 | return 0; |
| 9888 | |
| 9889 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9890 | if (!nl_rules) |
| 9891 | return -ENOBUFS; |
| 9892 | |
| 9893 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9894 | nl_rule = nla_nest_start(msg, i + 1); |
| 9895 | if (!nl_rule) |
| 9896 | return -ENOBUFS; |
| 9897 | |
| 9898 | rule = &rdev->coalesce->rules[i]; |
| 9899 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9900 | rule->delay)) |
| 9901 | return -ENOBUFS; |
| 9902 | |
| 9903 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9904 | rule->condition)) |
| 9905 | return -ENOBUFS; |
| 9906 | |
| 9907 | nl_pats = nla_nest_start(msg, |
| 9908 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9909 | if (!nl_pats) |
| 9910 | return -ENOBUFS; |
| 9911 | |
| 9912 | for (j = 0; j < rule->n_patterns; j++) { |
| 9913 | nl_pat = nla_nest_start(msg, j + 1); |
| 9914 | if (!nl_pat) |
| 9915 | return -ENOBUFS; |
| 9916 | pat_len = rule->patterns[j].pattern_len; |
| 9917 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9918 | DIV_ROUND_UP(pat_len, 8), |
| 9919 | rule->patterns[j].mask) || |
| 9920 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9921 | rule->patterns[j].pattern) || |
| 9922 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9923 | rule->patterns[j].pkt_offset)) |
| 9924 | return -ENOBUFS; |
| 9925 | nla_nest_end(msg, nl_pat); |
| 9926 | } |
| 9927 | nla_nest_end(msg, nl_pats); |
| 9928 | nla_nest_end(msg, nl_rule); |
| 9929 | } |
| 9930 | nla_nest_end(msg, nl_rules); |
| 9931 | |
| 9932 | return 0; |
| 9933 | } |
| 9934 | |
| 9935 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9936 | { |
| 9937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9938 | struct sk_buff *msg; |
| 9939 | void *hdr; |
| 9940 | |
| 9941 | if (!rdev->wiphy.coalesce) |
| 9942 | return -EOPNOTSUPP; |
| 9943 | |
| 9944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9945 | if (!msg) |
| 9946 | return -ENOMEM; |
| 9947 | |
| 9948 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9949 | NL80211_CMD_GET_COALESCE); |
| 9950 | if (!hdr) |
| 9951 | goto nla_put_failure; |
| 9952 | |
| 9953 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9954 | goto nla_put_failure; |
| 9955 | |
| 9956 | genlmsg_end(msg, hdr); |
| 9957 | return genlmsg_reply(msg, info); |
| 9958 | |
| 9959 | nla_put_failure: |
| 9960 | nlmsg_free(msg); |
| 9961 | return -ENOBUFS; |
| 9962 | } |
| 9963 | |
| 9964 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9965 | { |
| 9966 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9967 | int i, j; |
| 9968 | struct cfg80211_coalesce_rules *rule; |
| 9969 | |
| 9970 | if (!coalesce) |
| 9971 | return; |
| 9972 | |
| 9973 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9974 | rule = &coalesce->rules[i]; |
| 9975 | for (j = 0; j < rule->n_patterns; j++) |
| 9976 | kfree(rule->patterns[j].mask); |
| 9977 | kfree(rule->patterns); |
| 9978 | } |
| 9979 | kfree(coalesce->rules); |
| 9980 | kfree(coalesce); |
| 9981 | rdev->coalesce = NULL; |
| 9982 | } |
| 9983 | |
| 9984 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9985 | struct nlattr *rule, |
| 9986 | struct cfg80211_coalesce_rules *new_rule) |
| 9987 | { |
| 9988 | int err, i; |
| 9989 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9990 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9991 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9992 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9993 | |
| 9994 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9995 | nla_len(rule), nl80211_coalesce_policy); |
| 9996 | if (err) |
| 9997 | return err; |
| 9998 | |
| 9999 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10000 | new_rule->delay = |
| 10001 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10002 | if (new_rule->delay > coalesce->max_delay) |
| 10003 | return -EINVAL; |
| 10004 | |
| 10005 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10006 | new_rule->condition = |
| 10007 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10008 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10009 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10010 | return -EINVAL; |
| 10011 | |
| 10012 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10013 | return -EINVAL; |
| 10014 | |
| 10015 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10016 | rem) |
| 10017 | n_patterns++; |
| 10018 | if (n_patterns > coalesce->n_patterns) |
| 10019 | return -EINVAL; |
| 10020 | |
| 10021 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10022 | GFP_KERNEL); |
| 10023 | if (!new_rule->patterns) |
| 10024 | return -ENOMEM; |
| 10025 | |
| 10026 | new_rule->n_patterns = n_patterns; |
| 10027 | i = 0; |
| 10028 | |
| 10029 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10030 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10031 | u8 *mask_pat; |
| 10032 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10033 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 10034 | nla_len(pat), NULL); |
| 10035 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10036 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10037 | return -EINVAL; |
| 10038 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10039 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10040 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10041 | return -EINVAL; |
| 10042 | if (pat_len > coalesce->pattern_max_len || |
| 10043 | pat_len < coalesce->pattern_min_len) |
| 10044 | return -EINVAL; |
| 10045 | |
| 10046 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10047 | pkt_offset = 0; |
| 10048 | else |
| 10049 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10050 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10051 | return -EINVAL; |
| 10052 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10053 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10054 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10055 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10056 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10057 | |
| 10058 | new_rule->patterns[i].mask = mask_pat; |
| 10059 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10060 | mask_len); |
| 10061 | |
| 10062 | mask_pat += mask_len; |
| 10063 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10064 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10065 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10066 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10067 | i++; |
| 10068 | } |
| 10069 | |
| 10070 | return 0; |
| 10071 | } |
| 10072 | |
| 10073 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10074 | { |
| 10075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10076 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10077 | struct cfg80211_coalesce new_coalesce = {}; |
| 10078 | struct cfg80211_coalesce *n_coalesce; |
| 10079 | int err, rem_rule, n_rules = 0, i, j; |
| 10080 | struct nlattr *rule; |
| 10081 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10082 | |
| 10083 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10084 | return -EOPNOTSUPP; |
| 10085 | |
| 10086 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10087 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10088 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10089 | return 0; |
| 10090 | } |
| 10091 | |
| 10092 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10093 | rem_rule) |
| 10094 | n_rules++; |
| 10095 | if (n_rules > coalesce->n_rules) |
| 10096 | return -EINVAL; |
| 10097 | |
| 10098 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10099 | GFP_KERNEL); |
| 10100 | if (!new_coalesce.rules) |
| 10101 | return -ENOMEM; |
| 10102 | |
| 10103 | new_coalesce.n_rules = n_rules; |
| 10104 | i = 0; |
| 10105 | |
| 10106 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10107 | rem_rule) { |
| 10108 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10109 | &new_coalesce.rules[i]); |
| 10110 | if (err) |
| 10111 | goto error; |
| 10112 | |
| 10113 | i++; |
| 10114 | } |
| 10115 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10116 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10117 | if (err) |
| 10118 | goto error; |
| 10119 | |
| 10120 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10121 | if (!n_coalesce) { |
| 10122 | err = -ENOMEM; |
| 10123 | goto error; |
| 10124 | } |
| 10125 | cfg80211_rdev_free_coalesce(rdev); |
| 10126 | rdev->coalesce = n_coalesce; |
| 10127 | |
| 10128 | return 0; |
| 10129 | error: |
| 10130 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10131 | tmp_rule = &new_coalesce.rules[i]; |
| 10132 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10133 | kfree(tmp_rule->patterns[j].mask); |
| 10134 | kfree(tmp_rule->patterns); |
| 10135 | } |
| 10136 | kfree(new_coalesce.rules); |
| 10137 | |
| 10138 | return err; |
| 10139 | } |
| 10140 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10141 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10142 | { |
| 10143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10144 | struct net_device *dev = info->user_ptr[1]; |
| 10145 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10146 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10147 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10148 | int err; |
| 10149 | |
| 10150 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10151 | return -EINVAL; |
| 10152 | |
| 10153 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 10154 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10155 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10156 | nl80211_rekey_policy); |
| 10157 | if (err) |
| 10158 | return err; |
| 10159 | |
| 10160 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10161 | return -ERANGE; |
| 10162 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10163 | return -ERANGE; |
| 10164 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10165 | return -ERANGE; |
| 10166 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10167 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10168 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10169 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10170 | |
| 10171 | wdev_lock(wdev); |
| 10172 | if (!wdev->current_bss) { |
| 10173 | err = -ENOTCONN; |
| 10174 | goto out; |
| 10175 | } |
| 10176 | |
| 10177 | if (!rdev->ops->set_rekey_data) { |
| 10178 | err = -EOPNOTSUPP; |
| 10179 | goto out; |
| 10180 | } |
| 10181 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10182 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10183 | out: |
| 10184 | wdev_unlock(wdev); |
| 10185 | return err; |
| 10186 | } |
| 10187 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10188 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10189 | struct genl_info *info) |
| 10190 | { |
| 10191 | struct net_device *dev = info->user_ptr[1]; |
| 10192 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10193 | |
| 10194 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10195 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10196 | return -EINVAL; |
| 10197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10198 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10199 | return -EBUSY; |
| 10200 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10201 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10202 | return 0; |
| 10203 | } |
| 10204 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10205 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10206 | struct genl_info *info) |
| 10207 | { |
| 10208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10209 | struct net_device *dev = info->user_ptr[1]; |
| 10210 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10211 | struct sk_buff *msg; |
| 10212 | void *hdr; |
| 10213 | const u8 *addr; |
| 10214 | u64 cookie; |
| 10215 | int err; |
| 10216 | |
| 10217 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10218 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10219 | return -EOPNOTSUPP; |
| 10220 | |
| 10221 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10222 | return -EINVAL; |
| 10223 | |
| 10224 | if (!rdev->ops->probe_client) |
| 10225 | return -EOPNOTSUPP; |
| 10226 | |
| 10227 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10228 | if (!msg) |
| 10229 | return -ENOMEM; |
| 10230 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10231 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10232 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10233 | if (!hdr) { |
| 10234 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10235 | goto free_msg; |
| 10236 | } |
| 10237 | |
| 10238 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10240 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10241 | if (err) |
| 10242 | goto free_msg; |
| 10243 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10244 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10245 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10246 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10247 | |
| 10248 | genlmsg_end(msg, hdr); |
| 10249 | |
| 10250 | return genlmsg_reply(msg, info); |
| 10251 | |
| 10252 | nla_put_failure: |
| 10253 | err = -ENOBUFS; |
| 10254 | free_msg: |
| 10255 | nlmsg_free(msg); |
| 10256 | return err; |
| 10257 | } |
| 10258 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10259 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10260 | { |
| 10261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10262 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10263 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10264 | |
| 10265 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10266 | return -EOPNOTSUPP; |
| 10267 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10268 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10269 | if (!nreg) |
| 10270 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10271 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10272 | /* First, check if already registered. */ |
| 10273 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10274 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10275 | if (reg->nlportid == info->snd_portid) { |
| 10276 | rv = -EALREADY; |
| 10277 | goto out_err; |
| 10278 | } |
| 10279 | } |
| 10280 | /* Add it to the list */ |
| 10281 | nreg->nlportid = info->snd_portid; |
| 10282 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10283 | |
| 10284 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10285 | |
| 10286 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10287 | out_err: |
| 10288 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10289 | kfree(nreg); |
| 10290 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10291 | } |
| 10292 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10293 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10294 | { |
| 10295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10296 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10297 | int err; |
| 10298 | |
| 10299 | if (!rdev->ops->start_p2p_device) |
| 10300 | return -EOPNOTSUPP; |
| 10301 | |
| 10302 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10303 | return -EOPNOTSUPP; |
| 10304 | |
| 10305 | if (wdev->p2p_started) |
| 10306 | return 0; |
| 10307 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10308 | if (rfkill_blocked(rdev->rfkill)) |
| 10309 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10310 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10311 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10312 | if (err) |
| 10313 | return err; |
| 10314 | |
| 10315 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10316 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10317 | |
| 10318 | return 0; |
| 10319 | } |
| 10320 | |
| 10321 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10322 | { |
| 10323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10324 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10325 | |
| 10326 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10327 | return -EOPNOTSUPP; |
| 10328 | |
| 10329 | if (!rdev->ops->stop_p2p_device) |
| 10330 | return -EOPNOTSUPP; |
| 10331 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10332 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10333 | |
| 10334 | return 0; |
| 10335 | } |
| 10336 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10337 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 10338 | struct genl_info *info) |
| 10339 | { |
| 10340 | void *hdr; |
| 10341 | struct sk_buff *msg; |
| 10342 | |
| 10343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10344 | if (!msg) |
| 10345 | return -ENOMEM; |
| 10346 | |
| 10347 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10348 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 10349 | if (!hdr) |
| 10350 | goto nla_put_failure; |
| 10351 | |
| 10352 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 10353 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 10354 | goto nla_put_failure; |
| 10355 | |
| 10356 | genlmsg_end(msg, hdr); |
| 10357 | return genlmsg_reply(msg, info); |
| 10358 | |
| 10359 | nla_put_failure: |
| 10360 | kfree_skb(msg); |
| 10361 | return -ENOBUFS; |
| 10362 | } |
| 10363 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10364 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 10365 | { |
| 10366 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10367 | struct cfg80211_update_ft_ies_params ft_params; |
| 10368 | struct net_device *dev = info->user_ptr[1]; |
| 10369 | |
| 10370 | if (!rdev->ops->update_ft_ies) |
| 10371 | return -EOPNOTSUPP; |
| 10372 | |
| 10373 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 10374 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 10375 | return -EINVAL; |
| 10376 | |
| 10377 | memset(&ft_params, 0, sizeof(ft_params)); |
| 10378 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 10379 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10380 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10381 | |
| 10382 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 10383 | } |
| 10384 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10385 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 10386 | struct genl_info *info) |
| 10387 | { |
| 10388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10389 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10390 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 10391 | u16 duration; |
| 10392 | int ret; |
| 10393 | |
| 10394 | if (!rdev->ops->crit_proto_start) |
| 10395 | return -EOPNOTSUPP; |
| 10396 | |
| 10397 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 10398 | return -EINVAL; |
| 10399 | |
| 10400 | if (rdev->crit_proto_nlportid) |
| 10401 | return -EBUSY; |
| 10402 | |
| 10403 | /* determine protocol if provided */ |
| 10404 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 10405 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 10406 | |
| 10407 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 10408 | return -EINVAL; |
| 10409 | |
| 10410 | /* timeout must be provided */ |
| 10411 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 10412 | return -EINVAL; |
| 10413 | |
| 10414 | duration = |
| 10415 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 10416 | |
| 10417 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 10418 | return -ERANGE; |
| 10419 | |
| 10420 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 10421 | if (!ret) |
| 10422 | rdev->crit_proto_nlportid = info->snd_portid; |
| 10423 | |
| 10424 | return ret; |
| 10425 | } |
| 10426 | |
| 10427 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 10428 | struct genl_info *info) |
| 10429 | { |
| 10430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10431 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10432 | |
| 10433 | if (!rdev->ops->crit_proto_stop) |
| 10434 | return -EOPNOTSUPP; |
| 10435 | |
| 10436 | if (rdev->crit_proto_nlportid) { |
| 10437 | rdev->crit_proto_nlportid = 0; |
| 10438 | rdev_crit_proto_stop(rdev, wdev); |
| 10439 | } |
| 10440 | return 0; |
| 10441 | } |
| 10442 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10443 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 10444 | { |
| 10445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10446 | struct wireless_dev *wdev = |
| 10447 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10448 | int i, err; |
| 10449 | u32 vid, subcmd; |
| 10450 | |
| 10451 | if (!rdev->wiphy.vendor_commands) |
| 10452 | return -EOPNOTSUPP; |
| 10453 | |
| 10454 | if (IS_ERR(wdev)) { |
| 10455 | err = PTR_ERR(wdev); |
| 10456 | if (err != -EINVAL) |
| 10457 | return err; |
| 10458 | wdev = NULL; |
| 10459 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10460 | return -EINVAL; |
| 10461 | } |
| 10462 | |
| 10463 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 10464 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 10465 | return -EINVAL; |
| 10466 | |
| 10467 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 10468 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10469 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 10470 | const struct wiphy_vendor_command *vcmd; |
| 10471 | void *data = NULL; |
| 10472 | int len = 0; |
| 10473 | |
| 10474 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 10475 | |
| 10476 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10477 | continue; |
| 10478 | |
| 10479 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10480 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10481 | if (!wdev) |
| 10482 | return -EINVAL; |
| 10483 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10484 | !wdev->netdev) |
| 10485 | return -EINVAL; |
| 10486 | |
| 10487 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10488 | if (wdev->netdev && |
| 10489 | !netif_running(wdev->netdev)) |
| 10490 | return -ENETDOWN; |
| 10491 | if (!wdev->netdev && !wdev->p2p_started) |
| 10492 | return -ENETDOWN; |
| 10493 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10494 | |
| 10495 | if (!vcmd->doit) |
| 10496 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10497 | } else { |
| 10498 | wdev = NULL; |
| 10499 | } |
| 10500 | |
| 10501 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 10502 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10503 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10504 | } |
| 10505 | |
| 10506 | rdev->cur_cmd_info = info; |
| 10507 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 10508 | data, len); |
| 10509 | rdev->cur_cmd_info = NULL; |
| 10510 | return err; |
| 10511 | } |
| 10512 | |
| 10513 | return -EOPNOTSUPP; |
| 10514 | } |
| 10515 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10516 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 10517 | struct netlink_callback *cb, |
| 10518 | struct cfg80211_registered_device **rdev, |
| 10519 | struct wireless_dev **wdev) |
| 10520 | { |
| 10521 | u32 vid, subcmd; |
| 10522 | unsigned int i; |
| 10523 | int vcmd_idx = -1; |
| 10524 | int err; |
| 10525 | void *data = NULL; |
| 10526 | unsigned int data_len = 0; |
| 10527 | |
| 10528 | rtnl_lock(); |
| 10529 | |
| 10530 | if (cb->args[0]) { |
| 10531 | /* subtract the 1 again here */ |
| 10532 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 10533 | struct wireless_dev *tmp; |
| 10534 | |
| 10535 | if (!wiphy) { |
| 10536 | err = -ENODEV; |
| 10537 | goto out_unlock; |
| 10538 | } |
| 10539 | *rdev = wiphy_to_rdev(wiphy); |
| 10540 | *wdev = NULL; |
| 10541 | |
| 10542 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 10543 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10544 | if (tmp->identifier == cb->args[1] - 1) { |
| 10545 | *wdev = tmp; |
| 10546 | break; |
| 10547 | } |
| 10548 | } |
| 10549 | } |
| 10550 | |
| 10551 | /* keep rtnl locked in successful case */ |
| 10552 | return 0; |
| 10553 | } |
| 10554 | |
| 10555 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10556 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 10557 | nl80211_policy); |
| 10558 | if (err) |
| 10559 | goto out_unlock; |
| 10560 | |
| 10561 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 10562 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 10563 | err = -EINVAL; |
| 10564 | goto out_unlock; |
| 10565 | } |
| 10566 | |
| 10567 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 10568 | nl80211_fam.attrbuf); |
| 10569 | if (IS_ERR(*wdev)) |
| 10570 | *wdev = NULL; |
| 10571 | |
| 10572 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 10573 | nl80211_fam.attrbuf); |
| 10574 | if (IS_ERR(*rdev)) { |
| 10575 | err = PTR_ERR(*rdev); |
| 10576 | goto out_unlock; |
| 10577 | } |
| 10578 | |
| 10579 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 10580 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10581 | |
| 10582 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 10583 | const struct wiphy_vendor_command *vcmd; |
| 10584 | |
| 10585 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 10586 | |
| 10587 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10588 | continue; |
| 10589 | |
| 10590 | if (!vcmd->dumpit) { |
| 10591 | err = -EOPNOTSUPP; |
| 10592 | goto out_unlock; |
| 10593 | } |
| 10594 | |
| 10595 | vcmd_idx = i; |
| 10596 | break; |
| 10597 | } |
| 10598 | |
| 10599 | if (vcmd_idx < 0) { |
| 10600 | err = -EOPNOTSUPP; |
| 10601 | goto out_unlock; |
| 10602 | } |
| 10603 | |
| 10604 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 10605 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10606 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10607 | } |
| 10608 | |
| 10609 | /* 0 is the first index - add 1 to parse only once */ |
| 10610 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 10611 | /* add 1 to know if it was NULL */ |
| 10612 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 10613 | cb->args[2] = vcmd_idx; |
| 10614 | cb->args[3] = (unsigned long)data; |
| 10615 | cb->args[4] = data_len; |
| 10616 | |
| 10617 | /* keep rtnl locked in successful case */ |
| 10618 | return 0; |
| 10619 | out_unlock: |
| 10620 | rtnl_unlock(); |
| 10621 | return err; |
| 10622 | } |
| 10623 | |
| 10624 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 10625 | struct netlink_callback *cb) |
| 10626 | { |
| 10627 | struct cfg80211_registered_device *rdev; |
| 10628 | struct wireless_dev *wdev; |
| 10629 | unsigned int vcmd_idx; |
| 10630 | const struct wiphy_vendor_command *vcmd; |
| 10631 | void *data; |
| 10632 | int data_len; |
| 10633 | int err; |
| 10634 | struct nlattr *vendor_data; |
| 10635 | |
| 10636 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 10637 | if (err) |
| 10638 | return err; |
| 10639 | |
| 10640 | vcmd_idx = cb->args[2]; |
| 10641 | data = (void *)cb->args[3]; |
| 10642 | data_len = cb->args[4]; |
| 10643 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 10644 | |
| 10645 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10646 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10647 | if (!wdev) |
| 10648 | return -EINVAL; |
| 10649 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10650 | !wdev->netdev) |
| 10651 | return -EINVAL; |
| 10652 | |
| 10653 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10654 | if (wdev->netdev && |
| 10655 | !netif_running(wdev->netdev)) |
| 10656 | return -ENETDOWN; |
| 10657 | if (!wdev->netdev && !wdev->p2p_started) |
| 10658 | return -ENETDOWN; |
| 10659 | } |
| 10660 | } |
| 10661 | |
| 10662 | while (1) { |
| 10663 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10664 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10665 | NL80211_CMD_VENDOR); |
| 10666 | if (!hdr) |
| 10667 | break; |
| 10668 | |
| 10669 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10670 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10671 | wdev_id(wdev), |
| 10672 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10673 | genlmsg_cancel(skb, hdr); |
| 10674 | break; |
| 10675 | } |
| 10676 | |
| 10677 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 10678 | if (!vendor_data) { |
| 10679 | genlmsg_cancel(skb, hdr); |
| 10680 | break; |
| 10681 | } |
| 10682 | |
| 10683 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 10684 | (unsigned long *)&cb->args[5]); |
| 10685 | nla_nest_end(skb, vendor_data); |
| 10686 | |
| 10687 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10688 | genlmsg_cancel(skb, hdr); |
| 10689 | break; |
| 10690 | } else if (err) { |
| 10691 | genlmsg_cancel(skb, hdr); |
| 10692 | goto out; |
| 10693 | } |
| 10694 | |
| 10695 | genlmsg_end(skb, hdr); |
| 10696 | } |
| 10697 | |
| 10698 | err = skb->len; |
| 10699 | out: |
| 10700 | rtnl_unlock(); |
| 10701 | return err; |
| 10702 | } |
| 10703 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10704 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 10705 | enum nl80211_commands cmd, |
| 10706 | enum nl80211_attrs attr, |
| 10707 | int approxlen) |
| 10708 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10709 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10710 | |
| 10711 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 10712 | return NULL; |
| 10713 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10714 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10715 | rdev->cur_cmd_info->snd_portid, |
| 10716 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10717 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10718 | } |
| 10719 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 10720 | |
| 10721 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 10722 | { |
| 10723 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10724 | void *hdr = ((void **)skb->cb)[1]; |
| 10725 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10726 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10727 | /* clear CB data for netlink core to own from now on */ |
| 10728 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10729 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10730 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 10731 | kfree_skb(skb); |
| 10732 | return -EINVAL; |
| 10733 | } |
| 10734 | |
| 10735 | nla_nest_end(skb, data); |
| 10736 | genlmsg_end(skb, hdr); |
| 10737 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 10738 | } |
| 10739 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 10740 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10741 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 10742 | struct genl_info *info) |
| 10743 | { |
| 10744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10745 | struct cfg80211_qos_map *qos_map = NULL; |
| 10746 | struct net_device *dev = info->user_ptr[1]; |
| 10747 | u8 *pos, len, num_des, des_len, des; |
| 10748 | int ret; |
| 10749 | |
| 10750 | if (!rdev->ops->set_qos_map) |
| 10751 | return -EOPNOTSUPP; |
| 10752 | |
| 10753 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10754 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10755 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10756 | |
| 10757 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10758 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10759 | return -EINVAL; |
| 10760 | |
| 10761 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10762 | if (!qos_map) |
| 10763 | return -ENOMEM; |
| 10764 | |
| 10765 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10766 | if (num_des) { |
| 10767 | des_len = num_des * |
| 10768 | sizeof(struct cfg80211_dscp_exception); |
| 10769 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10770 | qos_map->num_des = num_des; |
| 10771 | for (des = 0; des < num_des; des++) { |
| 10772 | if (qos_map->dscp_exception[des].up > 7) { |
| 10773 | kfree(qos_map); |
| 10774 | return -EINVAL; |
| 10775 | } |
| 10776 | } |
| 10777 | pos += des_len; |
| 10778 | } |
| 10779 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10780 | } |
| 10781 | |
| 10782 | wdev_lock(dev->ieee80211_ptr); |
| 10783 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10784 | if (!ret) |
| 10785 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10786 | wdev_unlock(dev->ieee80211_ptr); |
| 10787 | |
| 10788 | kfree(qos_map); |
| 10789 | return ret; |
| 10790 | } |
| 10791 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10792 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10793 | { |
| 10794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10795 | struct net_device *dev = info->user_ptr[1]; |
| 10796 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10797 | const u8 *peer; |
| 10798 | u8 tsid, up; |
| 10799 | u16 admitted_time = 0; |
| 10800 | int err; |
| 10801 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10802 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10803 | return -EOPNOTSUPP; |
| 10804 | |
| 10805 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10806 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10807 | return -EINVAL; |
| 10808 | |
| 10809 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10810 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10811 | return -EINVAL; |
| 10812 | |
| 10813 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10814 | if (up >= IEEE80211_NUM_UPS) |
| 10815 | return -EINVAL; |
| 10816 | |
| 10817 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10818 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10819 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10820 | * need more attributes for that (e.g. BA session requirement); |
| 10821 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10822 | */ |
| 10823 | return -EINVAL; |
| 10824 | } |
| 10825 | |
| 10826 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10827 | |
| 10828 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10829 | admitted_time = |
| 10830 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10831 | if (!admitted_time) |
| 10832 | return -EINVAL; |
| 10833 | } |
| 10834 | |
| 10835 | wdev_lock(wdev); |
| 10836 | switch (wdev->iftype) { |
| 10837 | case NL80211_IFTYPE_STATION: |
| 10838 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10839 | if (wdev->current_bss) |
| 10840 | break; |
| 10841 | err = -ENOTCONN; |
| 10842 | goto out; |
| 10843 | default: |
| 10844 | err = -EOPNOTSUPP; |
| 10845 | goto out; |
| 10846 | } |
| 10847 | |
| 10848 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10849 | |
| 10850 | out: |
| 10851 | wdev_unlock(wdev); |
| 10852 | return err; |
| 10853 | } |
| 10854 | |
| 10855 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10856 | { |
| 10857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10858 | struct net_device *dev = info->user_ptr[1]; |
| 10859 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10860 | const u8 *peer; |
| 10861 | u8 tsid; |
| 10862 | int err; |
| 10863 | |
| 10864 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10865 | return -EINVAL; |
| 10866 | |
| 10867 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10868 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10869 | |
| 10870 | wdev_lock(wdev); |
| 10871 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10872 | wdev_unlock(wdev); |
| 10873 | |
| 10874 | return err; |
| 10875 | } |
| 10876 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10877 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10878 | struct genl_info *info) |
| 10879 | { |
| 10880 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10881 | struct net_device *dev = info->user_ptr[1]; |
| 10882 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10883 | struct cfg80211_chan_def chandef = {}; |
| 10884 | const u8 *addr; |
| 10885 | u8 oper_class; |
| 10886 | int err; |
| 10887 | |
| 10888 | if (!rdev->ops->tdls_channel_switch || |
| 10889 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10890 | return -EOPNOTSUPP; |
| 10891 | |
| 10892 | switch (dev->ieee80211_ptr->iftype) { |
| 10893 | case NL80211_IFTYPE_STATION: |
| 10894 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10895 | break; |
| 10896 | default: |
| 10897 | return -EOPNOTSUPP; |
| 10898 | } |
| 10899 | |
| 10900 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10901 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10902 | return -EINVAL; |
| 10903 | |
| 10904 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10905 | if (err) |
| 10906 | return err; |
| 10907 | |
| 10908 | /* |
| 10909 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10910 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10911 | * specification is not defined for them. |
| 10912 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10913 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10914 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10915 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10916 | return -EINVAL; |
| 10917 | |
| 10918 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10919 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10920 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10921 | return -EINVAL; |
| 10922 | |
| 10923 | /* don't allow switching to DFS channels */ |
| 10924 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10925 | return -EINVAL; |
| 10926 | |
| 10927 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10928 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10929 | |
| 10930 | wdev_lock(wdev); |
| 10931 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10932 | wdev_unlock(wdev); |
| 10933 | |
| 10934 | return err; |
| 10935 | } |
| 10936 | |
| 10937 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10938 | struct genl_info *info) |
| 10939 | { |
| 10940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10941 | struct net_device *dev = info->user_ptr[1]; |
| 10942 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10943 | const u8 *addr; |
| 10944 | |
| 10945 | if (!rdev->ops->tdls_channel_switch || |
| 10946 | !rdev->ops->tdls_cancel_channel_switch || |
| 10947 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10948 | return -EOPNOTSUPP; |
| 10949 | |
| 10950 | switch (dev->ieee80211_ptr->iftype) { |
| 10951 | case NL80211_IFTYPE_STATION: |
| 10952 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10953 | break; |
| 10954 | default: |
| 10955 | return -EOPNOTSUPP; |
| 10956 | } |
| 10957 | |
| 10958 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10959 | return -EINVAL; |
| 10960 | |
| 10961 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10962 | |
| 10963 | wdev_lock(wdev); |
| 10964 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10965 | wdev_unlock(wdev); |
| 10966 | |
| 10967 | return 0; |
| 10968 | } |
| 10969 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10970 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10971 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10972 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10973 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10974 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10975 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10976 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10977 | /* 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] | 10978 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10979 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10980 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10981 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10982 | 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] | 10983 | struct genl_info *info) |
| 10984 | { |
| 10985 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10986 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10987 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10988 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10989 | |
| 10990 | if (rtnl) |
| 10991 | rtnl_lock(); |
| 10992 | |
| 10993 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10994 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10995 | if (IS_ERR(rdev)) { |
| 10996 | if (rtnl) |
| 10997 | rtnl_unlock(); |
| 10998 | return PTR_ERR(rdev); |
| 10999 | } |
| 11000 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11001 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 11002 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11003 | ASSERT_RTNL(); |
| 11004 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11005 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 11006 | info->attrs); |
| 11007 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11008 | if (rtnl) |
| 11009 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11010 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11011 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11012 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11013 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11014 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11015 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11016 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 11017 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11018 | if (rtnl) |
| 11019 | rtnl_unlock(); |
| 11020 | return -EINVAL; |
| 11021 | } |
| 11022 | |
| 11023 | info->user_ptr[1] = dev; |
| 11024 | } else { |
| 11025 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11026 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11027 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11028 | if (dev) { |
| 11029 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 11030 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11031 | if (rtnl) |
| 11032 | rtnl_unlock(); |
| 11033 | return -ENETDOWN; |
| 11034 | } |
| 11035 | |
| 11036 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11037 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 11038 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11039 | if (rtnl) |
| 11040 | rtnl_unlock(); |
| 11041 | return -ENETDOWN; |
| 11042 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11043 | } |
| 11044 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11045 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11046 | } |
| 11047 | |
| 11048 | return 0; |
| 11049 | } |
| 11050 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11051 | 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] | 11052 | struct genl_info *info) |
| 11053 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11054 | if (info->user_ptr[1]) { |
| 11055 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 11056 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11057 | |
| 11058 | if (wdev->netdev) |
| 11059 | dev_put(wdev->netdev); |
| 11060 | } else { |
| 11061 | dev_put(info->user_ptr[1]); |
| 11062 | } |
| 11063 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11064 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11065 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 11066 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11067 | |
| 11068 | /* If needed, clear the netlink message payload from the SKB |
| 11069 | * as it might contain key data that shouldn't stick around on |
| 11070 | * the heap after the SKB is freed. The netlink message header |
| 11071 | * is still needed for further processing, so leave it intact. |
| 11072 | */ |
| 11073 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 11074 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 11075 | |
| 11076 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 11077 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11078 | } |
| 11079 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 11080 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11081 | { |
| 11082 | .cmd = NL80211_CMD_GET_WIPHY, |
| 11083 | .doit = nl80211_get_wiphy, |
| 11084 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11085 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11086 | .policy = nl80211_policy, |
| 11087 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11088 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11089 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11090 | }, |
| 11091 | { |
| 11092 | .cmd = NL80211_CMD_SET_WIPHY, |
| 11093 | .doit = nl80211_set_wiphy, |
| 11094 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11095 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11096 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11097 | }, |
| 11098 | { |
| 11099 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 11100 | .doit = nl80211_get_interface, |
| 11101 | .dumpit = nl80211_dump_interface, |
| 11102 | .policy = nl80211_policy, |
| 11103 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11104 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11105 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11106 | }, |
| 11107 | { |
| 11108 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 11109 | .doit = nl80211_set_interface, |
| 11110 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11111 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11112 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11113 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11114 | }, |
| 11115 | { |
| 11116 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 11117 | .doit = nl80211_new_interface, |
| 11118 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11119 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11120 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11121 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11122 | }, |
| 11123 | { |
| 11124 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 11125 | .doit = nl80211_del_interface, |
| 11126 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11127 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 11128 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11129 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11130 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11131 | { |
| 11132 | .cmd = NL80211_CMD_GET_KEY, |
| 11133 | .doit = nl80211_get_key, |
| 11134 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11135 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11136 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11137 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11138 | }, |
| 11139 | { |
| 11140 | .cmd = NL80211_CMD_SET_KEY, |
| 11141 | .doit = nl80211_set_key, |
| 11142 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11143 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11144 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11145 | NL80211_FLAG_NEED_RTNL | |
| 11146 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11147 | }, |
| 11148 | { |
| 11149 | .cmd = NL80211_CMD_NEW_KEY, |
| 11150 | .doit = nl80211_new_key, |
| 11151 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11152 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11153 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11154 | NL80211_FLAG_NEED_RTNL | |
| 11155 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11156 | }, |
| 11157 | { |
| 11158 | .cmd = NL80211_CMD_DEL_KEY, |
| 11159 | .doit = nl80211_del_key, |
| 11160 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11161 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11162 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11163 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11164 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11165 | { |
| 11166 | .cmd = NL80211_CMD_SET_BEACON, |
| 11167 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11168 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11169 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11170 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11171 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11172 | }, |
| 11173 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11174 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11175 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11176 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11177 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11178 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11179 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11180 | }, |
| 11181 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11182 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11183 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11184 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11185 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11186 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11187 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11188 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11189 | { |
| 11190 | .cmd = NL80211_CMD_GET_STATION, |
| 11191 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11192 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11193 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11194 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11195 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11196 | }, |
| 11197 | { |
| 11198 | .cmd = NL80211_CMD_SET_STATION, |
| 11199 | .doit = nl80211_set_station, |
| 11200 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11201 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11202 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11203 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11204 | }, |
| 11205 | { |
| 11206 | .cmd = NL80211_CMD_NEW_STATION, |
| 11207 | .doit = nl80211_new_station, |
| 11208 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11209 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11211 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11212 | }, |
| 11213 | { |
| 11214 | .cmd = NL80211_CMD_DEL_STATION, |
| 11215 | .doit = nl80211_del_station, |
| 11216 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11217 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11219 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11220 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11221 | { |
| 11222 | .cmd = NL80211_CMD_GET_MPATH, |
| 11223 | .doit = nl80211_get_mpath, |
| 11224 | .dumpit = nl80211_dump_mpath, |
| 11225 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11226 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11228 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11229 | }, |
| 11230 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11231 | .cmd = NL80211_CMD_GET_MPP, |
| 11232 | .doit = nl80211_get_mpp, |
| 11233 | .dumpit = nl80211_dump_mpp, |
| 11234 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11235 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11237 | NL80211_FLAG_NEED_RTNL, |
| 11238 | }, |
| 11239 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11240 | .cmd = NL80211_CMD_SET_MPATH, |
| 11241 | .doit = nl80211_set_mpath, |
| 11242 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11243 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11244 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11245 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11246 | }, |
| 11247 | { |
| 11248 | .cmd = NL80211_CMD_NEW_MPATH, |
| 11249 | .doit = nl80211_new_mpath, |
| 11250 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11251 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11252 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11253 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11254 | }, |
| 11255 | { |
| 11256 | .cmd = NL80211_CMD_DEL_MPATH, |
| 11257 | .doit = nl80211_del_mpath, |
| 11258 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11259 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11260 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11261 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11262 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11263 | { |
| 11264 | .cmd = NL80211_CMD_SET_BSS, |
| 11265 | .doit = nl80211_set_bss, |
| 11266 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11267 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11268 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11269 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11270 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11271 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11272 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11273 | .doit = nl80211_get_reg_do, |
| 11274 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11275 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11276 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11277 | /* can be retrieved by unprivileged users */ |
| 11278 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11279 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11280 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11281 | .cmd = NL80211_CMD_SET_REG, |
| 11282 | .doit = nl80211_set_reg, |
| 11283 | .policy = nl80211_policy, |
| 11284 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11285 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11286 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11287 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11288 | { |
| 11289 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 11290 | .doit = nl80211_req_set_reg, |
| 11291 | .policy = nl80211_policy, |
| 11292 | .flags = GENL_ADMIN_PERM, |
| 11293 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11294 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11295 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 11296 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11297 | .policy = nl80211_policy, |
| 11298 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11299 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11300 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11301 | }, |
| 11302 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11303 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 11304 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11305 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11306 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11307 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11308 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11309 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 11310 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11311 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 11312 | .doit = nl80211_trigger_scan, |
| 11313 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11314 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11315 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11316 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11317 | }, |
| 11318 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11319 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 11320 | .doit = nl80211_abort_scan, |
| 11321 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11322 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11323 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11324 | NL80211_FLAG_NEED_RTNL, |
| 11325 | }, |
| 11326 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11327 | .cmd = NL80211_CMD_GET_SCAN, |
| 11328 | .policy = nl80211_policy, |
| 11329 | .dumpit = nl80211_dump_scan, |
| 11330 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11331 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11332 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 11333 | .doit = nl80211_start_sched_scan, |
| 11334 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11335 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11337 | NL80211_FLAG_NEED_RTNL, |
| 11338 | }, |
| 11339 | { |
| 11340 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 11341 | .doit = nl80211_stop_sched_scan, |
| 11342 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11343 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11345 | NL80211_FLAG_NEED_RTNL, |
| 11346 | }, |
| 11347 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11348 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 11349 | .doit = nl80211_authenticate, |
| 11350 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11351 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11353 | NL80211_FLAG_NEED_RTNL | |
| 11354 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11355 | }, |
| 11356 | { |
| 11357 | .cmd = NL80211_CMD_ASSOCIATE, |
| 11358 | .doit = nl80211_associate, |
| 11359 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11360 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11361 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11362 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11363 | }, |
| 11364 | { |
| 11365 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 11366 | .doit = nl80211_deauthenticate, |
| 11367 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11368 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11369 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11370 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11371 | }, |
| 11372 | { |
| 11373 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 11374 | .doit = nl80211_disassociate, |
| 11375 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11376 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11377 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11378 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11379 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11380 | { |
| 11381 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 11382 | .doit = nl80211_join_ibss, |
| 11383 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11384 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11385 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11386 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11387 | }, |
| 11388 | { |
| 11389 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 11390 | .doit = nl80211_leave_ibss, |
| 11391 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11392 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11393 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11394 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11395 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11396 | #ifdef CONFIG_NL80211_TESTMODE |
| 11397 | { |
| 11398 | .cmd = NL80211_CMD_TESTMODE, |
| 11399 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 11400 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11401 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11402 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11403 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11404 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11405 | }, |
| 11406 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11407 | { |
| 11408 | .cmd = NL80211_CMD_CONNECT, |
| 11409 | .doit = nl80211_connect, |
| 11410 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11411 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11412 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11413 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11414 | }, |
| 11415 | { |
| 11416 | .cmd = NL80211_CMD_DISCONNECT, |
| 11417 | .doit = nl80211_disconnect, |
| 11418 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11419 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11421 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11422 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11423 | { |
| 11424 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 11425 | .doit = nl80211_wiphy_netns, |
| 11426 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11427 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11428 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11429 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11430 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 11431 | { |
| 11432 | .cmd = NL80211_CMD_GET_SURVEY, |
| 11433 | .policy = nl80211_policy, |
| 11434 | .dumpit = nl80211_dump_survey, |
| 11435 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11436 | { |
| 11437 | .cmd = NL80211_CMD_SET_PMKSA, |
| 11438 | .doit = nl80211_setdel_pmksa, |
| 11439 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11440 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11442 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11443 | }, |
| 11444 | { |
| 11445 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 11446 | .doit = nl80211_setdel_pmksa, |
| 11447 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11448 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11450 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11451 | }, |
| 11452 | { |
| 11453 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 11454 | .doit = nl80211_flush_pmksa, |
| 11455 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11456 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11458 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11459 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11460 | { |
| 11461 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 11462 | .doit = nl80211_remain_on_channel, |
| 11463 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11464 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11465 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11466 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11467 | }, |
| 11468 | { |
| 11469 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 11470 | .doit = nl80211_cancel_remain_on_channel, |
| 11471 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11472 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11473 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11474 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11475 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11476 | { |
| 11477 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 11478 | .doit = nl80211_set_tx_bitrate_mask, |
| 11479 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11480 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11481 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11482 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11483 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11484 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11485 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 11486 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11487 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11488 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11489 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11490 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11491 | }, |
| 11492 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11493 | .cmd = NL80211_CMD_FRAME, |
| 11494 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11495 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11496 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11497 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11498 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11499 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11500 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11501 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 11502 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 11503 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11504 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11505 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11506 | NL80211_FLAG_NEED_RTNL, |
| 11507 | }, |
| 11508 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11509 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 11510 | .doit = nl80211_set_power_save, |
| 11511 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11512 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11513 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11514 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11515 | }, |
| 11516 | { |
| 11517 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 11518 | .doit = nl80211_get_power_save, |
| 11519 | .policy = nl80211_policy, |
| 11520 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11521 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11522 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11523 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11524 | { |
| 11525 | .cmd = NL80211_CMD_SET_CQM, |
| 11526 | .doit = nl80211_set_cqm, |
| 11527 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11528 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11529 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11530 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11531 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11532 | { |
| 11533 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 11534 | .doit = nl80211_set_channel, |
| 11535 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11536 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11537 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11538 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11539 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11540 | { |
| 11541 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 11542 | .doit = nl80211_set_wds_peer, |
| 11543 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11544 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 11545 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11546 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11547 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11548 | { |
| 11549 | .cmd = NL80211_CMD_JOIN_MESH, |
| 11550 | .doit = nl80211_join_mesh, |
| 11551 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11552 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11554 | NL80211_FLAG_NEED_RTNL, |
| 11555 | }, |
| 11556 | { |
| 11557 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 11558 | .doit = nl80211_leave_mesh, |
| 11559 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11560 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11562 | NL80211_FLAG_NEED_RTNL, |
| 11563 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11564 | { |
| 11565 | .cmd = NL80211_CMD_JOIN_OCB, |
| 11566 | .doit = nl80211_join_ocb, |
| 11567 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11568 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11569 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11570 | NL80211_FLAG_NEED_RTNL, |
| 11571 | }, |
| 11572 | { |
| 11573 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 11574 | .doit = nl80211_leave_ocb, |
| 11575 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11576 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11578 | NL80211_FLAG_NEED_RTNL, |
| 11579 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11580 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11581 | { |
| 11582 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 11583 | .doit = nl80211_get_wowlan, |
| 11584 | .policy = nl80211_policy, |
| 11585 | /* can be retrieved by unprivileged users */ |
| 11586 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11587 | NL80211_FLAG_NEED_RTNL, |
| 11588 | }, |
| 11589 | { |
| 11590 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 11591 | .doit = nl80211_set_wowlan, |
| 11592 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11593 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11594 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11595 | NL80211_FLAG_NEED_RTNL, |
| 11596 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11597 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11598 | { |
| 11599 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 11600 | .doit = nl80211_set_rekey_data, |
| 11601 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11602 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11604 | NL80211_FLAG_NEED_RTNL | |
| 11605 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11606 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11607 | { |
| 11608 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 11609 | .doit = nl80211_tdls_mgmt, |
| 11610 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11611 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11613 | NL80211_FLAG_NEED_RTNL, |
| 11614 | }, |
| 11615 | { |
| 11616 | .cmd = NL80211_CMD_TDLS_OPER, |
| 11617 | .doit = nl80211_tdls_oper, |
| 11618 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11619 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11621 | NL80211_FLAG_NEED_RTNL, |
| 11622 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11623 | { |
| 11624 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 11625 | .doit = nl80211_register_unexpected_frame, |
| 11626 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11627 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11628 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11629 | NL80211_FLAG_NEED_RTNL, |
| 11630 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11631 | { |
| 11632 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 11633 | .doit = nl80211_probe_client, |
| 11634 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11635 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11636 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11637 | NL80211_FLAG_NEED_RTNL, |
| 11638 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11639 | { |
| 11640 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 11641 | .doit = nl80211_register_beacons, |
| 11642 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11643 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11644 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11645 | NL80211_FLAG_NEED_RTNL, |
| 11646 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11647 | { |
| 11648 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 11649 | .doit = nl80211_set_noack_map, |
| 11650 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11651 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11652 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11653 | NL80211_FLAG_NEED_RTNL, |
| 11654 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11655 | { |
| 11656 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 11657 | .doit = nl80211_start_p2p_device, |
| 11658 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11659 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11660 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11661 | NL80211_FLAG_NEED_RTNL, |
| 11662 | }, |
| 11663 | { |
| 11664 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 11665 | .doit = nl80211_stop_p2p_device, |
| 11666 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11667 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11668 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11669 | NL80211_FLAG_NEED_RTNL, |
| 11670 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11671 | { |
| 11672 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 11673 | .doit = nl80211_set_mcast_rate, |
| 11674 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11675 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11676 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11677 | NL80211_FLAG_NEED_RTNL, |
| 11678 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11679 | { |
| 11680 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 11681 | .doit = nl80211_set_mac_acl, |
| 11682 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11683 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11684 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11685 | NL80211_FLAG_NEED_RTNL, |
| 11686 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11687 | { |
| 11688 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 11689 | .doit = nl80211_start_radar_detection, |
| 11690 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11691 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11692 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11693 | NL80211_FLAG_NEED_RTNL, |
| 11694 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11695 | { |
| 11696 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 11697 | .doit = nl80211_get_protocol_features, |
| 11698 | .policy = nl80211_policy, |
| 11699 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11700 | { |
| 11701 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 11702 | .doit = nl80211_update_ft_ies, |
| 11703 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11704 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11705 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11706 | NL80211_FLAG_NEED_RTNL, |
| 11707 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11708 | { |
| 11709 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 11710 | .doit = nl80211_crit_protocol_start, |
| 11711 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11712 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11713 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11714 | NL80211_FLAG_NEED_RTNL, |
| 11715 | }, |
| 11716 | { |
| 11717 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 11718 | .doit = nl80211_crit_protocol_stop, |
| 11719 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11720 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11721 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11722 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11723 | }, |
| 11724 | { |
| 11725 | .cmd = NL80211_CMD_GET_COALESCE, |
| 11726 | .doit = nl80211_get_coalesce, |
| 11727 | .policy = nl80211_policy, |
| 11728 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11729 | NL80211_FLAG_NEED_RTNL, |
| 11730 | }, |
| 11731 | { |
| 11732 | .cmd = NL80211_CMD_SET_COALESCE, |
| 11733 | .doit = nl80211_set_coalesce, |
| 11734 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11735 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11736 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11737 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11738 | }, |
| 11739 | { |
| 11740 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 11741 | .doit = nl80211_channel_switch, |
| 11742 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11743 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11745 | NL80211_FLAG_NEED_RTNL, |
| 11746 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11747 | { |
| 11748 | .cmd = NL80211_CMD_VENDOR, |
| 11749 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11750 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11751 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11752 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11753 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11754 | NL80211_FLAG_NEED_RTNL, |
| 11755 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11756 | { |
| 11757 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11758 | .doit = nl80211_set_qos_map, |
| 11759 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11760 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11761 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11762 | NL80211_FLAG_NEED_RTNL, |
| 11763 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11764 | { |
| 11765 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11766 | .doit = nl80211_add_tx_ts, |
| 11767 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11768 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11769 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11770 | NL80211_FLAG_NEED_RTNL, |
| 11771 | }, |
| 11772 | { |
| 11773 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11774 | .doit = nl80211_del_tx_ts, |
| 11775 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11776 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11777 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11778 | NL80211_FLAG_NEED_RTNL, |
| 11779 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11780 | { |
| 11781 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11782 | .doit = nl80211_tdls_channel_switch, |
| 11783 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11784 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11785 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11786 | NL80211_FLAG_NEED_RTNL, |
| 11787 | }, |
| 11788 | { |
| 11789 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11790 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11791 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11792 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11793 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11794 | NL80211_FLAG_NEED_RTNL, |
| 11795 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11796 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11797 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11798 | /* notification functions */ |
| 11799 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11800 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11801 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11802 | { |
| 11803 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11804 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11805 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11806 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11807 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11808 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11809 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11810 | if (!msg) |
| 11811 | return; |
| 11812 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11813 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11814 | nlmsg_free(msg); |
| 11815 | return; |
| 11816 | } |
| 11817 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11818 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11819 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11820 | } |
| 11821 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11822 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11823 | struct cfg80211_registered_device *rdev) |
| 11824 | { |
| 11825 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11826 | struct nlattr *nest; |
| 11827 | int i; |
| 11828 | |
| 11829 | if (WARN_ON(!req)) |
| 11830 | return 0; |
| 11831 | |
| 11832 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11833 | if (!nest) |
| 11834 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11835 | for (i = 0; i < req->n_ssids; i++) { |
| 11836 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11837 | goto nla_put_failure; |
| 11838 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11839 | nla_nest_end(msg, nest); |
| 11840 | |
| 11841 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11842 | if (!nest) |
| 11843 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11844 | for (i = 0; i < req->n_channels; i++) { |
| 11845 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11846 | goto nla_put_failure; |
| 11847 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11848 | nla_nest_end(msg, nest); |
| 11849 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11850 | if (req->ie && |
| 11851 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11852 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11853 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11854 | if (req->flags && |
| 11855 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11856 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11857 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 11858 | if (req->info.scan_start_tsf && |
| 11859 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 11860 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 11861 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 11862 | req->info.tsf_bssid))) |
| 11863 | goto nla_put_failure; |
| 11864 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11865 | return 0; |
| 11866 | nla_put_failure: |
| 11867 | return -ENOBUFS; |
| 11868 | } |
| 11869 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11870 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11871 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11872 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11873 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11874 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11875 | { |
| 11876 | void *hdr; |
| 11877 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11878 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11879 | if (!hdr) |
| 11880 | return -1; |
| 11881 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11882 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11883 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11884 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11885 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11886 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11887 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11888 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11889 | /* ignore errors and send incomplete event anyway */ |
| 11890 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11891 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11892 | genlmsg_end(msg, hdr); |
| 11893 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11894 | |
| 11895 | nla_put_failure: |
| 11896 | genlmsg_cancel(msg, hdr); |
| 11897 | return -EMSGSIZE; |
| 11898 | } |
| 11899 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11900 | static int |
| 11901 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11902 | struct cfg80211_registered_device *rdev, |
| 11903 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11904 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11905 | { |
| 11906 | void *hdr; |
| 11907 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11908 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11909 | if (!hdr) |
| 11910 | return -1; |
| 11911 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11912 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11913 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11914 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11915 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11916 | genlmsg_end(msg, hdr); |
| 11917 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11918 | |
| 11919 | nla_put_failure: |
| 11920 | genlmsg_cancel(msg, hdr); |
| 11921 | return -EMSGSIZE; |
| 11922 | } |
| 11923 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11924 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11925 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11926 | { |
| 11927 | struct sk_buff *msg; |
| 11928 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11930 | if (!msg) |
| 11931 | return; |
| 11932 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11933 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11934 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11935 | nlmsg_free(msg); |
| 11936 | return; |
| 11937 | } |
| 11938 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11939 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11940 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11941 | } |
| 11942 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11943 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11944 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11945 | { |
| 11946 | struct sk_buff *msg; |
| 11947 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11948 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11949 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11950 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11951 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11952 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11953 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11954 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11955 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11956 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11957 | } |
| 11958 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11959 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11960 | } |
| 11961 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11962 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11963 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11964 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11965 | if (!msg) |
| 11966 | return; |
| 11967 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11968 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11969 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11970 | } |
| 11971 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11972 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11973 | struct net_device *netdev) |
| 11974 | { |
| 11975 | struct sk_buff *msg; |
| 11976 | |
| 11977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11978 | if (!msg) |
| 11979 | return; |
| 11980 | |
| 11981 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11982 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11983 | nlmsg_free(msg); |
| 11984 | return; |
| 11985 | } |
| 11986 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11987 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11988 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11989 | } |
| 11990 | |
| 11991 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11992 | struct net_device *netdev, u32 cmd) |
| 11993 | { |
| 11994 | struct sk_buff *msg; |
| 11995 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11997 | if (!msg) |
| 11998 | return; |
| 11999 | |
| 12000 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 12001 | nlmsg_free(msg); |
| 12002 | return; |
| 12003 | } |
| 12004 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12005 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12006 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12007 | } |
| 12008 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12009 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 12010 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12011 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12012 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12013 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 12014 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12015 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12016 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 12017 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12018 | NL80211_REGDOM_TYPE_WORLD)) |
| 12019 | goto nla_put_failure; |
| 12020 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 12021 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12022 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 12023 | goto nla_put_failure; |
| 12024 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 12025 | request->intersect) { |
| 12026 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12027 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 12028 | goto nla_put_failure; |
| 12029 | } else { |
| 12030 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12031 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 12032 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 12033 | request->alpha2)) |
| 12034 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12035 | } |
| 12036 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12037 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 12038 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 12039 | |
| 12040 | if (wiphy && |
| 12041 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 12042 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 12043 | |
| 12044 | if (wiphy && |
| 12045 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 12046 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 12047 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12048 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12049 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12050 | return true; |
| 12051 | |
| 12052 | nla_put_failure: |
| 12053 | return false; |
| 12054 | } |
| 12055 | |
| 12056 | /* |
| 12057 | * This can happen on global regulatory changes or device specific settings |
| 12058 | * based on custom regulatory domains. |
| 12059 | */ |
| 12060 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 12061 | struct regulatory_request *request) |
| 12062 | { |
| 12063 | struct sk_buff *msg; |
| 12064 | void *hdr; |
| 12065 | |
| 12066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12067 | if (!msg) |
| 12068 | return; |
| 12069 | |
| 12070 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 12071 | if (!hdr) { |
| 12072 | nlmsg_free(msg); |
| 12073 | return; |
| 12074 | } |
| 12075 | |
| 12076 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 12077 | goto nla_put_failure; |
| 12078 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12079 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12080 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12081 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12082 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12083 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12084 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12085 | |
| 12086 | return; |
| 12087 | |
| 12088 | nla_put_failure: |
| 12089 | genlmsg_cancel(msg, hdr); |
| 12090 | nlmsg_free(msg); |
| 12091 | } |
| 12092 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12093 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 12094 | struct net_device *netdev, |
| 12095 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12096 | enum nl80211_commands cmd, gfp_t gfp, |
| 12097 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12098 | { |
| 12099 | struct sk_buff *msg; |
| 12100 | void *hdr; |
| 12101 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12103 | if (!msg) |
| 12104 | return; |
| 12105 | |
| 12106 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12107 | if (!hdr) { |
| 12108 | nlmsg_free(msg); |
| 12109 | return; |
| 12110 | } |
| 12111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12113 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12114 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 12115 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12116 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12117 | if (uapsd_queues >= 0) { |
| 12118 | struct nlattr *nla_wmm = |
| 12119 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 12120 | if (!nla_wmm) |
| 12121 | goto nla_put_failure; |
| 12122 | |
| 12123 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 12124 | uapsd_queues)) |
| 12125 | goto nla_put_failure; |
| 12126 | |
| 12127 | nla_nest_end(msg, nla_wmm); |
| 12128 | } |
| 12129 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12130 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12131 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12132 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12133 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12134 | return; |
| 12135 | |
| 12136 | nla_put_failure: |
| 12137 | genlmsg_cancel(msg, hdr); |
| 12138 | nlmsg_free(msg); |
| 12139 | } |
| 12140 | |
| 12141 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12142 | struct net_device *netdev, const u8 *buf, |
| 12143 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12144 | { |
| 12145 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12146 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12147 | } |
| 12148 | |
| 12149 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 12150 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12151 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12152 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12153 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12154 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12155 | } |
| 12156 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12157 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12158 | struct net_device *netdev, const u8 *buf, |
| 12159 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12160 | { |
| 12161 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12162 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12163 | } |
| 12164 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12165 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 12166 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12167 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12168 | { |
| 12169 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12170 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12171 | } |
| 12172 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12173 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 12174 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12175 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12176 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12177 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12178 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12179 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 12180 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12181 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12182 | if (WARN_ON(len < 2)) |
| 12183 | return; |
| 12184 | |
| 12185 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 12186 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 12187 | else |
| 12188 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 12189 | |
| 12190 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12191 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12192 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12193 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12194 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 12195 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 12196 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12197 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12198 | { |
| 12199 | struct sk_buff *msg; |
| 12200 | void *hdr; |
| 12201 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12203 | if (!msg) |
| 12204 | return; |
| 12205 | |
| 12206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12207 | if (!hdr) { |
| 12208 | nlmsg_free(msg); |
| 12209 | return; |
| 12210 | } |
| 12211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12213 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12214 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 12215 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12216 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12217 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12218 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12219 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12220 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12221 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12222 | return; |
| 12223 | |
| 12224 | nla_put_failure: |
| 12225 | genlmsg_cancel(msg, hdr); |
| 12226 | nlmsg_free(msg); |
| 12227 | } |
| 12228 | |
| 12229 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12230 | struct net_device *netdev, const u8 *addr, |
| 12231 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12232 | { |
| 12233 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12234 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12235 | } |
| 12236 | |
| 12237 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12238 | struct net_device *netdev, const u8 *addr, |
| 12239 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12240 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12241 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 12242 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12243 | } |
| 12244 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12245 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 12246 | struct net_device *netdev, const u8 *bssid, |
| 12247 | const u8 *req_ie, size_t req_ie_len, |
| 12248 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12249 | int status, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12250 | { |
| 12251 | struct sk_buff *msg; |
| 12252 | void *hdr; |
| 12253 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12255 | if (!msg) |
| 12256 | return; |
| 12257 | |
| 12258 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 12259 | if (!hdr) { |
| 12260 | nlmsg_free(msg); |
| 12261 | return; |
| 12262 | } |
| 12263 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12264 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12265 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12266 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12267 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 12268 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 12269 | status) || |
| 12270 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12271 | (req_ie && |
| 12272 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12273 | (resp_ie && |
| 12274 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12275 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12276 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12277 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12278 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12279 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12280 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12281 | return; |
| 12282 | |
| 12283 | nla_put_failure: |
| 12284 | genlmsg_cancel(msg, hdr); |
| 12285 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12286 | } |
| 12287 | |
| 12288 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 12289 | struct net_device *netdev, const u8 *bssid, |
| 12290 | const u8 *req_ie, size_t req_ie_len, |
| 12291 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 12292 | { |
| 12293 | struct sk_buff *msg; |
| 12294 | void *hdr; |
| 12295 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12296 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12297 | if (!msg) |
| 12298 | return; |
| 12299 | |
| 12300 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 12301 | if (!hdr) { |
| 12302 | nlmsg_free(msg); |
| 12303 | return; |
| 12304 | } |
| 12305 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12306 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12307 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12308 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 12309 | (req_ie && |
| 12310 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12311 | (resp_ie && |
| 12312 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12313 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12314 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12315 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12316 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12317 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12318 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12319 | return; |
| 12320 | |
| 12321 | nla_put_failure: |
| 12322 | genlmsg_cancel(msg, hdr); |
| 12323 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12324 | } |
| 12325 | |
| 12326 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 12327 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 12328 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12329 | { |
| 12330 | struct sk_buff *msg; |
| 12331 | void *hdr; |
| 12332 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12333 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12334 | if (!msg) |
| 12335 | return; |
| 12336 | |
| 12337 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 12338 | if (!hdr) { |
| 12339 | nlmsg_free(msg); |
| 12340 | return; |
| 12341 | } |
| 12342 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12343 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12344 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12345 | (from_ap && reason && |
| 12346 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 12347 | (from_ap && |
| 12348 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 12349 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 12350 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12351 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12352 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12353 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12354 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12355 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12356 | return; |
| 12357 | |
| 12358 | nla_put_failure: |
| 12359 | genlmsg_cancel(msg, hdr); |
| 12360 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12361 | } |
| 12362 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12363 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 12364 | struct net_device *netdev, const u8 *bssid, |
| 12365 | gfp_t gfp) |
| 12366 | { |
| 12367 | struct sk_buff *msg; |
| 12368 | void *hdr; |
| 12369 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12370 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12371 | if (!msg) |
| 12372 | return; |
| 12373 | |
| 12374 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 12375 | if (!hdr) { |
| 12376 | nlmsg_free(msg); |
| 12377 | return; |
| 12378 | } |
| 12379 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12380 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12381 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12382 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12383 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12384 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12385 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12386 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12387 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12388 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12389 | return; |
| 12390 | |
| 12391 | nla_put_failure: |
| 12392 | genlmsg_cancel(msg, hdr); |
| 12393 | nlmsg_free(msg); |
| 12394 | } |
| 12395 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12396 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 12397 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12398 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12400 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12401 | struct sk_buff *msg; |
| 12402 | void *hdr; |
| 12403 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12404 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 12405 | return; |
| 12406 | |
| 12407 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 12408 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12410 | if (!msg) |
| 12411 | return; |
| 12412 | |
| 12413 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 12414 | if (!hdr) { |
| 12415 | nlmsg_free(msg); |
| 12416 | return; |
| 12417 | } |
| 12418 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12419 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12420 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12421 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12422 | (ie_len && ie && |
| 12423 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 12424 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12425 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12426 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12427 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12428 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12429 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12430 | return; |
| 12431 | |
| 12432 | nla_put_failure: |
| 12433 | genlmsg_cancel(msg, hdr); |
| 12434 | nlmsg_free(msg); |
| 12435 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12436 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12437 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12438 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 12439 | struct net_device *netdev, const u8 *addr, |
| 12440 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12441 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12442 | { |
| 12443 | struct sk_buff *msg; |
| 12444 | void *hdr; |
| 12445 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12446 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12447 | if (!msg) |
| 12448 | return; |
| 12449 | |
| 12450 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 12451 | if (!hdr) { |
| 12452 | nlmsg_free(msg); |
| 12453 | return; |
| 12454 | } |
| 12455 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12456 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12457 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12458 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 12459 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 12460 | (key_id != -1 && |
| 12461 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 12462 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 12463 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12464 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12465 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12466 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12467 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12468 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12469 | return; |
| 12470 | |
| 12471 | nla_put_failure: |
| 12472 | genlmsg_cancel(msg, hdr); |
| 12473 | nlmsg_free(msg); |
| 12474 | } |
| 12475 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12476 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 12477 | struct ieee80211_channel *channel_before, |
| 12478 | struct ieee80211_channel *channel_after) |
| 12479 | { |
| 12480 | struct sk_buff *msg; |
| 12481 | void *hdr; |
| 12482 | struct nlattr *nl_freq; |
| 12483 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12485 | if (!msg) |
| 12486 | return; |
| 12487 | |
| 12488 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 12489 | if (!hdr) { |
| 12490 | nlmsg_free(msg); |
| 12491 | return; |
| 12492 | } |
| 12493 | |
| 12494 | /* |
| 12495 | * Since we are applying the beacon hint to a wiphy we know its |
| 12496 | * wiphy_idx is valid |
| 12497 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 12499 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12500 | |
| 12501 | /* Before */ |
| 12502 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 12503 | if (!nl_freq) |
| 12504 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12505 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12506 | goto nla_put_failure; |
| 12507 | nla_nest_end(msg, nl_freq); |
| 12508 | |
| 12509 | /* After */ |
| 12510 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 12511 | if (!nl_freq) |
| 12512 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12513 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12514 | goto nla_put_failure; |
| 12515 | nla_nest_end(msg, nl_freq); |
| 12516 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12517 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12518 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12519 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12520 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12521 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12522 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12523 | |
| 12524 | return; |
| 12525 | |
| 12526 | nla_put_failure: |
| 12527 | genlmsg_cancel(msg, hdr); |
| 12528 | nlmsg_free(msg); |
| 12529 | } |
| 12530 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12531 | static void nl80211_send_remain_on_chan_event( |
| 12532 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12533 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12534 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12535 | unsigned int duration, gfp_t gfp) |
| 12536 | { |
| 12537 | struct sk_buff *msg; |
| 12538 | void *hdr; |
| 12539 | |
| 12540 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12541 | if (!msg) |
| 12542 | return; |
| 12543 | |
| 12544 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12545 | if (!hdr) { |
| 12546 | nlmsg_free(msg); |
| 12547 | return; |
| 12548 | } |
| 12549 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12550 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12551 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12552 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12553 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12554 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12555 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12556 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 12557 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12558 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12559 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12560 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12561 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12562 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 12563 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 12564 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12565 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12566 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12567 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12568 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12569 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12570 | return; |
| 12571 | |
| 12572 | nla_put_failure: |
| 12573 | genlmsg_cancel(msg, hdr); |
| 12574 | nlmsg_free(msg); |
| 12575 | } |
| 12576 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12577 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 12578 | struct ieee80211_channel *chan, |
| 12579 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12580 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12581 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12582 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12583 | |
| 12584 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12585 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12586 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12587 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12588 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12589 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12590 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12591 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 12592 | struct ieee80211_channel *chan, |
| 12593 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12594 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12595 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12596 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12597 | |
| 12598 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12599 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12600 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12601 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12602 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12603 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12604 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 12605 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12606 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12607 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12608 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12609 | struct sk_buff *msg; |
| 12610 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12611 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 12612 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12614 | if (!msg) |
| 12615 | return; |
| 12616 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12617 | 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] | 12618 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12619 | nlmsg_free(msg); |
| 12620 | return; |
| 12621 | } |
| 12622 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12623 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12624 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12625 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12626 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12627 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12628 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 12629 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12630 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12631 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12632 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12633 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12634 | struct station_info empty_sinfo = {}; |
| 12635 | |
| 12636 | if (!sinfo) |
| 12637 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12638 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12639 | trace_cfg80211_del_sta(dev, mac_addr); |
| 12640 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12641 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12642 | if (!msg) |
| 12643 | return; |
| 12644 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12645 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 12646 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12647 | nlmsg_free(msg); |
| 12648 | return; |
| 12649 | } |
| 12650 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12651 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12652 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12653 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12654 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12655 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12656 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 12657 | enum nl80211_connect_failed_reason reason, |
| 12658 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12659 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12660 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12661 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12662 | struct sk_buff *msg; |
| 12663 | void *hdr; |
| 12664 | |
| 12665 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 12666 | if (!msg) |
| 12667 | return; |
| 12668 | |
| 12669 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 12670 | if (!hdr) { |
| 12671 | nlmsg_free(msg); |
| 12672 | return; |
| 12673 | } |
| 12674 | |
| 12675 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12676 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 12677 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 12678 | goto nla_put_failure; |
| 12679 | |
| 12680 | genlmsg_end(msg, hdr); |
| 12681 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12682 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12683 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12684 | return; |
| 12685 | |
| 12686 | nla_put_failure: |
| 12687 | genlmsg_cancel(msg, hdr); |
| 12688 | nlmsg_free(msg); |
| 12689 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12690 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12691 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12692 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 12693 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12694 | { |
| 12695 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12696 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12697 | struct sk_buff *msg; |
| 12698 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12699 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12700 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12701 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12702 | return false; |
| 12703 | |
| 12704 | msg = nlmsg_new(100, gfp); |
| 12705 | if (!msg) |
| 12706 | return true; |
| 12707 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12708 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12709 | if (!hdr) { |
| 12710 | nlmsg_free(msg); |
| 12711 | return true; |
| 12712 | } |
| 12713 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12714 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12715 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12716 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12717 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12718 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12719 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12720 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12721 | return true; |
| 12722 | |
| 12723 | nla_put_failure: |
| 12724 | genlmsg_cancel(msg, hdr); |
| 12725 | nlmsg_free(msg); |
| 12726 | return true; |
| 12727 | } |
| 12728 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12729 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 12730 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12731 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12732 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12733 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12734 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12735 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 12736 | |
| 12737 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12738 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 12739 | trace_cfg80211_return_bool(false); |
| 12740 | return false; |
| 12741 | } |
| 12742 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 12743 | addr, gfp); |
| 12744 | trace_cfg80211_return_bool(ret); |
| 12745 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12746 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12747 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 12748 | |
| 12749 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 12750 | const u8 *addr, gfp_t gfp) |
| 12751 | { |
| 12752 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12753 | bool ret; |
| 12754 | |
| 12755 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 12756 | |
| 12757 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12758 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 12759 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 12760 | trace_cfg80211_return_bool(false); |
| 12761 | return false; |
| 12762 | } |
| 12763 | ret = __nl80211_unexpected_frame(dev, |
| 12764 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12765 | addr, gfp); |
| 12766 | trace_cfg80211_return_bool(ret); |
| 12767 | return ret; |
| 12768 | } |
| 12769 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12770 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12771 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12772 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12773 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12774 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12775 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12776 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12777 | struct sk_buff *msg; |
| 12778 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12779 | |
| 12780 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12781 | if (!msg) |
| 12782 | return -ENOMEM; |
| 12783 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12784 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12785 | if (!hdr) { |
| 12786 | nlmsg_free(msg); |
| 12787 | return -ENOMEM; |
| 12788 | } |
| 12789 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12790 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12791 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12792 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12793 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12794 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12795 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12796 | (sig_dbm && |
| 12797 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12798 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12799 | (flags && |
| 12800 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12801 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12802 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12803 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12804 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12805 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12806 | |
| 12807 | nla_put_failure: |
| 12808 | genlmsg_cancel(msg, hdr); |
| 12809 | nlmsg_free(msg); |
| 12810 | return -ENOBUFS; |
| 12811 | } |
| 12812 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12813 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12814 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12815 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12816 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12817 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12818 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12819 | struct sk_buff *msg; |
| 12820 | void *hdr; |
| 12821 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12822 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12823 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12825 | if (!msg) |
| 12826 | return; |
| 12827 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12828 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12829 | if (!hdr) { |
| 12830 | nlmsg_free(msg); |
| 12831 | return; |
| 12832 | } |
| 12833 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12834 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12835 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12836 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12837 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12838 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12839 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12840 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12841 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12842 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12843 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12844 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12845 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12846 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12847 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12848 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12849 | return; |
| 12850 | |
| 12851 | nla_put_failure: |
| 12852 | genlmsg_cancel(msg, hdr); |
| 12853 | nlmsg_free(msg); |
| 12854 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12855 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12856 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12857 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12858 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12859 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12860 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12861 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12862 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12863 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12864 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12865 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12866 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12867 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12868 | cb = (void **)msg->cb; |
| 12869 | |
| 12870 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12871 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12872 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12873 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12874 | } |
| 12875 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12876 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12877 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12878 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12879 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12880 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12881 | goto nla_put_failure; |
| 12882 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12883 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12884 | if (!cb[1]) |
| 12885 | goto nla_put_failure; |
| 12886 | |
| 12887 | cb[2] = rdev; |
| 12888 | |
| 12889 | return msg; |
| 12890 | nla_put_failure: |
| 12891 | nlmsg_free(msg); |
| 12892 | return NULL; |
| 12893 | } |
| 12894 | |
| 12895 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12896 | { |
| 12897 | void **cb = (void **)msg->cb; |
| 12898 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12899 | |
| 12900 | nla_nest_end(msg, cb[1]); |
| 12901 | genlmsg_end(msg, cb[0]); |
| 12902 | |
| 12903 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12904 | |
| 12905 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12906 | NL80211_MCGRP_MLME, gfp); |
| 12907 | } |
| 12908 | |
| 12909 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12910 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12911 | gfp_t gfp) |
| 12912 | { |
| 12913 | struct sk_buff *msg; |
| 12914 | |
| 12915 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12916 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12917 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12918 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12919 | return; |
| 12920 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12921 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12922 | if (!msg) |
| 12923 | return; |
| 12924 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12925 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12926 | rssi_event)) |
| 12927 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12928 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12929 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12930 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12931 | return; |
| 12932 | |
| 12933 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12934 | nlmsg_free(msg); |
| 12935 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12936 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12937 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12938 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12939 | const u8 *peer, u32 num_packets, |
| 12940 | u32 rate, u32 intvl, gfp_t gfp) |
| 12941 | { |
| 12942 | struct sk_buff *msg; |
| 12943 | |
| 12944 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12945 | if (!msg) |
| 12946 | return; |
| 12947 | |
| 12948 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12949 | goto nla_put_failure; |
| 12950 | |
| 12951 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12952 | goto nla_put_failure; |
| 12953 | |
| 12954 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12955 | goto nla_put_failure; |
| 12956 | |
| 12957 | cfg80211_send_cqm(msg, gfp); |
| 12958 | return; |
| 12959 | |
| 12960 | nla_put_failure: |
| 12961 | nlmsg_free(msg); |
| 12962 | } |
| 12963 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12964 | |
| 12965 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12966 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12967 | { |
| 12968 | struct sk_buff *msg; |
| 12969 | |
| 12970 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12971 | |
| 12972 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12973 | if (!msg) |
| 12974 | return; |
| 12975 | |
| 12976 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12977 | goto nla_put_failure; |
| 12978 | |
| 12979 | cfg80211_send_cqm(msg, gfp); |
| 12980 | return; |
| 12981 | |
| 12982 | nla_put_failure: |
| 12983 | nlmsg_free(msg); |
| 12984 | } |
| 12985 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12986 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12987 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12988 | { |
| 12989 | struct sk_buff *msg; |
| 12990 | |
| 12991 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12992 | if (!msg) |
| 12993 | return; |
| 12994 | |
| 12995 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12996 | goto nla_put_failure; |
| 12997 | |
| 12998 | cfg80211_send_cqm(msg, gfp); |
| 12999 | return; |
| 13000 | |
| 13001 | nla_put_failure: |
| 13002 | nlmsg_free(msg); |
| 13003 | } |
| 13004 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 13005 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13006 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 13007 | struct net_device *netdev, const u8 *bssid, |
| 13008 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13009 | { |
| 13010 | struct sk_buff *msg; |
| 13011 | struct nlattr *rekey_attr; |
| 13012 | void *hdr; |
| 13013 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13015 | if (!msg) |
| 13016 | return; |
| 13017 | |
| 13018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 13019 | if (!hdr) { |
| 13020 | nlmsg_free(msg); |
| 13021 | return; |
| 13022 | } |
| 13023 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13026 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13027 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13028 | |
| 13029 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 13030 | if (!rekey_attr) |
| 13031 | goto nla_put_failure; |
| 13032 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13033 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 13034 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 13035 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13036 | |
| 13037 | nla_nest_end(msg, rekey_attr); |
| 13038 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13039 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13040 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13041 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13042 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13043 | return; |
| 13044 | |
| 13045 | nla_put_failure: |
| 13046 | genlmsg_cancel(msg, hdr); |
| 13047 | nlmsg_free(msg); |
| 13048 | } |
| 13049 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13050 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 13051 | const u8 *replay_ctr, gfp_t gfp) |
| 13052 | { |
| 13053 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13054 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13055 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13056 | |
| 13057 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 13058 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 13059 | } |
| 13060 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 13061 | |
| 13062 | static void |
| 13063 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 13064 | struct net_device *netdev, int index, |
| 13065 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13066 | { |
| 13067 | struct sk_buff *msg; |
| 13068 | struct nlattr *attr; |
| 13069 | void *hdr; |
| 13070 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13072 | if (!msg) |
| 13073 | return; |
| 13074 | |
| 13075 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 13076 | if (!hdr) { |
| 13077 | nlmsg_free(msg); |
| 13078 | return; |
| 13079 | } |
| 13080 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13082 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13083 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13084 | |
| 13085 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 13086 | if (!attr) |
| 13087 | goto nla_put_failure; |
| 13088 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13089 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 13090 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 13091 | (preauth && |
| 13092 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 13093 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13094 | |
| 13095 | nla_nest_end(msg, attr); |
| 13096 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13097 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13098 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13099 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13100 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13101 | return; |
| 13102 | |
| 13103 | nla_put_failure: |
| 13104 | genlmsg_cancel(msg, hdr); |
| 13105 | nlmsg_free(msg); |
| 13106 | } |
| 13107 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13108 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 13109 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 13110 | { |
| 13111 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13112 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13113 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13114 | |
| 13115 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 13116 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 13117 | } |
| 13118 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 13119 | |
| 13120 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 13121 | struct net_device *netdev, |
| 13122 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13123 | gfp_t gfp, |
| 13124 | enum nl80211_commands notif, |
| 13125 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13126 | { |
| 13127 | struct sk_buff *msg; |
| 13128 | void *hdr; |
| 13129 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13131 | if (!msg) |
| 13132 | return; |
| 13133 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13134 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13135 | if (!hdr) { |
| 13136 | nlmsg_free(msg); |
| 13137 | return; |
| 13138 | } |
| 13139 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 13140 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13141 | goto nla_put_failure; |
| 13142 | |
| 13143 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 13144 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13145 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13146 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 13147 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 13148 | goto nla_put_failure; |
| 13149 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13150 | genlmsg_end(msg, hdr); |
| 13151 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13152 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13153 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13154 | return; |
| 13155 | |
| 13156 | nla_put_failure: |
| 13157 | genlmsg_cancel(msg, hdr); |
| 13158 | nlmsg_free(msg); |
| 13159 | } |
| 13160 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13161 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 13162 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13163 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13164 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13165 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13166 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13167 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13168 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13169 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13170 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13171 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 13172 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 13173 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13174 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13175 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13176 | } |
| 13177 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 13178 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13179 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 13180 | struct cfg80211_chan_def *chandef, |
| 13181 | u8 count) |
| 13182 | { |
| 13183 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13184 | struct wiphy *wiphy = wdev->wiphy; |
| 13185 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13186 | |
| 13187 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 13188 | |
| 13189 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13190 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 13191 | } |
| 13192 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 13193 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13194 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13195 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 13196 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13197 | enum nl80211_radar_event event, |
| 13198 | struct net_device *netdev, gfp_t gfp) |
| 13199 | { |
| 13200 | struct sk_buff *msg; |
| 13201 | void *hdr; |
| 13202 | |
| 13203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13204 | if (!msg) |
| 13205 | return; |
| 13206 | |
| 13207 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 13208 | if (!hdr) { |
| 13209 | nlmsg_free(msg); |
| 13210 | return; |
| 13211 | } |
| 13212 | |
| 13213 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 13214 | goto nla_put_failure; |
| 13215 | |
| 13216 | /* NOP and radar events don't need a netdev parameter */ |
| 13217 | if (netdev) { |
| 13218 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 13219 | |
| 13220 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13221 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13222 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13223 | goto nla_put_failure; |
| 13224 | } |
| 13225 | |
| 13226 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 13227 | goto nla_put_failure; |
| 13228 | |
| 13229 | if (nl80211_send_chandef(msg, chandef)) |
| 13230 | goto nla_put_failure; |
| 13231 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13232 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13233 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13235 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13236 | return; |
| 13237 | |
| 13238 | nla_put_failure: |
| 13239 | genlmsg_cancel(msg, hdr); |
| 13240 | nlmsg_free(msg); |
| 13241 | } |
| 13242 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13243 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 13244 | u64 cookie, bool acked, gfp_t gfp) |
| 13245 | { |
| 13246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13247 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13248 | struct sk_buff *msg; |
| 13249 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13250 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13251 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 13252 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13254 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13255 | if (!msg) |
| 13256 | return; |
| 13257 | |
| 13258 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 13259 | if (!hdr) { |
| 13260 | nlmsg_free(msg); |
| 13261 | return; |
| 13262 | } |
| 13263 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13264 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13265 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13266 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13267 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13268 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13269 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 13270 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13271 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13272 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13273 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13274 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13275 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13276 | return; |
| 13277 | |
| 13278 | nla_put_failure: |
| 13279 | genlmsg_cancel(msg, hdr); |
| 13280 | nlmsg_free(msg); |
| 13281 | } |
| 13282 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 13283 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13284 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 13285 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13286 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13287 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13288 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13289 | struct sk_buff *msg; |
| 13290 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13291 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13292 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13293 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 13294 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13295 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13296 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 13297 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 13298 | if (!msg) { |
| 13299 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13300 | return; |
| 13301 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13302 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13303 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 13304 | if (!hdr) |
| 13305 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13306 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13307 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13308 | (freq && |
| 13309 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 13310 | (sig_dbm && |
| 13311 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 13312 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 13313 | goto nla_put_failure; |
| 13314 | |
| 13315 | genlmsg_end(msg, hdr); |
| 13316 | |
| 13317 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13318 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13319 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13320 | return; |
| 13321 | |
| 13322 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13323 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13324 | if (hdr) |
| 13325 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13326 | nlmsg_free(msg); |
| 13327 | } |
| 13328 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 13329 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13330 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13331 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 13332 | struct cfg80211_wowlan_wakeup *wakeup) |
| 13333 | { |
| 13334 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 13335 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 13336 | int i, j; |
| 13337 | |
| 13338 | nl_results = nla_nest_start( |
| 13339 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 13340 | if (!nl_results) |
| 13341 | return -EMSGSIZE; |
| 13342 | |
| 13343 | for (i = 0; i < nd->n_matches; i++) { |
| 13344 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 13345 | |
| 13346 | nl_match = nla_nest_start(msg, i); |
| 13347 | if (!nl_match) |
| 13348 | break; |
| 13349 | |
| 13350 | /* The SSID attribute is optional in nl80211, but for |
| 13351 | * simplicity reasons it's always present in the |
| 13352 | * cfg80211 structure. If a driver can't pass the |
| 13353 | * SSID, that needs to be changed. A zero length SSID |
| 13354 | * is still a valid SSID (wildcard), so it cannot be |
| 13355 | * used for this purpose. |
| 13356 | */ |
| 13357 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 13358 | match->ssid.ssid)) { |
| 13359 | nla_nest_cancel(msg, nl_match); |
| 13360 | goto out; |
| 13361 | } |
| 13362 | |
| 13363 | if (match->n_channels) { |
| 13364 | nl_freqs = nla_nest_start( |
| 13365 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13366 | if (!nl_freqs) { |
| 13367 | nla_nest_cancel(msg, nl_match); |
| 13368 | goto out; |
| 13369 | } |
| 13370 | |
| 13371 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 13372 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13373 | nla_nest_cancel(msg, nl_freqs); |
| 13374 | nla_nest_cancel(msg, nl_match); |
| 13375 | goto out; |
| 13376 | } |
| 13377 | } |
| 13378 | |
| 13379 | nla_nest_end(msg, nl_freqs); |
| 13380 | } |
| 13381 | |
| 13382 | nla_nest_end(msg, nl_match); |
| 13383 | } |
| 13384 | |
| 13385 | out: |
| 13386 | nla_nest_end(msg, nl_results); |
| 13387 | return 0; |
| 13388 | } |
| 13389 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13390 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 13391 | struct cfg80211_wowlan_wakeup *wakeup, |
| 13392 | gfp_t gfp) |
| 13393 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13394 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13395 | struct sk_buff *msg; |
| 13396 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13397 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13398 | |
| 13399 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 13400 | |
| 13401 | if (wakeup) |
| 13402 | size += wakeup->packet_present_len; |
| 13403 | |
| 13404 | msg = nlmsg_new(size, gfp); |
| 13405 | if (!msg) |
| 13406 | return; |
| 13407 | |
| 13408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 13409 | if (!hdr) |
| 13410 | goto free_msg; |
| 13411 | |
| 13412 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13413 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13414 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13415 | goto free_msg; |
| 13416 | |
| 13417 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13418 | wdev->netdev->ifindex)) |
| 13419 | goto free_msg; |
| 13420 | |
| 13421 | if (wakeup) { |
| 13422 | struct nlattr *reasons; |
| 13423 | |
| 13424 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 13425 | if (!reasons) |
| 13426 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13427 | |
| 13428 | if (wakeup->disconnect && |
| 13429 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 13430 | goto free_msg; |
| 13431 | if (wakeup->magic_pkt && |
| 13432 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 13433 | goto free_msg; |
| 13434 | if (wakeup->gtk_rekey_failure && |
| 13435 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 13436 | goto free_msg; |
| 13437 | if (wakeup->eap_identity_req && |
| 13438 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 13439 | goto free_msg; |
| 13440 | if (wakeup->four_way_handshake && |
| 13441 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 13442 | goto free_msg; |
| 13443 | if (wakeup->rfkill_release && |
| 13444 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 13445 | goto free_msg; |
| 13446 | |
| 13447 | if (wakeup->pattern_idx >= 0 && |
| 13448 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 13449 | wakeup->pattern_idx)) |
| 13450 | goto free_msg; |
| 13451 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13452 | if (wakeup->tcp_match && |
| 13453 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 13454 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13455 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13456 | if (wakeup->tcp_connlost && |
| 13457 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 13458 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13459 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13460 | if (wakeup->tcp_nomoretokens && |
| 13461 | nla_put_flag(msg, |
| 13462 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 13463 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13464 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13465 | if (wakeup->packet) { |
| 13466 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 13467 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 13468 | |
| 13469 | if (!wakeup->packet_80211) { |
| 13470 | pkt_attr = |
| 13471 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 13472 | len_attr = |
| 13473 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 13474 | } |
| 13475 | |
| 13476 | if (wakeup->packet_len && |
| 13477 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 13478 | goto free_msg; |
| 13479 | |
| 13480 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 13481 | wakeup->packet)) |
| 13482 | goto free_msg; |
| 13483 | } |
| 13484 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13485 | if (wakeup->net_detect && |
| 13486 | cfg80211_net_detect_results(msg, wakeup)) |
| 13487 | goto free_msg; |
| 13488 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13489 | nla_nest_end(msg, reasons); |
| 13490 | } |
| 13491 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13492 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13493 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13494 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13495 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13496 | return; |
| 13497 | |
| 13498 | free_msg: |
| 13499 | nlmsg_free(msg); |
| 13500 | } |
| 13501 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 13502 | #endif |
| 13503 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13504 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 13505 | enum nl80211_tdls_operation oper, |
| 13506 | u16 reason_code, gfp_t gfp) |
| 13507 | { |
| 13508 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13509 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13510 | struct sk_buff *msg; |
| 13511 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13512 | |
| 13513 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 13514 | reason_code); |
| 13515 | |
| 13516 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13517 | if (!msg) |
| 13518 | return; |
| 13519 | |
| 13520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 13521 | if (!hdr) { |
| 13522 | nlmsg_free(msg); |
| 13523 | return; |
| 13524 | } |
| 13525 | |
| 13526 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13527 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13528 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 13529 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 13530 | (reason_code > 0 && |
| 13531 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 13532 | goto nla_put_failure; |
| 13533 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13534 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13535 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13536 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13537 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13538 | return; |
| 13539 | |
| 13540 | nla_put_failure: |
| 13541 | genlmsg_cancel(msg, hdr); |
| 13542 | nlmsg_free(msg); |
| 13543 | } |
| 13544 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 13545 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13546 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 13547 | unsigned long state, |
| 13548 | void *_notify) |
| 13549 | { |
| 13550 | struct netlink_notify *notify = _notify; |
| 13551 | struct cfg80211_registered_device *rdev; |
| 13552 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13553 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13554 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 13555 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13556 | return NOTIFY_DONE; |
| 13557 | |
| 13558 | rcu_read_lock(); |
| 13559 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13560 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13561 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13562 | bool schedule_scan_stop = false; |
| 13563 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 13564 | rcu_dereference(rdev->sched_scan_req); |
| 13565 | |
| 13566 | if (sched_scan_req && notify->portid && |
| 13567 | sched_scan_req->owner_nlportid == notify->portid) |
| 13568 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13569 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13570 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13571 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13572 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13573 | if (wdev->owner_nlportid == notify->portid) |
| 13574 | schedule_destroy_work = true; |
| 13575 | } |
| 13576 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13577 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13578 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 13579 | list) { |
| 13580 | if (reg->nlportid == notify->portid) { |
| 13581 | list_del(®->list); |
| 13582 | kfree(reg); |
| 13583 | break; |
| 13584 | } |
| 13585 | } |
| 13586 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13587 | |
| 13588 | if (schedule_destroy_work) { |
| 13589 | struct cfg80211_iface_destroy *destroy; |
| 13590 | |
| 13591 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 13592 | if (destroy) { |
| 13593 | destroy->nlportid = notify->portid; |
| 13594 | spin_lock(&rdev->destroy_list_lock); |
| 13595 | list_add(&destroy->list, &rdev->destroy_list); |
| 13596 | spin_unlock(&rdev->destroy_list_lock); |
| 13597 | schedule_work(&rdev->destroy_work); |
| 13598 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13599 | } else if (schedule_scan_stop) { |
| 13600 | sched_scan_req->owner_nlportid = 0; |
| 13601 | |
| 13602 | if (rdev->ops->sched_scan_stop && |
| 13603 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 13604 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13605 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13606 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13607 | |
| 13608 | rcu_read_unlock(); |
| 13609 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 13610 | /* |
| 13611 | * It is possible that the user space process that is controlling the |
| 13612 | * indoor setting disappeared, so notify the regulatory core. |
| 13613 | */ |
| 13614 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 13615 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13616 | } |
| 13617 | |
| 13618 | static struct notifier_block nl80211_netlink_notifier = { |
| 13619 | .notifier_call = nl80211_netlink_notify, |
| 13620 | }; |
| 13621 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13622 | void cfg80211_ft_event(struct net_device *netdev, |
| 13623 | struct cfg80211_ft_event_params *ft_event) |
| 13624 | { |
| 13625 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13626 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13627 | struct sk_buff *msg; |
| 13628 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13629 | |
| 13630 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 13631 | |
| 13632 | if (!ft_event->target_ap) |
| 13633 | return; |
| 13634 | |
| 13635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13636 | if (!msg) |
| 13637 | return; |
| 13638 | |
| 13639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13640 | if (!hdr) |
| 13641 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13642 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13643 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13644 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13645 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 13646 | goto out; |
| 13647 | |
| 13648 | if (ft_event->ies && |
| 13649 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 13650 | goto out; |
| 13651 | if (ft_event->ric_ies && |
| 13652 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 13653 | ft_event->ric_ies)) |
| 13654 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13655 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13656 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13657 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13658 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13659 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13660 | return; |
| 13661 | out: |
| 13662 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13663 | } |
| 13664 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 13665 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13666 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 13667 | { |
| 13668 | struct cfg80211_registered_device *rdev; |
| 13669 | struct sk_buff *msg; |
| 13670 | void *hdr; |
| 13671 | u32 nlportid; |
| 13672 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13673 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13674 | if (!rdev->crit_proto_nlportid) |
| 13675 | return; |
| 13676 | |
| 13677 | nlportid = rdev->crit_proto_nlportid; |
| 13678 | rdev->crit_proto_nlportid = 0; |
| 13679 | |
| 13680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13681 | if (!msg) |
| 13682 | return; |
| 13683 | |
| 13684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 13685 | if (!hdr) |
| 13686 | goto nla_put_failure; |
| 13687 | |
| 13688 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13689 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13690 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13691 | goto nla_put_failure; |
| 13692 | |
| 13693 | genlmsg_end(msg, hdr); |
| 13694 | |
| 13695 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 13696 | return; |
| 13697 | |
| 13698 | nla_put_failure: |
| 13699 | if (hdr) |
| 13700 | genlmsg_cancel(msg, hdr); |
| 13701 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13702 | } |
| 13703 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 13704 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13705 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 13706 | { |
| 13707 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13708 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13709 | struct sk_buff *msg; |
| 13710 | void *hdr; |
| 13711 | |
| 13712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13713 | if (!msg) |
| 13714 | return; |
| 13715 | |
| 13716 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 13717 | if (!hdr) |
| 13718 | goto out; |
| 13719 | |
| 13720 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13721 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13722 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13723 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13724 | goto out; |
| 13725 | |
| 13726 | genlmsg_end(msg, hdr); |
| 13727 | |
| 13728 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 13729 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13730 | return; |
| 13731 | out: |
| 13732 | nlmsg_free(msg); |
| 13733 | } |
| 13734 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13735 | /* initialisation/exit functions */ |
| 13736 | |
| 13737 | int nl80211_init(void) |
| 13738 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 13739 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13740 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13741 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 13742 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13743 | if (err) |
| 13744 | return err; |
| 13745 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13746 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 13747 | if (err) |
| 13748 | goto err_out; |
| 13749 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13750 | return 0; |
| 13751 | err_out: |
| 13752 | genl_unregister_family(&nl80211_fam); |
| 13753 | return err; |
| 13754 | } |
| 13755 | |
| 13756 | void nl80211_exit(void) |
| 13757 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13758 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13759 | genl_unregister_family(&nl80211_fam); |
| 13760 | } |