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; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame^] | 851 | bool have_key = false; |
| 852 | |
| 853 | nla_for_each_nested(key, keys, rem) { |
| 854 | have_key = true; |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | if (!have_key) |
| 859 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 860 | |
| 861 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 862 | if (!result) |
| 863 | return ERR_PTR(-ENOMEM); |
| 864 | |
| 865 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 866 | |
| 867 | nla_for_each_nested(key, keys, rem) { |
| 868 | memset(&parse, 0, sizeof(parse)); |
| 869 | parse.idx = -1; |
| 870 | |
| 871 | err = nl80211_parse_key_new(key, &parse); |
| 872 | if (err) |
| 873 | goto error; |
| 874 | err = -EINVAL; |
| 875 | if (!parse.p.key) |
| 876 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 877 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | goto error; |
| 879 | if (parse.def) { |
| 880 | if (def) |
| 881 | goto error; |
| 882 | def = 1; |
| 883 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 884 | if (!parse.def_uni || !parse.def_multi) |
| 885 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 886 | } else if (parse.defmgmt) |
| 887 | goto error; |
| 888 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 889 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 890 | if (err) |
| 891 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 892 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 893 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 894 | err = -EINVAL; |
| 895 | goto error; |
| 896 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 897 | result->params[parse.idx].cipher = parse.p.cipher; |
| 898 | result->params[parse.idx].key_len = parse.p.key_len; |
| 899 | result->params[parse.idx].key = result->data[parse.idx]; |
| 900 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 901 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 902 | /* must be WEP key if we got here */ |
| 903 | if (no_ht) |
| 904 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame^] | 907 | if (result->def < 0) { |
| 908 | err = -EINVAL; |
| 909 | goto error; |
| 910 | } |
| 911 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 912 | return result; |
| 913 | error: |
| 914 | kfree(result); |
| 915 | return ERR_PTR(err); |
| 916 | } |
| 917 | |
| 918 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 919 | { |
| 920 | ASSERT_WDEV_LOCK(wdev); |
| 921 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 922 | switch (wdev->iftype) { |
| 923 | case NL80211_IFTYPE_AP: |
| 924 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 925 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 926 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 927 | break; |
| 928 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 929 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 930 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 931 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 932 | return -ENOLINK; |
| 933 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 934 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 935 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 936 | case NL80211_IFTYPE_MONITOR: |
| 937 | case NL80211_IFTYPE_P2P_DEVICE: |
| 938 | case NL80211_IFTYPE_WDS: |
| 939 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | return 0; |
| 944 | } |
| 945 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 946 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 947 | struct nlattr *tb) |
| 948 | { |
| 949 | struct ieee80211_channel *chan; |
| 950 | |
| 951 | if (tb == NULL) |
| 952 | return NULL; |
| 953 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 954 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 955 | return NULL; |
| 956 | return chan; |
| 957 | } |
| 958 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 959 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 960 | { |
| 961 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 962 | int i; |
| 963 | |
| 964 | if (!nl_modes) |
| 965 | goto nla_put_failure; |
| 966 | |
| 967 | i = 0; |
| 968 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 969 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 970 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 971 | ifmodes >>= 1; |
| 972 | i++; |
| 973 | } |
| 974 | |
| 975 | nla_nest_end(msg, nl_modes); |
| 976 | return 0; |
| 977 | |
| 978 | nla_put_failure: |
| 979 | return -ENOBUFS; |
| 980 | } |
| 981 | |
| 982 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 983 | struct sk_buff *msg, |
| 984 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 985 | { |
| 986 | struct nlattr *nl_combis; |
| 987 | int i, j; |
| 988 | |
| 989 | nl_combis = nla_nest_start(msg, |
| 990 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 991 | if (!nl_combis) |
| 992 | goto nla_put_failure; |
| 993 | |
| 994 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 995 | const struct ieee80211_iface_combination *c; |
| 996 | struct nlattr *nl_combi, *nl_limits; |
| 997 | |
| 998 | c = &wiphy->iface_combinations[i]; |
| 999 | |
| 1000 | nl_combi = nla_nest_start(msg, i + 1); |
| 1001 | if (!nl_combi) |
| 1002 | goto nla_put_failure; |
| 1003 | |
| 1004 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1005 | if (!nl_limits) |
| 1006 | goto nla_put_failure; |
| 1007 | |
| 1008 | for (j = 0; j < c->n_limits; j++) { |
| 1009 | struct nlattr *nl_limit; |
| 1010 | |
| 1011 | nl_limit = nla_nest_start(msg, j + 1); |
| 1012 | if (!nl_limit) |
| 1013 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1014 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1015 | c->limits[j].max)) |
| 1016 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1017 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1018 | c->limits[j].types)) |
| 1019 | goto nla_put_failure; |
| 1020 | nla_nest_end(msg, nl_limit); |
| 1021 | } |
| 1022 | |
| 1023 | nla_nest_end(msg, nl_limits); |
| 1024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1025 | if (c->beacon_int_infra_match && |
| 1026 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1027 | goto nla_put_failure; |
| 1028 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1029 | c->num_different_channels) || |
| 1030 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1031 | c->max_interfaces)) |
| 1032 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1033 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1034 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1035 | c->radar_detect_widths) || |
| 1036 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1037 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1038 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1039 | |
| 1040 | nla_nest_end(msg, nl_combi); |
| 1041 | } |
| 1042 | |
| 1043 | nla_nest_end(msg, nl_combis); |
| 1044 | |
| 1045 | return 0; |
| 1046 | nla_put_failure: |
| 1047 | return -ENOBUFS; |
| 1048 | } |
| 1049 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1051 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1052 | struct sk_buff *msg) |
| 1053 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1054 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1055 | struct nlattr *nl_tcp; |
| 1056 | |
| 1057 | if (!tcp) |
| 1058 | return 0; |
| 1059 | |
| 1060 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1061 | if (!nl_tcp) |
| 1062 | return -ENOBUFS; |
| 1063 | |
| 1064 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1065 | tcp->data_payload_max)) |
| 1066 | return -ENOBUFS; |
| 1067 | |
| 1068 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1069 | tcp->data_payload_max)) |
| 1070 | return -ENOBUFS; |
| 1071 | |
| 1072 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1073 | return -ENOBUFS; |
| 1074 | |
| 1075 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1076 | sizeof(*tcp->tok), tcp->tok)) |
| 1077 | return -ENOBUFS; |
| 1078 | |
| 1079 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1080 | tcp->data_interval_max)) |
| 1081 | return -ENOBUFS; |
| 1082 | |
| 1083 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1084 | tcp->wake_payload_max)) |
| 1085 | return -ENOBUFS; |
| 1086 | |
| 1087 | nla_nest_end(msg, nl_tcp); |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1091 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1092 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1093 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1094 | { |
| 1095 | struct nlattr *nl_wowlan; |
| 1096 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1097 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1098 | return 0; |
| 1099 | |
| 1100 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1101 | if (!nl_wowlan) |
| 1102 | return -ENOBUFS; |
| 1103 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1104 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1105 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1106 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1107 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1108 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1109 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1110 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1111 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1112 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1114 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1115 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1116 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1118 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1119 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1120 | return -ENOBUFS; |
| 1121 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1122 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1123 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1124 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1125 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1126 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1127 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1128 | }; |
| 1129 | |
| 1130 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1131 | sizeof(pat), &pat)) |
| 1132 | return -ENOBUFS; |
| 1133 | } |
| 1134 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1135 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1136 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1137 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1138 | return -ENOBUFS; |
| 1139 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1140 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1141 | return -ENOBUFS; |
| 1142 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1143 | nla_nest_end(msg, nl_wowlan); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | #endif |
| 1148 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1149 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1150 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1151 | { |
| 1152 | struct nl80211_coalesce_rule_support rule; |
| 1153 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1154 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1155 | return 0; |
| 1156 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1157 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1158 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1159 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1160 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1161 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1162 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1163 | |
| 1164 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1165 | return -ENOBUFS; |
| 1166 | |
| 1167 | return 0; |
| 1168 | } |
| 1169 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1170 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1171 | struct ieee80211_supported_band *sband) |
| 1172 | { |
| 1173 | struct nlattr *nl_rates, *nl_rate; |
| 1174 | struct ieee80211_rate *rate; |
| 1175 | int i; |
| 1176 | |
| 1177 | /* add HT info */ |
| 1178 | if (sband->ht_cap.ht_supported && |
| 1179 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1180 | sizeof(sband->ht_cap.mcs), |
| 1181 | &sband->ht_cap.mcs) || |
| 1182 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1183 | sband->ht_cap.cap) || |
| 1184 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1185 | sband->ht_cap.ampdu_factor) || |
| 1186 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1187 | sband->ht_cap.ampdu_density))) |
| 1188 | return -ENOBUFS; |
| 1189 | |
| 1190 | /* add VHT info */ |
| 1191 | if (sband->vht_cap.vht_supported && |
| 1192 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1193 | sizeof(sband->vht_cap.vht_mcs), |
| 1194 | &sband->vht_cap.vht_mcs) || |
| 1195 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1196 | sband->vht_cap.cap))) |
| 1197 | return -ENOBUFS; |
| 1198 | |
| 1199 | /* add bitrates */ |
| 1200 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1201 | if (!nl_rates) |
| 1202 | return -ENOBUFS; |
| 1203 | |
| 1204 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1205 | nl_rate = nla_nest_start(msg, i); |
| 1206 | if (!nl_rate) |
| 1207 | return -ENOBUFS; |
| 1208 | |
| 1209 | rate = &sband->bitrates[i]; |
| 1210 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1211 | rate->bitrate)) |
| 1212 | return -ENOBUFS; |
| 1213 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1214 | nla_put_flag(msg, |
| 1215 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1216 | return -ENOBUFS; |
| 1217 | |
| 1218 | nla_nest_end(msg, nl_rate); |
| 1219 | } |
| 1220 | |
| 1221 | nla_nest_end(msg, nl_rates); |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int |
| 1227 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1228 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1229 | { |
| 1230 | u16 stypes; |
| 1231 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1232 | enum nl80211_iftype ift; |
| 1233 | int i; |
| 1234 | |
| 1235 | if (!mgmt_stypes) |
| 1236 | return 0; |
| 1237 | |
| 1238 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1239 | if (!nl_ifs) |
| 1240 | return -ENOBUFS; |
| 1241 | |
| 1242 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1243 | nl_ftypes = nla_nest_start(msg, ift); |
| 1244 | if (!nl_ftypes) |
| 1245 | return -ENOBUFS; |
| 1246 | i = 0; |
| 1247 | stypes = mgmt_stypes[ift].tx; |
| 1248 | while (stypes) { |
| 1249 | if ((stypes & 1) && |
| 1250 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1251 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1252 | return -ENOBUFS; |
| 1253 | stypes >>= 1; |
| 1254 | i++; |
| 1255 | } |
| 1256 | nla_nest_end(msg, nl_ftypes); |
| 1257 | } |
| 1258 | |
| 1259 | nla_nest_end(msg, nl_ifs); |
| 1260 | |
| 1261 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1262 | if (!nl_ifs) |
| 1263 | return -ENOBUFS; |
| 1264 | |
| 1265 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1266 | nl_ftypes = nla_nest_start(msg, ift); |
| 1267 | if (!nl_ftypes) |
| 1268 | return -ENOBUFS; |
| 1269 | i = 0; |
| 1270 | stypes = mgmt_stypes[ift].rx; |
| 1271 | while (stypes) { |
| 1272 | if ((stypes & 1) && |
| 1273 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1274 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1275 | return -ENOBUFS; |
| 1276 | stypes >>= 1; |
| 1277 | i++; |
| 1278 | } |
| 1279 | nla_nest_end(msg, nl_ftypes); |
| 1280 | } |
| 1281 | nla_nest_end(msg, nl_ifs); |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1286 | struct nl80211_dump_wiphy_state { |
| 1287 | s64 filter_wiphy; |
| 1288 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1289 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1290 | bool split; |
| 1291 | }; |
| 1292 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1293 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1294 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1296 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1297 | { |
| 1298 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1299 | struct nlattr *nl_bands, *nl_band; |
| 1300 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1301 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1302 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1303 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1304 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1305 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1307 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1308 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1309 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1310 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | return -ENOBUFS; |
| 1312 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1313 | if (WARN_ON(!state)) |
| 1314 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1315 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1317 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1318 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1319 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1321 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1322 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1323 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1324 | goto finish; |
| 1325 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1326 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | case 0: |
| 1328 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1332 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1333 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1335 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1336 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1337 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1341 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1343 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1345 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1347 | rdev->wiphy.max_match_sets) || |
| 1348 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1349 | rdev->wiphy.max_sched_scan_plans) || |
| 1350 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1351 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1352 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1353 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1354 | goto nla_put_failure; |
| 1355 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1356 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1358 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1359 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1361 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1362 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1364 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1365 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1367 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1369 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1370 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1373 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1374 | state->split_start++; |
| 1375 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1376 | break; |
| 1377 | case 1: |
| 1378 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1379 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1380 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1381 | goto nla_put_failure; |
| 1382 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1384 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1385 | goto nla_put_failure; |
| 1386 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1387 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1388 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1389 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1390 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1392 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1394 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1396 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1397 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1398 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1399 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1400 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1401 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1402 | if ((rdev->wiphy.available_antennas_tx || |
| 1403 | rdev->wiphy.available_antennas_rx) && |
| 1404 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1405 | u32 tx_ant = 0, rx_ant = 0; |
| 1406 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1407 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1408 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1409 | if (!res) { |
| 1410 | if (nla_put_u32(msg, |
| 1411 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1412 | tx_ant) || |
| 1413 | nla_put_u32(msg, |
| 1414 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1415 | rx_ant)) |
| 1416 | goto nla_put_failure; |
| 1417 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1418 | } |
| 1419 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1420 | state->split_start++; |
| 1421 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1422 | break; |
| 1423 | case 2: |
| 1424 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1425 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | state->split_start++; |
| 1428 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | break; |
| 1430 | case 3: |
| 1431 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1432 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1433 | goto nla_put_failure; |
| 1434 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1436 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | struct ieee80211_supported_band *sband; |
| 1438 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1439 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | |
| 1441 | if (!sband) |
| 1442 | continue; |
| 1443 | |
| 1444 | nl_band = nla_nest_start(msg, band); |
| 1445 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1446 | goto nla_put_failure; |
| 1447 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1448 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1449 | case 0: |
| 1450 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1451 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1452 | state->chan_start++; |
| 1453 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | break; |
| 1455 | default: |
| 1456 | /* add frequencies */ |
| 1457 | nl_freqs = nla_nest_start( |
| 1458 | msg, NL80211_BAND_ATTR_FREQS); |
| 1459 | if (!nl_freqs) |
| 1460 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1461 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1462 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | i < sband->n_channels; |
| 1464 | i++) { |
| 1465 | nl_freq = nla_nest_start(msg, i); |
| 1466 | if (!nl_freq) |
| 1467 | goto nla_put_failure; |
| 1468 | |
| 1469 | chan = &sband->channels[i]; |
| 1470 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1471 | if (nl80211_msg_put_channel( |
| 1472 | msg, chan, |
| 1473 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | goto nla_put_failure; |
| 1475 | |
| 1476 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1477 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | break; |
| 1479 | } |
| 1480 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1481 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1483 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | nla_nest_end(msg, nl_freqs); |
| 1485 | } |
| 1486 | |
| 1487 | nla_nest_end(msg, nl_band); |
| 1488 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1489 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1490 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1491 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | band--; |
| 1493 | break; |
| 1494 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1495 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1497 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1498 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1499 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1500 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1501 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1502 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1504 | if (state->band_start == 0 && state->chan_start == 0) |
| 1505 | state->split_start++; |
| 1506 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | break; |
| 1508 | case 4: |
| 1509 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1510 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1511 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | |
| 1513 | i = 0; |
| 1514 | #define CMD(op, n) \ |
| 1515 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1516 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1517 | i++; \ |
| 1518 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1519 | goto nla_put_failure; \ |
| 1520 | } \ |
| 1521 | } while (0) |
| 1522 | |
| 1523 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1524 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1525 | CMD(add_key, NEW_KEY); |
| 1526 | CMD(start_ap, START_AP); |
| 1527 | CMD(add_station, NEW_STATION); |
| 1528 | CMD(add_mpath, NEW_MPATH); |
| 1529 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1530 | CMD(change_bss, SET_BSS); |
| 1531 | CMD(auth, AUTHENTICATE); |
| 1532 | CMD(assoc, ASSOCIATE); |
| 1533 | CMD(deauth, DEAUTHENTICATE); |
| 1534 | CMD(disassoc, DISASSOCIATE); |
| 1535 | CMD(join_ibss, JOIN_IBSS); |
| 1536 | CMD(join_mesh, JOIN_MESH); |
| 1537 | CMD(set_pmksa, SET_PMKSA); |
| 1538 | CMD(del_pmksa, DEL_PMKSA); |
| 1539 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1540 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1542 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1543 | CMD(mgmt_tx, FRAME); |
| 1544 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1545 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | i++; |
| 1547 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1548 | goto nla_put_failure; |
| 1549 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1550 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1551 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | i++; |
| 1553 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1554 | goto nla_put_failure; |
| 1555 | } |
| 1556 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1557 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1558 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1559 | CMD(tdls_oper, TDLS_OPER); |
| 1560 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1561 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1563 | CMD(probe_client, PROBE_CLIENT); |
| 1564 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | i++; |
| 1567 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1568 | goto nla_put_failure; |
| 1569 | } |
| 1570 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1571 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1572 | #ifdef CONFIG_NL80211_TESTMODE |
| 1573 | CMD(testmode_cmd, TESTMODE); |
| 1574 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1576 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1577 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1579 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1580 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1581 | if (rdev->wiphy.features & |
| 1582 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1583 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1584 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1585 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1586 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1587 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1588 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | i++; |
| 1590 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1591 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1592 | } |
| 1593 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1594 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1595 | i++; |
| 1596 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1597 | goto nla_put_failure; |
| 1598 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1599 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1601 | state->split_start++; |
| 1602 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | break; |
| 1604 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1605 | if (rdev->ops->remain_on_channel && |
| 1606 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1607 | nla_put_u32(msg, |
| 1608 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1609 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1610 | goto nla_put_failure; |
| 1611 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1612 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1614 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1615 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1617 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1618 | state->split_start++; |
| 1619 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1620 | break; |
| 1621 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1622 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1623 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1624 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1625 | state->split_start++; |
| 1626 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1627 | break; |
| 1628 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1629 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | #endif |
| 1631 | case 7: |
| 1632 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1634 | goto nla_put_failure; |
| 1635 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1636 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1637 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1638 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1639 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1640 | state->split_start++; |
| 1641 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1642 | break; |
| 1643 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1644 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | goto nla_put_failure; |
| 1648 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1649 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1650 | /* |
| 1651 | * We can only add the per-channel limit information if the |
| 1652 | * dump is split, otherwise it makes it too big. Therefore |
| 1653 | * only advertise it in that case. |
| 1654 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1655 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1656 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1657 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | goto nla_put_failure; |
| 1659 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1660 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1661 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1662 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1663 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1664 | goto nla_put_failure; |
| 1665 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1666 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1667 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1668 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1669 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1670 | goto nla_put_failure; |
| 1671 | |
| 1672 | /* |
| 1673 | * Any information below this point is only available to |
| 1674 | * applications that can deal with it being split. This |
| 1675 | * helps ensure that newly added capabilities don't break |
| 1676 | * older tools by overrunning their buffers. |
| 1677 | * |
| 1678 | * We still increment split_start so that in the split |
| 1679 | * case we'll continue with more data in the next round, |
| 1680 | * but break unconditionally so unsplit data stops here. |
| 1681 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1682 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | break; |
| 1684 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1685 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1686 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1687 | rdev->wiphy.extended_capabilities_len, |
| 1688 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1689 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | rdev->wiphy.extended_capabilities_len, |
| 1691 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1692 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1693 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1694 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1695 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1696 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1697 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1698 | goto nla_put_failure; |
| 1699 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1700 | state->split_start++; |
| 1701 | break; |
| 1702 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1704 | goto nla_put_failure; |
| 1705 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1706 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1707 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1708 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1709 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1710 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1711 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1712 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1713 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1714 | goto nla_put_failure; |
| 1715 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1716 | state->split_start++; |
| 1717 | break; |
| 1718 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1720 | const struct nl80211_vendor_cmd_info *info; |
| 1721 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1722 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1723 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1724 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1725 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1726 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1727 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1728 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1729 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1730 | goto nla_put_failure; |
| 1731 | } |
| 1732 | nla_nest_end(msg, nested); |
| 1733 | } |
| 1734 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1735 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1736 | const struct nl80211_vendor_cmd_info *info; |
| 1737 | struct nlattr *nested; |
| 1738 | |
| 1739 | nested = nla_nest_start(msg, |
| 1740 | NL80211_ATTR_VENDOR_EVENTS); |
| 1741 | if (!nested) |
| 1742 | goto nla_put_failure; |
| 1743 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1744 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1745 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1746 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1747 | goto nla_put_failure; |
| 1748 | } |
| 1749 | nla_nest_end(msg, nested); |
| 1750 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1751 | state->split_start++; |
| 1752 | break; |
| 1753 | case 12: |
| 1754 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1755 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1756 | rdev->wiphy.max_num_csa_counters)) |
| 1757 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1758 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1759 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1760 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1761 | goto nla_put_failure; |
| 1762 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1763 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1764 | sizeof(rdev->wiphy.ext_features), |
| 1765 | rdev->wiphy.ext_features)) |
| 1766 | goto nla_put_failure; |
| 1767 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1768 | if (rdev->wiphy.bss_select_support) { |
| 1769 | struct nlattr *nested; |
| 1770 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1771 | |
| 1772 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1773 | if (!nested) |
| 1774 | goto nla_put_failure; |
| 1775 | |
| 1776 | i = 0; |
| 1777 | while (bss_select_support) { |
| 1778 | if ((bss_select_support & 1) && |
| 1779 | nla_put_flag(msg, i)) |
| 1780 | goto nla_put_failure; |
| 1781 | i++; |
| 1782 | bss_select_support >>= 1; |
| 1783 | } |
| 1784 | nla_nest_end(msg, nested); |
| 1785 | } |
| 1786 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1787 | state->split_start++; |
| 1788 | break; |
| 1789 | case 13: |
| 1790 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1791 | rdev->wiphy.iftype_ext_capab) { |
| 1792 | struct nlattr *nested_ext_capab, *nested; |
| 1793 | |
| 1794 | nested = nla_nest_start(msg, |
| 1795 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1796 | if (!nested) |
| 1797 | goto nla_put_failure; |
| 1798 | |
| 1799 | for (i = state->capa_start; |
| 1800 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1801 | const struct wiphy_iftype_ext_capab *capab; |
| 1802 | |
| 1803 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1804 | |
| 1805 | nested_ext_capab = nla_nest_start(msg, i); |
| 1806 | if (!nested_ext_capab || |
| 1807 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1808 | capab->iftype) || |
| 1809 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1810 | capab->extended_capabilities_len, |
| 1811 | capab->extended_capabilities) || |
| 1812 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1813 | capab->extended_capabilities_len, |
| 1814 | capab->extended_capabilities_mask)) |
| 1815 | goto nla_put_failure; |
| 1816 | |
| 1817 | nla_nest_end(msg, nested_ext_capab); |
| 1818 | if (state->split) |
| 1819 | break; |
| 1820 | } |
| 1821 | nla_nest_end(msg, nested); |
| 1822 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1823 | state->capa_start = i + 1; |
| 1824 | break; |
| 1825 | } |
| 1826 | } |
| 1827 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1828 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1829 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1830 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1831 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1832 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1833 | genlmsg_end(msg, hdr); |
| 1834 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1835 | |
| 1836 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1837 | genlmsg_cancel(msg, hdr); |
| 1838 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1839 | } |
| 1840 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1841 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1842 | struct netlink_callback *cb, |
| 1843 | struct nl80211_dump_wiphy_state *state) |
| 1844 | { |
| 1845 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1846 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1847 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1848 | /* ignore parse errors for backward compatibility */ |
| 1849 | if (ret) |
| 1850 | return 0; |
| 1851 | |
| 1852 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1853 | if (tb[NL80211_ATTR_WIPHY]) |
| 1854 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1855 | if (tb[NL80211_ATTR_WDEV]) |
| 1856 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1857 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1858 | struct net_device *netdev; |
| 1859 | struct cfg80211_registered_device *rdev; |
| 1860 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1861 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1862 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1863 | if (!netdev) |
| 1864 | return -ENODEV; |
| 1865 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1866 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1867 | netdev->ieee80211_ptr->wiphy); |
| 1868 | state->filter_wiphy = rdev->wiphy_idx; |
| 1869 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1870 | } |
| 1871 | |
| 1872 | return 0; |
| 1873 | } |
| 1874 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1875 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1876 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1877 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1878 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1879 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1880 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1881 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1882 | if (!state) { |
| 1883 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1884 | if (!state) { |
| 1885 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1886 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1887 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1888 | state->filter_wiphy = -1; |
| 1889 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1890 | if (ret) { |
| 1891 | kfree(state); |
| 1892 | rtnl_unlock(); |
| 1893 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1894 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1895 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1896 | } |
| 1897 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1898 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1899 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1900 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1901 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1902 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1903 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1904 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1905 | continue; |
| 1906 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1907 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1908 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1909 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1910 | NETLINK_CB(cb->skb).portid, |
| 1911 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1912 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1913 | if (ret < 0) { |
| 1914 | /* |
| 1915 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1916 | * or EMSGSIZE returned), this SKB is still |
| 1917 | * empty (so it's not too big because another |
| 1918 | * wiphy dataset is already in the skb) and |
| 1919 | * we've not tried to adjust the dump allocation |
| 1920 | * yet ... then adjust the alloc size to be |
| 1921 | * bigger, and return 1 but with the empty skb. |
| 1922 | * This results in an empty message being RX'ed |
| 1923 | * in userspace, but that is ignored. |
| 1924 | * |
| 1925 | * We can then retry with the larger buffer. |
| 1926 | */ |
| 1927 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1928 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1929 | cb->min_dump_alloc < 4096) { |
| 1930 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1931 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1932 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1933 | return 1; |
| 1934 | } |
| 1935 | idx--; |
| 1936 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1937 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1938 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1939 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1940 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1941 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1942 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1943 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1944 | |
| 1945 | return skb->len; |
| 1946 | } |
| 1947 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1948 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1949 | { |
| 1950 | kfree((void *)cb->args[0]); |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1955 | { |
| 1956 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1958 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1959 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1960 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1961 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1962 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1963 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1964 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1965 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1966 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | nlmsg_free(msg); |
| 1968 | return -ENOBUFS; |
| 1969 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1970 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1971 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1974 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1975 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1976 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1977 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1978 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1979 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1980 | }; |
| 1981 | |
| 1982 | static int parse_txq_params(struct nlattr *tb[], |
| 1983 | struct ieee80211_txq_params *txq_params) |
| 1984 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1985 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1986 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1987 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1988 | return -EINVAL; |
| 1989 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1990 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1991 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1992 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1993 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1994 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1995 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1996 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1997 | return -EINVAL; |
| 1998 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1999 | return 0; |
| 2000 | } |
| 2001 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2003 | { |
| 2004 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2005 | * You can only set the channel explicitly for WDS interfaces, |
| 2006 | * all others have their channel managed via their respective |
| 2007 | * "establish a connection" command (connect, join, ...) |
| 2008 | * |
| 2009 | * For AP/GO and mesh mode, the channel can be set with the |
| 2010 | * channel userspace API, but is only stored and passed to the |
| 2011 | * low-level driver when the AP starts or the mesh is joined. |
| 2012 | * This is for backward compatibility, userspace can also give |
| 2013 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2014 | * |
| 2015 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2016 | * whatever else is going on, so they have their own special |
| 2017 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2018 | */ |
| 2019 | return !wdev || |
| 2020 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2021 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2022 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2023 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2024 | } |
| 2025 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2026 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2027 | struct genl_info *info, |
| 2028 | struct cfg80211_chan_def *chandef) |
| 2029 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2030 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2031 | |
| 2032 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2033 | return -EINVAL; |
| 2034 | |
| 2035 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2036 | |
| 2037 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2038 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2039 | chandef->center_freq1 = control_freq; |
| 2040 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2041 | |
| 2042 | /* Primary channel not allowed */ |
| 2043 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2044 | return -EINVAL; |
| 2045 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2046 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2047 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2048 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2049 | chantype = nla_get_u32( |
| 2050 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2051 | |
| 2052 | switch (chantype) { |
| 2053 | case NL80211_CHAN_NO_HT: |
| 2054 | case NL80211_CHAN_HT20: |
| 2055 | case NL80211_CHAN_HT40PLUS: |
| 2056 | case NL80211_CHAN_HT40MINUS: |
| 2057 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2058 | chantype); |
| 2059 | break; |
| 2060 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2061 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2062 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2063 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2064 | chandef->width = |
| 2065 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2066 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2067 | chandef->center_freq1 = |
| 2068 | nla_get_u32( |
| 2069 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2070 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2071 | chandef->center_freq2 = |
| 2072 | nla_get_u32( |
| 2073 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2074 | } |
| 2075 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2076 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2077 | return -EINVAL; |
| 2078 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2079 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2080 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2081 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2082 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2083 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2084 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2085 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2086 | return -EINVAL; |
| 2087 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2088 | return 0; |
| 2089 | } |
| 2090 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2091 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2092 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2093 | struct genl_info *info) |
| 2094 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2095 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2096 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2097 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2098 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2099 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2100 | if (dev) |
| 2101 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2102 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2103 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2104 | if (wdev) |
| 2105 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2106 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2107 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2108 | if (result) |
| 2109 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2110 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2111 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2112 | case NL80211_IFTYPE_AP: |
| 2113 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2114 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2115 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2116 | result = -EINVAL; |
| 2117 | break; |
| 2118 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2119 | if (wdev->beacon_interval) { |
| 2120 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2121 | !(rdev->wiphy.features & |
| 2122 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2123 | result = -EBUSY; |
| 2124 | break; |
| 2125 | } |
| 2126 | |
| 2127 | /* Only allow dynamic channel width changes */ |
| 2128 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2129 | result = -EBUSY; |
| 2130 | break; |
| 2131 | } |
| 2132 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2133 | if (result) |
| 2134 | break; |
| 2135 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2136 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2137 | result = 0; |
| 2138 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2139 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2140 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2141 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2142 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2143 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2144 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2145 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2146 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2147 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2148 | |
| 2149 | return result; |
| 2150 | } |
| 2151 | |
| 2152 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2155 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2156 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2157 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2158 | } |
| 2159 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2160 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2161 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2163 | struct net_device *dev = info->user_ptr[1]; |
| 2164 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2165 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2166 | |
| 2167 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2168 | return -EINVAL; |
| 2169 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2170 | if (netif_running(dev)) |
| 2171 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2172 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2173 | if (!rdev->ops->set_wds_peer) |
| 2174 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2175 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2176 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2177 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2178 | |
| 2179 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2180 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2181 | } |
| 2182 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2183 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2184 | { |
| 2185 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2186 | struct net_device *netdev = NULL; |
| 2187 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2188 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2189 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2190 | u32 changed; |
| 2191 | u8 retry_short = 0, retry_long = 0; |
| 2192 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2193 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2194 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2195 | ASSERT_RTNL(); |
| 2196 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2197 | /* |
| 2198 | * Try to find the wiphy and netdev. Normally this |
| 2199 | * function shouldn't need the netdev, but this is |
| 2200 | * done for backward compatibility -- previously |
| 2201 | * setting the channel was done per wiphy, but now |
| 2202 | * it is per netdev. Previous userland like hostapd |
| 2203 | * also passed a netdev to set_wiphy, so that it is |
| 2204 | * possible to let that go to the right netdev! |
| 2205 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2206 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2207 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2208 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2209 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2210 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2211 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2212 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2213 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2214 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2215 | } |
| 2216 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2217 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2218 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2219 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2220 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2221 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2222 | wdev = NULL; |
| 2223 | netdev = NULL; |
| 2224 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2225 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2226 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2227 | |
| 2228 | /* |
| 2229 | * end workaround code, by now the rdev is available |
| 2230 | * and locked, and wdev may or may not be NULL. |
| 2231 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2232 | |
| 2233 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2234 | result = cfg80211_dev_rename( |
| 2235 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2236 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2237 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2238 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2240 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2241 | struct ieee80211_txq_params txq_params; |
| 2242 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2243 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2244 | if (!rdev->ops->set_txq_params) |
| 2245 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2246 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2247 | if (!netdev) |
| 2248 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2249 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2250 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2251 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2252 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2253 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2254 | if (!netif_running(netdev)) |
| 2255 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2256 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2257 | nla_for_each_nested(nl_txq_params, |
| 2258 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2259 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2260 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2261 | nla_data(nl_txq_params), |
| 2262 | nla_len(nl_txq_params), |
| 2263 | txq_params_policy); |
| 2264 | if (result) |
| 2265 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2266 | result = parse_txq_params(tb, &txq_params); |
| 2267 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2268 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2269 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2270 | result = rdev_set_txq_params(rdev, netdev, |
| 2271 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2272 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2273 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2277 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2278 | result = __nl80211_set_channel( |
| 2279 | rdev, |
| 2280 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2281 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2282 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2283 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2284 | } |
| 2285 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2286 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2287 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2288 | enum nl80211_tx_power_setting type; |
| 2289 | int idx, mbm = 0; |
| 2290 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2291 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2292 | txp_wdev = NULL; |
| 2293 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2294 | if (!rdev->ops->set_tx_power) |
| 2295 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2296 | |
| 2297 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2298 | type = nla_get_u32(info->attrs[idx]); |
| 2299 | |
| 2300 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2301 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2302 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2303 | |
| 2304 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2305 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2306 | mbm = nla_get_u32(info->attrs[idx]); |
| 2307 | } |
| 2308 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2309 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2310 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2311 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2312 | } |
| 2313 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2314 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2315 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2316 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2317 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2318 | if ((!rdev->wiphy.available_antennas_tx && |
| 2319 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2320 | !rdev->ops->set_antenna) |
| 2321 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2322 | |
| 2323 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2324 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2325 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2326 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2327 | * available antenna masks, except for the "all" mask */ |
| 2328 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2330 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2331 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2332 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2333 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2334 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2335 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2336 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2337 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2338 | } |
| 2339 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2340 | changed = 0; |
| 2341 | |
| 2342 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2343 | retry_short = nla_get_u8( |
| 2344 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2345 | if (retry_short == 0) |
| 2346 | return -EINVAL; |
| 2347 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2348 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2349 | } |
| 2350 | |
| 2351 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2352 | retry_long = nla_get_u8( |
| 2353 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2354 | if (retry_long == 0) |
| 2355 | return -EINVAL; |
| 2356 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2357 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2358 | } |
| 2359 | |
| 2360 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2361 | frag_threshold = nla_get_u32( |
| 2362 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2363 | if (frag_threshold < 256) |
| 2364 | return -EINVAL; |
| 2365 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2366 | if (frag_threshold != (u32) -1) { |
| 2367 | /* |
| 2368 | * Fragments (apart from the last one) are required to |
| 2369 | * have even length. Make the fragmentation code |
| 2370 | * simpler by stripping LSB should someone try to use |
| 2371 | * odd threshold value. |
| 2372 | */ |
| 2373 | frag_threshold &= ~0x1; |
| 2374 | } |
| 2375 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2376 | } |
| 2377 | |
| 2378 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2379 | rts_threshold = nla_get_u32( |
| 2380 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2381 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2382 | } |
| 2383 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2384 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2385 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2386 | return -EINVAL; |
| 2387 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2388 | coverage_class = nla_get_u8( |
| 2389 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2390 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2391 | } |
| 2392 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2393 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2394 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2395 | return -EOPNOTSUPP; |
| 2396 | |
| 2397 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2398 | } |
| 2399 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2400 | if (changed) { |
| 2401 | u8 old_retry_short, old_retry_long; |
| 2402 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2403 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2404 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2405 | if (!rdev->ops->set_wiphy_params) |
| 2406 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2407 | |
| 2408 | old_retry_short = rdev->wiphy.retry_short; |
| 2409 | old_retry_long = rdev->wiphy.retry_long; |
| 2410 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2411 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2412 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2413 | |
| 2414 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2415 | rdev->wiphy.retry_short = retry_short; |
| 2416 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2417 | rdev->wiphy.retry_long = retry_long; |
| 2418 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2419 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2420 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2421 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2422 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2423 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2424 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2425 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2426 | if (result) { |
| 2427 | rdev->wiphy.retry_short = old_retry_short; |
| 2428 | rdev->wiphy.retry_long = old_retry_long; |
| 2429 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2430 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2431 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2432 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2433 | } |
| 2434 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2435 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2438 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2439 | { |
| 2440 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2441 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2442 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2443 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2444 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2445 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2446 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2447 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2448 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2449 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2451 | chandef->chan->center_freq)) |
| 2452 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2453 | switch (chandef->width) { |
| 2454 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2455 | case NL80211_CHAN_WIDTH_20: |
| 2456 | case NL80211_CHAN_WIDTH_40: |
| 2457 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2458 | cfg80211_get_chandef_type(chandef))) |
| 2459 | return -ENOBUFS; |
| 2460 | break; |
| 2461 | default: |
| 2462 | break; |
| 2463 | } |
| 2464 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2465 | return -ENOBUFS; |
| 2466 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2467 | return -ENOBUFS; |
| 2468 | if (chandef->center_freq2 && |
| 2469 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2470 | return -ENOBUFS; |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2474 | 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] | 2475 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2476 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2477 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2478 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2479 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2480 | void *hdr; |
| 2481 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2482 | if (removal) |
| 2483 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2484 | |
| 2485 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2486 | if (!hdr) |
| 2487 | return -1; |
| 2488 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2489 | if (dev && |
| 2490 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2491 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2492 | goto nla_put_failure; |
| 2493 | |
| 2494 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2495 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2496 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2497 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2498 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2499 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2500 | rdev->devlist_generation ^ |
| 2501 | (cfg80211_rdev_list_generation << 2))) |
| 2502 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2503 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2504 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2505 | int ret; |
| 2506 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2507 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2508 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2509 | if (ret == 0) { |
| 2510 | if (nl80211_send_chandef(msg, &chandef)) |
| 2511 | goto nla_put_failure; |
| 2512 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2513 | } |
| 2514 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2515 | if (rdev->ops->get_tx_power) { |
| 2516 | int dbm, ret; |
| 2517 | |
| 2518 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2519 | if (ret == 0 && |
| 2520 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2521 | DBM_TO_MBM(dbm))) |
| 2522 | goto nla_put_failure; |
| 2523 | } |
| 2524 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2525 | if (wdev->ssid_len) { |
| 2526 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2527 | goto nla_put_failure; |
| 2528 | } |
| 2529 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2530 | genlmsg_end(msg, hdr); |
| 2531 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2532 | |
| 2533 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2534 | genlmsg_cancel(msg, hdr); |
| 2535 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2539 | { |
| 2540 | int wp_idx = 0; |
| 2541 | int if_idx = 0; |
| 2542 | int wp_start = cb->args[0]; |
| 2543 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2544 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2545 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2546 | struct wireless_dev *wdev; |
| 2547 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2548 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2549 | if (!cb->args[2]) { |
| 2550 | struct nl80211_dump_wiphy_state state = { |
| 2551 | .filter_wiphy = -1, |
| 2552 | }; |
| 2553 | int ret; |
| 2554 | |
| 2555 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2556 | if (ret) |
| 2557 | return ret; |
| 2558 | |
| 2559 | filter_wiphy = state.filter_wiphy; |
| 2560 | |
| 2561 | /* |
| 2562 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2563 | * value needed to determine that parsing is necessary. |
| 2564 | */ |
| 2565 | if (filter_wiphy >= 0) |
| 2566 | cb->args[2] = filter_wiphy + 1; |
| 2567 | else |
| 2568 | cb->args[2] = -1; |
| 2569 | } else if (cb->args[2] > 0) { |
| 2570 | filter_wiphy = cb->args[2] - 1; |
| 2571 | } |
| 2572 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2573 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2574 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2575 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2576 | if (wp_idx < wp_start) { |
| 2577 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2578 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2579 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2580 | |
| 2581 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2582 | continue; |
| 2583 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2584 | if_idx = 0; |
| 2585 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2586 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2587 | if (if_idx < if_start) { |
| 2588 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2589 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2590 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2591 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2592 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2593 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2594 | goto out; |
| 2595 | } |
| 2596 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2597 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2598 | |
| 2599 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2600 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2601 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2602 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2603 | |
| 2604 | cb->args[0] = wp_idx; |
| 2605 | cb->args[1] = if_idx; |
| 2606 | |
| 2607 | return skb->len; |
| 2608 | } |
| 2609 | |
| 2610 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2611 | { |
| 2612 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2614 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2615 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2617 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2619 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2620 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2621 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2622 | nlmsg_free(msg); |
| 2623 | return -ENOBUFS; |
| 2624 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2625 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2626 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2627 | } |
| 2628 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2629 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2630 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2631 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2632 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2633 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2634 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2635 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2636 | }; |
| 2637 | |
| 2638 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2639 | { |
| 2640 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2641 | int flag; |
| 2642 | |
| 2643 | *mntrflags = 0; |
| 2644 | |
| 2645 | if (!nla) |
| 2646 | return -EINVAL; |
| 2647 | |
| 2648 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2649 | nla, mntr_flags_policy)) |
| 2650 | return -EINVAL; |
| 2651 | |
| 2652 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2653 | if (flags[flag]) |
| 2654 | *mntrflags |= (1<<flag); |
| 2655 | |
| 2656 | return 0; |
| 2657 | } |
| 2658 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2659 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2660 | struct net_device *netdev, u8 use_4addr, |
| 2661 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2662 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2663 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2664 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2665 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2666 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2667 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2668 | |
| 2669 | switch (iftype) { |
| 2670 | case NL80211_IFTYPE_AP_VLAN: |
| 2671 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2672 | return 0; |
| 2673 | break; |
| 2674 | case NL80211_IFTYPE_STATION: |
| 2675 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2676 | return 0; |
| 2677 | break; |
| 2678 | default: |
| 2679 | break; |
| 2680 | } |
| 2681 | |
| 2682 | return -EOPNOTSUPP; |
| 2683 | } |
| 2684 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2685 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2686 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2688 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2689 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2690 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2692 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2693 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2694 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2695 | memset(¶ms, 0, sizeof(params)); |
| 2696 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2697 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2698 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2699 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2700 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2701 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2702 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2703 | if (ntype > NL80211_IFTYPE_MAX) |
| 2704 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2705 | } |
| 2706 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2707 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2708 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2709 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2710 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2711 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2712 | if (netif_running(dev)) |
| 2713 | return -EBUSY; |
| 2714 | |
| 2715 | wdev_lock(wdev); |
| 2716 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2717 | IEEE80211_MAX_MESH_ID_LEN); |
| 2718 | wdev->mesh_id_up_len = |
| 2719 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2720 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2721 | wdev->mesh_id_up_len); |
| 2722 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2725 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2726 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2727 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2728 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2729 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2731 | } else { |
| 2732 | params.use_4addr = -1; |
| 2733 | } |
| 2734 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2735 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2736 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2737 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2738 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2739 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2740 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2741 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2742 | |
| 2743 | flags = &_flags; |
| 2744 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2745 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2746 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2747 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2748 | const u8 *mumimo_groups; |
| 2749 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2750 | |
| 2751 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2752 | return -EOPNOTSUPP; |
| 2753 | |
| 2754 | mumimo_groups = |
| 2755 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2756 | |
| 2757 | /* bits 0 and 63 are reserved and must be zero */ |
| 2758 | if ((mumimo_groups[0] & BIT(7)) || |
| 2759 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2760 | return -EINVAL; |
| 2761 | |
| 2762 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2763 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2764 | change = true; |
| 2765 | } |
| 2766 | |
| 2767 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2768 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2769 | |
| 2770 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2771 | return -EOPNOTSUPP; |
| 2772 | |
| 2773 | nla_memcpy(params.macaddr, |
| 2774 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2775 | ETH_ALEN); |
| 2776 | change = true; |
| 2777 | } |
| 2778 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2779 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2780 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2781 | return -EOPNOTSUPP; |
| 2782 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2783 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2784 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2785 | else |
| 2786 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2787 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2788 | if (!err && params.use_4addr != -1) |
| 2789 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2790 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2791 | return err; |
| 2792 | } |
| 2793 | |
| 2794 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2795 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2797 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2798 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2799 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2800 | int err; |
| 2801 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2802 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2803 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2804 | /* to avoid failing a new interface creation due to pending removal */ |
| 2805 | cfg80211_destroy_ifaces(rdev); |
| 2806 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2807 | memset(¶ms, 0, sizeof(params)); |
| 2808 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2809 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2810 | return -EINVAL; |
| 2811 | |
| 2812 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2813 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2814 | if (type > NL80211_IFTYPE_MAX) |
| 2815 | return -EINVAL; |
| 2816 | } |
| 2817 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2818 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2819 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2820 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2821 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2822 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2823 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2824 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2825 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2826 | ETH_ALEN); |
| 2827 | if (!is_valid_ether_addr(params.macaddr)) |
| 2828 | return -EADDRNOTAVAIL; |
| 2829 | } |
| 2830 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2831 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2832 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2833 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2834 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2835 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2836 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2837 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2838 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2839 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2840 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2841 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2842 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2843 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2844 | return -EOPNOTSUPP; |
| 2845 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2846 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2847 | if (!msg) |
| 2848 | return -ENOMEM; |
| 2849 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2850 | wdev = rdev_add_virtual_intf(rdev, |
| 2851 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2852 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2853 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2854 | if (WARN_ON(!wdev)) { |
| 2855 | nlmsg_free(msg); |
| 2856 | return -EPROTO; |
| 2857 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2858 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2859 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2860 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2861 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2862 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2863 | wdev->owner_nlportid = info->snd_portid; |
| 2864 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2865 | switch (type) { |
| 2866 | case NL80211_IFTYPE_MESH_POINT: |
| 2867 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2868 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2869 | wdev_lock(wdev); |
| 2870 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2871 | IEEE80211_MAX_MESH_ID_LEN); |
| 2872 | wdev->mesh_id_up_len = |
| 2873 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2874 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2875 | wdev->mesh_id_up_len); |
| 2876 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2877 | break; |
| 2878 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2879 | /* |
| 2880 | * P2P Device doesn't have a netdev, so doesn't go |
| 2881 | * through the netdev notifier and must be added here |
| 2882 | */ |
| 2883 | mutex_init(&wdev->mtx); |
| 2884 | INIT_LIST_HEAD(&wdev->event_list); |
| 2885 | spin_lock_init(&wdev->event_lock); |
| 2886 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2887 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2888 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2889 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2890 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2891 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2892 | break; |
| 2893 | default: |
| 2894 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2895 | } |
| 2896 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2897 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2898 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2899 | nlmsg_free(msg); |
| 2900 | return -ENOBUFS; |
| 2901 | } |
| 2902 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2903 | /* |
| 2904 | * For wdevs which have no associated netdev object (e.g. of type |
| 2905 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2906 | * For all other types, the event will be generated from the |
| 2907 | * netdev notifier |
| 2908 | */ |
| 2909 | if (!wdev->netdev) |
| 2910 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2911 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2912 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2916 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2918 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | if (!rdev->ops->del_virtual_intf) |
| 2921 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2922 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2923 | /* |
| 2924 | * If we remove a wireless device without a netdev then clear |
| 2925 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2926 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2927 | * since the wdev has been freed, unlike with a netdev where |
| 2928 | * we need the dev_put() for the netdev to really be freed. |
| 2929 | */ |
| 2930 | if (!wdev->netdev) |
| 2931 | info->user_ptr[1] = NULL; |
| 2932 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 2933 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2934 | } |
| 2935 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2936 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2937 | { |
| 2938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2939 | struct net_device *dev = info->user_ptr[1]; |
| 2940 | u16 noack_map; |
| 2941 | |
| 2942 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2943 | return -EINVAL; |
| 2944 | |
| 2945 | if (!rdev->ops->set_noack_map) |
| 2946 | return -EOPNOTSUPP; |
| 2947 | |
| 2948 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2949 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2950 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2953 | struct get_key_cookie { |
| 2954 | struct sk_buff *msg; |
| 2955 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2956 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2957 | }; |
| 2958 | |
| 2959 | static void get_key_callback(void *c, struct key_params *params) |
| 2960 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2961 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2962 | struct get_key_cookie *cookie = c; |
| 2963 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2964 | if ((params->key && |
| 2965 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2966 | params->key_len, params->key)) || |
| 2967 | (params->seq && |
| 2968 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2969 | params->seq_len, params->seq)) || |
| 2970 | (params->cipher && |
| 2971 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2972 | params->cipher))) |
| 2973 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2974 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2975 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2976 | if (!key) |
| 2977 | goto nla_put_failure; |
| 2978 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2979 | if ((params->key && |
| 2980 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2981 | params->key_len, params->key)) || |
| 2982 | (params->seq && |
| 2983 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2984 | params->seq_len, params->seq)) || |
| 2985 | (params->cipher && |
| 2986 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2987 | params->cipher))) |
| 2988 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2989 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2990 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2991 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2992 | |
| 2993 | nla_nest_end(cookie->msg, key); |
| 2994 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2995 | return; |
| 2996 | nla_put_failure: |
| 2997 | cookie->error = 1; |
| 2998 | } |
| 2999 | |
| 3000 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3003 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3004 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3005 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3006 | const u8 *mac_addr = NULL; |
| 3007 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3008 | struct get_key_cookie cookie = { |
| 3009 | .error = 0, |
| 3010 | }; |
| 3011 | void *hdr; |
| 3012 | struct sk_buff *msg; |
| 3013 | |
| 3014 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3015 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3016 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3017 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3018 | return -EINVAL; |
| 3019 | |
| 3020 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3021 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3022 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3023 | pairwise = !!mac_addr; |
| 3024 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3025 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3026 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3027 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3028 | return -EINVAL; |
| 3029 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3030 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3031 | return -EINVAL; |
| 3032 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3033 | } |
| 3034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3035 | if (!rdev->ops->get_key) |
| 3036 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3037 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3038 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3039 | return -ENOENT; |
| 3040 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3042 | if (!msg) |
| 3043 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3044 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3045 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3046 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3047 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3048 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3049 | |
| 3050 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3051 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3052 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3053 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3054 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3055 | goto nla_put_failure; |
| 3056 | if (mac_addr && |
| 3057 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3058 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3059 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3060 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3061 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3062 | |
| 3063 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3064 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3065 | |
| 3066 | if (cookie.error) |
| 3067 | goto nla_put_failure; |
| 3068 | |
| 3069 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3070 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3071 | |
| 3072 | nla_put_failure: |
| 3073 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3074 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3075 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3076 | return err; |
| 3077 | } |
| 3078 | |
| 3079 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3082 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3083 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3084 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3085 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3086 | err = nl80211_parse_key(info, &key); |
| 3087 | if (err) |
| 3088 | return err; |
| 3089 | |
| 3090 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3091 | return -EINVAL; |
| 3092 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3093 | /* only support setting default key */ |
| 3094 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3095 | return -EINVAL; |
| 3096 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3097 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3098 | |
| 3099 | if (key.def) { |
| 3100 | if (!rdev->ops->set_default_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_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3110 | key.def_uni, key.def_multi); |
| 3111 | |
| 3112 | if (err) |
| 3113 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3114 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3115 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3116 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3117 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3118 | } else { |
| 3119 | if (key.def_uni || !key.def_multi) { |
| 3120 | err = -EINVAL; |
| 3121 | goto out; |
| 3122 | } |
| 3123 | |
| 3124 | if (!rdev->ops->set_default_mgmt_key) { |
| 3125 | err = -EOPNOTSUPP; |
| 3126 | goto out; |
| 3127 | } |
| 3128 | |
| 3129 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3130 | if (err) |
| 3131 | goto out; |
| 3132 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3133 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3134 | if (err) |
| 3135 | goto out; |
| 3136 | |
| 3137 | #ifdef CONFIG_CFG80211_WEXT |
| 3138 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3139 | #endif |
| 3140 | } |
| 3141 | |
| 3142 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3143 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3144 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3145 | return err; |
| 3146 | } |
| 3147 | |
| 3148 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3149 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3151 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3152 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3153 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3154 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3155 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3156 | err = nl80211_parse_key(info, &key); |
| 3157 | if (err) |
| 3158 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3159 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3160 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3161 | return -EINVAL; |
| 3162 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3163 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3164 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3165 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3166 | if (key.type == -1) { |
| 3167 | if (mac_addr) |
| 3168 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3169 | else |
| 3170 | key.type = NL80211_KEYTYPE_GROUP; |
| 3171 | } |
| 3172 | |
| 3173 | /* for now */ |
| 3174 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3175 | key.type != NL80211_KEYTYPE_GROUP) |
| 3176 | return -EINVAL; |
| 3177 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3178 | if (!rdev->ops->add_key) |
| 3179 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3180 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3181 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3182 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3183 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3184 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3185 | |
| 3186 | wdev_lock(dev->ieee80211_ptr); |
| 3187 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3188 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3189 | err = rdev_add_key(rdev, dev, key.idx, |
| 3190 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3191 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3192 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3193 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3194 | return err; |
| 3195 | } |
| 3196 | |
| 3197 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3198 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3200 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3201 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3202 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3203 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3204 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3205 | err = nl80211_parse_key(info, &key); |
| 3206 | if (err) |
| 3207 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3208 | |
| 3209 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3210 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3211 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3212 | if (key.type == -1) { |
| 3213 | if (mac_addr) |
| 3214 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3215 | else |
| 3216 | key.type = NL80211_KEYTYPE_GROUP; |
| 3217 | } |
| 3218 | |
| 3219 | /* for now */ |
| 3220 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3221 | key.type != NL80211_KEYTYPE_GROUP) |
| 3222 | return -EINVAL; |
| 3223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3224 | if (!rdev->ops->del_key) |
| 3225 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3226 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3227 | wdev_lock(dev->ieee80211_ptr); |
| 3228 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3229 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3230 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3231 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3232 | err = -ENOENT; |
| 3233 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3234 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3235 | err = rdev_del_key(rdev, dev, key.idx, |
| 3236 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3237 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3238 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3239 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3240 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3241 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3242 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3243 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3244 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3245 | } |
| 3246 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3247 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3248 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3249 | return err; |
| 3250 | } |
| 3251 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3252 | /* This function returns an error or the number of nested attributes */ |
| 3253 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3254 | { |
| 3255 | struct nlattr *attr; |
| 3256 | int n_entries = 0, tmp; |
| 3257 | |
| 3258 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3259 | if (nla_len(attr) != ETH_ALEN) |
| 3260 | return -EINVAL; |
| 3261 | |
| 3262 | n_entries++; |
| 3263 | } |
| 3264 | |
| 3265 | return n_entries; |
| 3266 | } |
| 3267 | |
| 3268 | /* |
| 3269 | * This function parses ACL information and allocates memory for ACL data. |
| 3270 | * On successful return, the calling function is responsible to free the |
| 3271 | * ACL buffer returned by this function. |
| 3272 | */ |
| 3273 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3274 | struct genl_info *info) |
| 3275 | { |
| 3276 | enum nl80211_acl_policy acl_policy; |
| 3277 | struct nlattr *attr; |
| 3278 | struct cfg80211_acl_data *acl; |
| 3279 | int i = 0, n_entries, tmp; |
| 3280 | |
| 3281 | if (!wiphy->max_acl_mac_addrs) |
| 3282 | return ERR_PTR(-EOPNOTSUPP); |
| 3283 | |
| 3284 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3285 | return ERR_PTR(-EINVAL); |
| 3286 | |
| 3287 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3288 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3289 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3290 | return ERR_PTR(-EINVAL); |
| 3291 | |
| 3292 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3293 | return ERR_PTR(-EINVAL); |
| 3294 | |
| 3295 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3296 | if (n_entries < 0) |
| 3297 | return ERR_PTR(n_entries); |
| 3298 | |
| 3299 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3300 | return ERR_PTR(-ENOTSUPP); |
| 3301 | |
| 3302 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3303 | GFP_KERNEL); |
| 3304 | if (!acl) |
| 3305 | return ERR_PTR(-ENOMEM); |
| 3306 | |
| 3307 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3308 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3309 | i++; |
| 3310 | } |
| 3311 | |
| 3312 | acl->n_acl_entries = n_entries; |
| 3313 | acl->acl_policy = acl_policy; |
| 3314 | |
| 3315 | return acl; |
| 3316 | } |
| 3317 | |
| 3318 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3319 | { |
| 3320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3321 | struct net_device *dev = info->user_ptr[1]; |
| 3322 | struct cfg80211_acl_data *acl; |
| 3323 | int err; |
| 3324 | |
| 3325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3326 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3327 | return -EOPNOTSUPP; |
| 3328 | |
| 3329 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3330 | return -EINVAL; |
| 3331 | |
| 3332 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3333 | if (IS_ERR(acl)) |
| 3334 | return PTR_ERR(acl); |
| 3335 | |
| 3336 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3337 | |
| 3338 | kfree(acl); |
| 3339 | |
| 3340 | return err; |
| 3341 | } |
| 3342 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3343 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3344 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3345 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3346 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3347 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3348 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3349 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3350 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3351 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3352 | return -EINVAL; |
| 3353 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3354 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3355 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3356 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3357 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3358 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3359 | if (!bcn->head_len) |
| 3360 | return -EINVAL; |
| 3361 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3362 | } |
| 3363 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3364 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3365 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3366 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3367 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3368 | } |
| 3369 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3370 | if (!haveinfo) |
| 3371 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3372 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3373 | if (attrs[NL80211_ATTR_IE]) { |
| 3374 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3375 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3376 | } |
| 3377 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3378 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3379 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3380 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3381 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3382 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3383 | } |
| 3384 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3385 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3386 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3387 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3388 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3389 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3390 | } |
| 3391 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3392 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3393 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3394 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3395 | } |
| 3396 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3397 | return 0; |
| 3398 | } |
| 3399 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3400 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3401 | struct cfg80211_ap_settings *params) |
| 3402 | { |
| 3403 | struct wireless_dev *wdev; |
| 3404 | bool ret = false; |
| 3405 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3406 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3407 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3408 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3409 | continue; |
| 3410 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3411 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3412 | continue; |
| 3413 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3414 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3415 | ret = true; |
| 3416 | break; |
| 3417 | } |
| 3418 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3419 | return ret; |
| 3420 | } |
| 3421 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3422 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3423 | enum nl80211_auth_type auth_type, |
| 3424 | enum nl80211_commands cmd) |
| 3425 | { |
| 3426 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3427 | return false; |
| 3428 | |
| 3429 | switch (cmd) { |
| 3430 | case NL80211_CMD_AUTHENTICATE: |
| 3431 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3432 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3433 | return false; |
| 3434 | return true; |
| 3435 | case NL80211_CMD_CONNECT: |
| 3436 | case NL80211_CMD_START_AP: |
| 3437 | /* SAE not supported yet */ |
| 3438 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3439 | return false; |
| 3440 | return true; |
| 3441 | default: |
| 3442 | return false; |
| 3443 | } |
| 3444 | } |
| 3445 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3446 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3447 | { |
| 3448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3449 | struct net_device *dev = info->user_ptr[1]; |
| 3450 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3451 | struct cfg80211_ap_settings params; |
| 3452 | int err; |
| 3453 | |
| 3454 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3455 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3456 | return -EOPNOTSUPP; |
| 3457 | |
| 3458 | if (!rdev->ops->start_ap) |
| 3459 | return -EOPNOTSUPP; |
| 3460 | |
| 3461 | if (wdev->beacon_interval) |
| 3462 | return -EALREADY; |
| 3463 | |
| 3464 | memset(¶ms, 0, sizeof(params)); |
| 3465 | |
| 3466 | /* these are required for START_AP */ |
| 3467 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3468 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3469 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3470 | return -EINVAL; |
| 3471 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3472 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3473 | if (err) |
| 3474 | return err; |
| 3475 | |
| 3476 | params.beacon_interval = |
| 3477 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3478 | params.dtim_period = |
| 3479 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3480 | |
| 3481 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3482 | if (err) |
| 3483 | return err; |
| 3484 | |
| 3485 | /* |
| 3486 | * In theory, some of these attributes should be required here |
| 3487 | * but since they were not used when the command was originally |
| 3488 | * added, keep them optional for old user space programs to let |
| 3489 | * them continue to work with drivers that do not need the |
| 3490 | * additional information -- drivers must check! |
| 3491 | */ |
| 3492 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3493 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3494 | params.ssid_len = |
| 3495 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3496 | if (params.ssid_len == 0 || |
| 3497 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3498 | return -EINVAL; |
| 3499 | } |
| 3500 | |
| 3501 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3502 | params.hidden_ssid = nla_get_u32( |
| 3503 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3504 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3505 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3506 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3507 | return -EINVAL; |
| 3508 | } |
| 3509 | |
| 3510 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3511 | |
| 3512 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3513 | params.auth_type = nla_get_u32( |
| 3514 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3515 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3516 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3517 | return -EINVAL; |
| 3518 | } else |
| 3519 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3520 | |
| 3521 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3522 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3523 | if (err) |
| 3524 | return err; |
| 3525 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3526 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3527 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3528 | return -EOPNOTSUPP; |
| 3529 | params.inactivity_timeout = nla_get_u16( |
| 3530 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3531 | } |
| 3532 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3533 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3534 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3535 | return -EINVAL; |
| 3536 | params.p2p_ctwindow = |
| 3537 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3538 | if (params.p2p_ctwindow > 127) |
| 3539 | return -EINVAL; |
| 3540 | if (params.p2p_ctwindow != 0 && |
| 3541 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3542 | return -EINVAL; |
| 3543 | } |
| 3544 | |
| 3545 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3546 | u8 tmp; |
| 3547 | |
| 3548 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3549 | return -EINVAL; |
| 3550 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3551 | if (tmp > 1) |
| 3552 | return -EINVAL; |
| 3553 | params.p2p_opp_ps = tmp; |
| 3554 | if (params.p2p_opp_ps != 0 && |
| 3555 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3556 | return -EINVAL; |
| 3557 | } |
| 3558 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3559 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3560 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3561 | if (err) |
| 3562 | return err; |
| 3563 | } else if (wdev->preset_chandef.chan) { |
| 3564 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3565 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3566 | return -EINVAL; |
| 3567 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3568 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3569 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3570 | return -EINVAL; |
| 3571 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3572 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3573 | params.smps_mode = |
| 3574 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3575 | switch (params.smps_mode) { |
| 3576 | case NL80211_SMPS_OFF: |
| 3577 | break; |
| 3578 | case NL80211_SMPS_STATIC: |
| 3579 | if (!(rdev->wiphy.features & |
| 3580 | NL80211_FEATURE_STATIC_SMPS)) |
| 3581 | return -EINVAL; |
| 3582 | break; |
| 3583 | case NL80211_SMPS_DYNAMIC: |
| 3584 | if (!(rdev->wiphy.features & |
| 3585 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3586 | return -EINVAL; |
| 3587 | break; |
| 3588 | default: |
| 3589 | return -EINVAL; |
| 3590 | } |
| 3591 | } else { |
| 3592 | params.smps_mode = NL80211_SMPS_OFF; |
| 3593 | } |
| 3594 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3595 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3596 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3597 | return -EOPNOTSUPP; |
| 3598 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3599 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3600 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3601 | if (IS_ERR(params.acl)) |
| 3602 | return PTR_ERR(params.acl); |
| 3603 | } |
| 3604 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3605 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3606 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3607 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3608 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3609 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3610 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3611 | wdev->ssid_len = params.ssid_len; |
| 3612 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3613 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3614 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3615 | |
| 3616 | kfree(params.acl); |
| 3617 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3618 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3619 | } |
| 3620 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3621 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3622 | { |
| 3623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3624 | struct net_device *dev = info->user_ptr[1]; |
| 3625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3626 | struct cfg80211_beacon_data params; |
| 3627 | int err; |
| 3628 | |
| 3629 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3631 | return -EOPNOTSUPP; |
| 3632 | |
| 3633 | if (!rdev->ops->change_beacon) |
| 3634 | return -EOPNOTSUPP; |
| 3635 | |
| 3636 | if (!wdev->beacon_interval) |
| 3637 | return -EINVAL; |
| 3638 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3639 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3640 | if (err) |
| 3641 | return err; |
| 3642 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3643 | wdev_lock(wdev); |
| 3644 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3645 | wdev_unlock(wdev); |
| 3646 | |
| 3647 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | 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] | 3651 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3653 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3654 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3655 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3656 | } |
| 3657 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3658 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3659 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3660 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3661 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3662 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3663 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3664 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3665 | }; |
| 3666 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3667 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3668 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3669 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3670 | { |
| 3671 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3672 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3673 | int flag; |
| 3674 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3675 | /* |
| 3676 | * Try parsing the new attribute first so userspace |
| 3677 | * can specify both for older kernels. |
| 3678 | */ |
| 3679 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3680 | if (nla) { |
| 3681 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3682 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3683 | sta_flags = nla_data(nla); |
| 3684 | params->sta_flags_mask = sta_flags->mask; |
| 3685 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3686 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3687 | if ((params->sta_flags_mask | |
| 3688 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3689 | return -EINVAL; |
| 3690 | return 0; |
| 3691 | } |
| 3692 | |
| 3693 | /* if present, parse the old attribute */ |
| 3694 | |
| 3695 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3696 | if (!nla) |
| 3697 | return 0; |
| 3698 | |
| 3699 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3700 | nla, sta_flags_policy)) |
| 3701 | return -EINVAL; |
| 3702 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3703 | /* |
| 3704 | * Only allow certain flags for interface types so that |
| 3705 | * other attributes are silently ignored. Remember that |
| 3706 | * this is backward compatibility code with old userspace |
| 3707 | * and shouldn't be hit in other cases anyway. |
| 3708 | */ |
| 3709 | switch (iftype) { |
| 3710 | case NL80211_IFTYPE_AP: |
| 3711 | case NL80211_IFTYPE_AP_VLAN: |
| 3712 | case NL80211_IFTYPE_P2P_GO: |
| 3713 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3714 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3715 | BIT(NL80211_STA_FLAG_WME) | |
| 3716 | BIT(NL80211_STA_FLAG_MFP); |
| 3717 | break; |
| 3718 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3719 | case NL80211_IFTYPE_STATION: |
| 3720 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3721 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3722 | break; |
| 3723 | case NL80211_IFTYPE_MESH_POINT: |
| 3724 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3725 | BIT(NL80211_STA_FLAG_MFP) | |
| 3726 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3727 | default: |
| 3728 | return -EINVAL; |
| 3729 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3730 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3731 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3732 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3733 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3734 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3735 | /* no longer support new API additions in old API */ |
| 3736 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3737 | return -EINVAL; |
| 3738 | } |
| 3739 | } |
| 3740 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3741 | return 0; |
| 3742 | } |
| 3743 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3744 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3745 | int attr) |
| 3746 | { |
| 3747 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3748 | u32 bitrate; |
| 3749 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3750 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3751 | |
| 3752 | rate = nla_nest_start(msg, attr); |
| 3753 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3754 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3755 | |
| 3756 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3757 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3758 | /* report 16-bit bitrate only if we can */ |
| 3759 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3760 | if (bitrate > 0 && |
| 3761 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3762 | return false; |
| 3763 | if (bitrate_compat > 0 && |
| 3764 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3765 | return false; |
| 3766 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3767 | switch (info->bw) { |
| 3768 | case RATE_INFO_BW_5: |
| 3769 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3770 | break; |
| 3771 | case RATE_INFO_BW_10: |
| 3772 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3773 | break; |
| 3774 | default: |
| 3775 | WARN_ON(1); |
| 3776 | /* fall through */ |
| 3777 | case RATE_INFO_BW_20: |
| 3778 | rate_flg = 0; |
| 3779 | break; |
| 3780 | case RATE_INFO_BW_40: |
| 3781 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3782 | break; |
| 3783 | case RATE_INFO_BW_80: |
| 3784 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3785 | break; |
| 3786 | case RATE_INFO_BW_160: |
| 3787 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3788 | break; |
| 3789 | } |
| 3790 | |
| 3791 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3792 | return false; |
| 3793 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3794 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3795 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3796 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3797 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3798 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3799 | return false; |
| 3800 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3801 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3802 | return false; |
| 3803 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3804 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3805 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3806 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3807 | return false; |
| 3808 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3809 | |
| 3810 | nla_nest_end(msg, rate); |
| 3811 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3812 | } |
| 3813 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3814 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3815 | int id) |
| 3816 | { |
| 3817 | void *attr; |
| 3818 | int i = 0; |
| 3819 | |
| 3820 | if (!mask) |
| 3821 | return true; |
| 3822 | |
| 3823 | attr = nla_nest_start(msg, id); |
| 3824 | if (!attr) |
| 3825 | return false; |
| 3826 | |
| 3827 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3828 | if (!(mask & BIT(i))) |
| 3829 | continue; |
| 3830 | |
| 3831 | if (nla_put_u8(msg, i, signal[i])) |
| 3832 | return false; |
| 3833 | } |
| 3834 | |
| 3835 | nla_nest_end(msg, attr); |
| 3836 | |
| 3837 | return true; |
| 3838 | } |
| 3839 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3840 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3841 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3842 | struct cfg80211_registered_device *rdev, |
| 3843 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3844 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3845 | { |
| 3846 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3847 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3848 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3849 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3850 | if (!hdr) |
| 3851 | return -1; |
| 3852 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3853 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3854 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3855 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3856 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3857 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3858 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3859 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3860 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3861 | |
| 3862 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3863 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 3864 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3865 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3866 | sinfo->memb)) \ |
| 3867 | goto nla_put_failure; \ |
| 3868 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3869 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 3870 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 3871 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 3872 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 3873 | goto nla_put_failure; \ |
| 3874 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3875 | |
| 3876 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3877 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3878 | |
| 3879 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3880 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3881 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3882 | (u32)sinfo->rx_bytes)) |
| 3883 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3884 | |
| 3885 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3886 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3887 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3888 | (u32)sinfo->tx_bytes)) |
| 3889 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3890 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3891 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 3892 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3893 | PUT_SINFO(LLID, llid, u16); |
| 3894 | PUT_SINFO(PLID, plid, u16); |
| 3895 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3896 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3897 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3898 | switch (rdev->wiphy.signal_type) { |
| 3899 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3900 | PUT_SINFO(SIGNAL, signal, u8); |
| 3901 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3902 | break; |
| 3903 | default: |
| 3904 | break; |
| 3905 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3906 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3907 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3908 | sinfo->chain_signal, |
| 3909 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3910 | goto nla_put_failure; |
| 3911 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3912 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3913 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3914 | sinfo->chain_signal_avg, |
| 3915 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3916 | goto nla_put_failure; |
| 3917 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3918 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3919 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3920 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3921 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3922 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3923 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3924 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3925 | NL80211_STA_INFO_RX_BITRATE)) |
| 3926 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3927 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3928 | |
| 3929 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3930 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3931 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3932 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3933 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3934 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3935 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3936 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3937 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3938 | |
| 3939 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3940 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3941 | if (!bss_param) |
| 3942 | goto nla_put_failure; |
| 3943 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3944 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3945 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3946 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3947 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3948 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3949 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3950 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3951 | sinfo->bss_param.dtim_period) || |
| 3952 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3953 | sinfo->bss_param.beacon_interval)) |
| 3954 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3955 | |
| 3956 | nla_nest_end(msg, bss_param); |
| 3957 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3958 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3959 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3960 | sizeof(struct nl80211_sta_flag_update), |
| 3961 | &sinfo->sta_flags)) |
| 3962 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3963 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3964 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 3965 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 3966 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3967 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3968 | |
| 3969 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3970 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3971 | |
| 3972 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3973 | struct nlattr *tidsattr; |
| 3974 | int tid; |
| 3975 | |
| 3976 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3977 | if (!tidsattr) |
| 3978 | goto nla_put_failure; |
| 3979 | |
| 3980 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3981 | struct cfg80211_tid_stats *tidstats; |
| 3982 | struct nlattr *tidattr; |
| 3983 | |
| 3984 | tidstats = &sinfo->pertid[tid]; |
| 3985 | |
| 3986 | if (!tidstats->filled) |
| 3987 | continue; |
| 3988 | |
| 3989 | tidattr = nla_nest_start(msg, tid + 1); |
| 3990 | if (!tidattr) |
| 3991 | goto nla_put_failure; |
| 3992 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3993 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3994 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3995 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 3996 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3997 | goto nla_put_failure; \ |
| 3998 | } while (0) |
| 3999 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4000 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4001 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4002 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4003 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4004 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4005 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4006 | nla_nest_end(msg, tidattr); |
| 4007 | } |
| 4008 | |
| 4009 | nla_nest_end(msg, tidsattr); |
| 4010 | } |
| 4011 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4012 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4013 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4014 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4015 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4016 | sinfo->assoc_req_ies)) |
| 4017 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4018 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4019 | genlmsg_end(msg, hdr); |
| 4020 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4021 | |
| 4022 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4023 | genlmsg_cancel(msg, hdr); |
| 4024 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4025 | } |
| 4026 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4027 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4028 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4029 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4030 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4031 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4032 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4033 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4034 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4035 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4036 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4037 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4038 | if (err) |
| 4039 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4040 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4041 | if (!wdev->netdev) { |
| 4042 | err = -EINVAL; |
| 4043 | goto out_err; |
| 4044 | } |
| 4045 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4046 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4047 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4048 | goto out_err; |
| 4049 | } |
| 4050 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4051 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4052 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4053 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4054 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4055 | if (err == -ENOENT) |
| 4056 | break; |
| 4057 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4058 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4059 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4060 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4061 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4062 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4063 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4064 | &sinfo) < 0) |
| 4065 | goto out; |
| 4066 | |
| 4067 | sta_idx++; |
| 4068 | } |
| 4069 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4070 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4071 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4072 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4073 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4074 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4075 | |
| 4076 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4077 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4078 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4079 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4082 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4083 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4084 | struct sk_buff *msg; |
| 4085 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4086 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4087 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4088 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4089 | |
| 4090 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4091 | return -EINVAL; |
| 4092 | |
| 4093 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4094 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4095 | if (!rdev->ops->get_station) |
| 4096 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4097 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4098 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4099 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4100 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4101 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4103 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4104 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4105 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4106 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4107 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4108 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4109 | nlmsg_free(msg); |
| 4110 | return -ENOBUFS; |
| 4111 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4112 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4113 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4116 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4117 | struct station_parameters *params, |
| 4118 | enum cfg80211_station_type statype) |
| 4119 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4120 | if (params->listen_interval != -1 && |
| 4121 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4122 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4123 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4124 | if (params->support_p2p_ps != -1 && |
| 4125 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4126 | return -EINVAL; |
| 4127 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4128 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4129 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4130 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4131 | return -EINVAL; |
| 4132 | |
| 4133 | /* When you run into this, adjust the code below for the new flag */ |
| 4134 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4135 | |
| 4136 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4137 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4138 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4139 | /* |
| 4140 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4141 | * code doesn't have the bug of including TDLS in the |
| 4142 | * mask everywhere. |
| 4143 | */ |
| 4144 | if (params->sta_flags_mask & |
| 4145 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4146 | BIT(NL80211_STA_FLAG_MFP) | |
| 4147 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4148 | return -EINVAL; |
| 4149 | break; |
| 4150 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4151 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4152 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4153 | return -EINVAL; |
| 4154 | /* ignore since it can't change */ |
| 4155 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4156 | break; |
| 4157 | default: |
| 4158 | /* disallow mesh-specific things */ |
| 4159 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4160 | return -EINVAL; |
| 4161 | if (params->local_pm) |
| 4162 | return -EINVAL; |
| 4163 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4164 | return -EINVAL; |
| 4165 | } |
| 4166 | |
| 4167 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4168 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4169 | /* TDLS can't be set, ... */ |
| 4170 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4171 | return -EINVAL; |
| 4172 | /* |
| 4173 | * ... but don't bother the driver with it. This works around |
| 4174 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4175 | * TLDS_PEER flag in the mask even for AP mode. |
| 4176 | */ |
| 4177 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4178 | } |
| 4179 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4180 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4181 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4182 | /* reject other things that can't change */ |
| 4183 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4184 | return -EINVAL; |
| 4185 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4186 | return -EINVAL; |
| 4187 | if (params->supported_rates) |
| 4188 | return -EINVAL; |
| 4189 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4190 | return -EINVAL; |
| 4191 | } |
| 4192 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4193 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4194 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4195 | if (params->vlan) |
| 4196 | return -EINVAL; |
| 4197 | } |
| 4198 | |
| 4199 | switch (statype) { |
| 4200 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4201 | /* Use this only for authorizing/unauthorizing a station */ |
| 4202 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4203 | return -EOPNOTSUPP; |
| 4204 | break; |
| 4205 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4206 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4207 | /* accept only the listed bits */ |
| 4208 | if (params->sta_flags_mask & |
| 4209 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4210 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4211 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4212 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4213 | BIT(NL80211_STA_FLAG_WME) | |
| 4214 | BIT(NL80211_STA_FLAG_MFP))) |
| 4215 | return -EINVAL; |
| 4216 | |
| 4217 | /* but authenticated/associated only if driver handles it */ |
| 4218 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4219 | params->sta_flags_mask & |
| 4220 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4221 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4222 | return -EINVAL; |
| 4223 | break; |
| 4224 | case CFG80211_STA_IBSS: |
| 4225 | case CFG80211_STA_AP_STA: |
| 4226 | /* reject any changes other than AUTHORIZED */ |
| 4227 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4228 | return -EINVAL; |
| 4229 | break; |
| 4230 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4231 | /* reject any changes other than AUTHORIZED or WME */ |
| 4232 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4233 | BIT(NL80211_STA_FLAG_WME))) |
| 4234 | return -EINVAL; |
| 4235 | /* force (at least) rates when authorizing */ |
| 4236 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4237 | !params->supported_rates) |
| 4238 | return -EINVAL; |
| 4239 | break; |
| 4240 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4241 | /* reject any changes */ |
| 4242 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4243 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4244 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4245 | return -EINVAL; |
| 4246 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4247 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4248 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4249 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4250 | return -EINVAL; |
| 4251 | break; |
| 4252 | } |
| 4253 | |
| 4254 | return 0; |
| 4255 | } |
| 4256 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4257 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4258 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4259 | * 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] | 4260 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4261 | static struct net_device *get_vlan(struct genl_info *info, |
| 4262 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4263 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4264 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4265 | struct net_device *v; |
| 4266 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4267 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4268 | if (!vlanattr) |
| 4269 | return NULL; |
| 4270 | |
| 4271 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4272 | if (!v) |
| 4273 | return ERR_PTR(-ENODEV); |
| 4274 | |
| 4275 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4276 | ret = -EINVAL; |
| 4277 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4278 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4279 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4280 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4281 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4282 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4283 | ret = -EINVAL; |
| 4284 | goto error; |
| 4285 | } |
| 4286 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4287 | if (!netif_running(v)) { |
| 4288 | ret = -ENETDOWN; |
| 4289 | goto error; |
| 4290 | } |
| 4291 | |
| 4292 | return v; |
| 4293 | error: |
| 4294 | dev_put(v); |
| 4295 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | } |
| 4297 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4298 | static const struct nla_policy |
| 4299 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4300 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4301 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4302 | }; |
| 4303 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4304 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4305 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4306 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4307 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4308 | struct nlattr *nla; |
| 4309 | int err; |
| 4310 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4311 | /* parse WME attributes if present */ |
| 4312 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4313 | return 0; |
| 4314 | |
| 4315 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4316 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4317 | nl80211_sta_wme_policy); |
| 4318 | if (err) |
| 4319 | return err; |
| 4320 | |
| 4321 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4322 | params->uapsd_queues = nla_get_u8( |
| 4323 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4324 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4325 | return -EINVAL; |
| 4326 | |
| 4327 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4328 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4329 | |
| 4330 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4331 | return -EINVAL; |
| 4332 | |
| 4333 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4334 | |
| 4335 | return 0; |
| 4336 | } |
| 4337 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4338 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4339 | struct station_parameters *params) |
| 4340 | { |
| 4341 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4342 | params->supported_channels = |
| 4343 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4344 | params->supported_channels_len = |
| 4345 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4346 | /* |
| 4347 | * Need to include at least one (first channel, number of |
| 4348 | * channels) tuple for each subband, and must have proper |
| 4349 | * tuples for the rest of the data as well. |
| 4350 | */ |
| 4351 | if (params->supported_channels_len < 2) |
| 4352 | return -EINVAL; |
| 4353 | if (params->supported_channels_len % 2) |
| 4354 | return -EINVAL; |
| 4355 | } |
| 4356 | |
| 4357 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4358 | params->supported_oper_classes = |
| 4359 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4360 | params->supported_oper_classes_len = |
| 4361 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4362 | /* |
| 4363 | * The value of the Length field of the Supported Operating |
| 4364 | * Classes element is between 2 and 253. |
| 4365 | */ |
| 4366 | if (params->supported_oper_classes_len < 2 || |
| 4367 | params->supported_oper_classes_len > 253) |
| 4368 | return -EINVAL; |
| 4369 | } |
| 4370 | return 0; |
| 4371 | } |
| 4372 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4373 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4374 | struct station_parameters *params) |
| 4375 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4376 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4377 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4378 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4379 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4380 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4381 | params->ht_capa = |
| 4382 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4383 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4384 | params->vht_capa = |
| 4385 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4386 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4387 | err = nl80211_parse_sta_channel_info(info, params); |
| 4388 | if (err) |
| 4389 | return err; |
| 4390 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4391 | return nl80211_parse_sta_wme(info, params); |
| 4392 | } |
| 4393 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4394 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4395 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4398 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4399 | u8 *mac_addr; |
| 4400 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4401 | |
| 4402 | memset(¶ms, 0, sizeof(params)); |
| 4403 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4404 | if (!rdev->ops->change_station) |
| 4405 | return -EOPNOTSUPP; |
| 4406 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4407 | /* |
| 4408 | * AID and listen_interval properties can be set only for unassociated |
| 4409 | * station. Include these parameters here and will check them in |
| 4410 | * cfg80211_check_station_change(). |
| 4411 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4412 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4413 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4414 | |
| 4415 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4416 | params.listen_interval = |
| 4417 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4418 | else |
| 4419 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4420 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4421 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4422 | u8 tmp; |
| 4423 | |
| 4424 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4425 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4426 | return -EINVAL; |
| 4427 | |
| 4428 | params.support_p2p_ps = tmp; |
| 4429 | } else { |
| 4430 | params.support_p2p_ps = -1; |
| 4431 | } |
| 4432 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4433 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4434 | return -EINVAL; |
| 4435 | |
| 4436 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4437 | |
| 4438 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4439 | params.supported_rates = |
| 4440 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4441 | params.supported_rates_len = |
| 4442 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4443 | } |
| 4444 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4445 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4446 | params.capability = |
| 4447 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4448 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4449 | } |
| 4450 | |
| 4451 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4452 | params.ext_capab = |
| 4453 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4454 | params.ext_capab_len = |
| 4455 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4456 | } |
| 4457 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4458 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4459 | return -EINVAL; |
| 4460 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4461 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4462 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4463 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4464 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4465 | return -EINVAL; |
| 4466 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4467 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4468 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4469 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4470 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4471 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4472 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4473 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4474 | params.peer_aid = nla_get_u16( |
| 4475 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4476 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4477 | return -EINVAL; |
| 4478 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4479 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4480 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4481 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4482 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4483 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4484 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4485 | |
| 4486 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4487 | pm > NL80211_MESH_POWER_MAX) |
| 4488 | return -EINVAL; |
| 4489 | |
| 4490 | params.local_pm = pm; |
| 4491 | } |
| 4492 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4493 | /* Include parameters for TDLS peer (will check later) */ |
| 4494 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4495 | if (err) |
| 4496 | return err; |
| 4497 | |
| 4498 | params.vlan = get_vlan(info, rdev); |
| 4499 | if (IS_ERR(params.vlan)) |
| 4500 | return PTR_ERR(params.vlan); |
| 4501 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4502 | switch (dev->ieee80211_ptr->iftype) { |
| 4503 | case NL80211_IFTYPE_AP: |
| 4504 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4505 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4506 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4507 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4508 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4509 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4510 | break; |
| 4511 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4512 | err = -EOPNOTSUPP; |
| 4513 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4514 | } |
| 4515 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4516 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4517 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4518 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4519 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4520 | if (params.vlan) |
| 4521 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4522 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4523 | return err; |
| 4524 | } |
| 4525 | |
| 4526 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4527 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4529 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4530 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4531 | struct station_parameters params; |
| 4532 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4533 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4534 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4535 | |
| 4536 | memset(¶ms, 0, sizeof(params)); |
| 4537 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4538 | if (!rdev->ops->add_station) |
| 4539 | return -EOPNOTSUPP; |
| 4540 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4541 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4542 | return -EINVAL; |
| 4543 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4544 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4545 | return -EINVAL; |
| 4546 | |
| 4547 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4548 | return -EINVAL; |
| 4549 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4550 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4551 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4552 | return -EINVAL; |
| 4553 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4554 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4555 | params.supported_rates = |
| 4556 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4557 | params.supported_rates_len = |
| 4558 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4559 | params.listen_interval = |
| 4560 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4561 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4562 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4563 | u8 tmp; |
| 4564 | |
| 4565 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4566 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4567 | return -EINVAL; |
| 4568 | |
| 4569 | params.support_p2p_ps = tmp; |
| 4570 | } else { |
| 4571 | /* |
| 4572 | * if not specified, assume it's supported for P2P GO interface, |
| 4573 | * and is NOT supported for AP interface |
| 4574 | */ |
| 4575 | params.support_p2p_ps = |
| 4576 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4577 | } |
| 4578 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4579 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4580 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4581 | else |
| 4582 | 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] | 4583 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4584 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4585 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4586 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4587 | params.capability = |
| 4588 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4589 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4590 | } |
| 4591 | |
| 4592 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4593 | params.ext_capab = |
| 4594 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4595 | params.ext_capab_len = |
| 4596 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4597 | } |
| 4598 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4599 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4600 | params.ht_capa = |
| 4601 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4602 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4603 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4604 | params.vht_capa = |
| 4605 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4606 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4607 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4608 | params.opmode_notif_used = true; |
| 4609 | params.opmode_notif = |
| 4610 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4611 | } |
| 4612 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4613 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4614 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4615 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4616 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4617 | return -EINVAL; |
| 4618 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4619 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4620 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4621 | if (err) |
| 4622 | return err; |
| 4623 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4624 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4625 | if (err) |
| 4626 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4627 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4628 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4629 | return -EINVAL; |
| 4630 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4631 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4632 | * as userspace might just pass through the capabilities from the IEs |
| 4633 | * directly, rather than enforcing this restriction and returning an |
| 4634 | * error in this case. |
| 4635 | */ |
| 4636 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4637 | params.ht_capa = NULL; |
| 4638 | params.vht_capa = NULL; |
| 4639 | } |
| 4640 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4641 | /* When you run into this, adjust the code below for the new flag */ |
| 4642 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4643 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4644 | switch (dev->ieee80211_ptr->iftype) { |
| 4645 | case NL80211_IFTYPE_AP: |
| 4646 | case NL80211_IFTYPE_AP_VLAN: |
| 4647 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4648 | /* ignore WME attributes if iface/sta is not capable */ |
| 4649 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4650 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4651 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4652 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4653 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4654 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4655 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4656 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4657 | /* but don't bother the driver with it */ |
| 4658 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4659 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4660 | /* allow authenticated/associated only if driver handles it */ |
| 4661 | if (!(rdev->wiphy.features & |
| 4662 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4663 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4664 | return -EINVAL; |
| 4665 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4666 | /* Older userspace, or userspace wanting to be compatible with |
| 4667 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 4668 | * and assoc flags in the mask, but assumes the station will be |
| 4669 | * added as associated anyway since this was the required driver |
| 4670 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 4671 | * introduced. |
| 4672 | * In order to not bother drivers with this quirk in the API |
| 4673 | * set the flags in both the mask and set for new stations in |
| 4674 | * this case. |
| 4675 | */ |
| 4676 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 4677 | params.sta_flags_mask |= auth_assoc; |
| 4678 | params.sta_flags_set |= auth_assoc; |
| 4679 | } |
| 4680 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4681 | /* must be last in here for error handling */ |
| 4682 | params.vlan = get_vlan(info, rdev); |
| 4683 | if (IS_ERR(params.vlan)) |
| 4684 | return PTR_ERR(params.vlan); |
| 4685 | break; |
| 4686 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4687 | /* ignore uAPSD data */ |
| 4688 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4689 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4690 | /* associated is disallowed */ |
| 4691 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4692 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4693 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4694 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4695 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4696 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4697 | break; |
| 4698 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4699 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4700 | /* ignore uAPSD data */ |
| 4701 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4702 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4703 | /* these are disallowed */ |
| 4704 | if (params.sta_flags_mask & |
| 4705 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4706 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4707 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4708 | /* Only TDLS peers can be added */ |
| 4709 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4710 | return -EINVAL; |
| 4711 | /* Can only add if TDLS ... */ |
| 4712 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4713 | return -EOPNOTSUPP; |
| 4714 | /* ... with external setup is supported */ |
| 4715 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4716 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4717 | /* |
| 4718 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4719 | * as authorized, but it shouldn't yet be. |
| 4720 | */ |
| 4721 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4722 | break; |
| 4723 | default: |
| 4724 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4725 | } |
| 4726 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4727 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4728 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4729 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4730 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4731 | if (params.vlan) |
| 4732 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4733 | return err; |
| 4734 | } |
| 4735 | |
| 4736 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4737 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4739 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4740 | struct station_del_parameters params; |
| 4741 | |
| 4742 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4743 | |
| 4744 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4745 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4746 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4747 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4748 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4749 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4751 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4753 | if (!rdev->ops->del_station) |
| 4754 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4755 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4756 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4757 | params.subtype = |
| 4758 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4759 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4760 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4761 | return -EINVAL; |
| 4762 | } else { |
| 4763 | /* Default to Deauthentication frame */ |
| 4764 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4765 | } |
| 4766 | |
| 4767 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4768 | params.reason_code = |
| 4769 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4770 | if (params.reason_code == 0) |
| 4771 | return -EINVAL; /* 0 is reserved */ |
| 4772 | } else { |
| 4773 | /* Default to reason code 2 */ |
| 4774 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4775 | } |
| 4776 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4777 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4778 | } |
| 4779 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4780 | 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] | 4781 | int flags, struct net_device *dev, |
| 4782 | u8 *dst, u8 *next_hop, |
| 4783 | struct mpath_info *pinfo) |
| 4784 | { |
| 4785 | void *hdr; |
| 4786 | struct nlattr *pinfoattr; |
| 4787 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4788 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4789 | if (!hdr) |
| 4790 | return -1; |
| 4791 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4792 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4794 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4795 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4796 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4797 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4798 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4799 | if (!pinfoattr) |
| 4800 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4801 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4802 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4803 | pinfo->frame_qlen)) |
| 4804 | goto nla_put_failure; |
| 4805 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4806 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4807 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4808 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4809 | pinfo->metric)) || |
| 4810 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4811 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4812 | pinfo->exptime)) || |
| 4813 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4814 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4815 | pinfo->flags)) || |
| 4816 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4817 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4818 | pinfo->discovery_timeout)) || |
| 4819 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4820 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4821 | pinfo->discovery_retries))) |
| 4822 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4823 | |
| 4824 | nla_nest_end(msg, pinfoattr); |
| 4825 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4826 | genlmsg_end(msg, hdr); |
| 4827 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4828 | |
| 4829 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4830 | genlmsg_cancel(msg, hdr); |
| 4831 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4835 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4836 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4837 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4838 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4839 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4840 | u8 dst[ETH_ALEN]; |
| 4841 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4842 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4843 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4844 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4845 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4846 | if (err) |
| 4847 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4848 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4849 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4850 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4851 | goto out_err; |
| 4852 | } |
| 4853 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4854 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4855 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4856 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4857 | } |
| 4858 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4859 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4860 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4861 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4862 | if (err == -ENOENT) |
| 4863 | break; |
| 4864 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4865 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4866 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4867 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4868 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4869 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4870 | &pinfo) < 0) |
| 4871 | goto out; |
| 4872 | |
| 4873 | path_idx++; |
| 4874 | } |
| 4875 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4876 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4877 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4878 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4879 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4880 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4881 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4885 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4887 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4888 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4889 | struct mpath_info pinfo; |
| 4890 | struct sk_buff *msg; |
| 4891 | u8 *dst = NULL; |
| 4892 | u8 next_hop[ETH_ALEN]; |
| 4893 | |
| 4894 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4895 | |
| 4896 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4897 | return -EINVAL; |
| 4898 | |
| 4899 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4901 | if (!rdev->ops->get_mpath) |
| 4902 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4904 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4905 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4906 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4907 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4908 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4909 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4910 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4911 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4912 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4913 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4914 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4915 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4916 | dev, dst, next_hop, &pinfo) < 0) { |
| 4917 | nlmsg_free(msg); |
| 4918 | return -ENOBUFS; |
| 4919 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4921 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4925 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4927 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4928 | u8 *dst = NULL; |
| 4929 | u8 *next_hop = NULL; |
| 4930 | |
| 4931 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4932 | return -EINVAL; |
| 4933 | |
| 4934 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4935 | return -EINVAL; |
| 4936 | |
| 4937 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4938 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4940 | if (!rdev->ops->change_mpath) |
| 4941 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4942 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4943 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4944 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4945 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4946 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4947 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4949 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4952 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4953 | u8 *dst = NULL; |
| 4954 | u8 *next_hop = NULL; |
| 4955 | |
| 4956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4957 | return -EINVAL; |
| 4958 | |
| 4959 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4960 | return -EINVAL; |
| 4961 | |
| 4962 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4963 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4964 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4965 | if (!rdev->ops->add_mpath) |
| 4966 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4967 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4968 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4969 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4970 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4971 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4975 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4977 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4978 | u8 *dst = NULL; |
| 4979 | |
| 4980 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4981 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4982 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4983 | if (!rdev->ops->del_mpath) |
| 4984 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4986 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4987 | } |
| 4988 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4989 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4990 | { |
| 4991 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4992 | int err; |
| 4993 | struct net_device *dev = info->user_ptr[1]; |
| 4994 | struct mpath_info pinfo; |
| 4995 | struct sk_buff *msg; |
| 4996 | u8 *dst = NULL; |
| 4997 | u8 mpp[ETH_ALEN]; |
| 4998 | |
| 4999 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5000 | |
| 5001 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5002 | return -EINVAL; |
| 5003 | |
| 5004 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5005 | |
| 5006 | if (!rdev->ops->get_mpp) |
| 5007 | return -EOPNOTSUPP; |
| 5008 | |
| 5009 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5010 | return -EOPNOTSUPP; |
| 5011 | |
| 5012 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5013 | if (err) |
| 5014 | return err; |
| 5015 | |
| 5016 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5017 | if (!msg) |
| 5018 | return -ENOMEM; |
| 5019 | |
| 5020 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5021 | dev, dst, mpp, &pinfo) < 0) { |
| 5022 | nlmsg_free(msg); |
| 5023 | return -ENOBUFS; |
| 5024 | } |
| 5025 | |
| 5026 | return genlmsg_reply(msg, info); |
| 5027 | } |
| 5028 | |
| 5029 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5030 | struct netlink_callback *cb) |
| 5031 | { |
| 5032 | struct mpath_info pinfo; |
| 5033 | struct cfg80211_registered_device *rdev; |
| 5034 | struct wireless_dev *wdev; |
| 5035 | u8 dst[ETH_ALEN]; |
| 5036 | u8 mpp[ETH_ALEN]; |
| 5037 | int path_idx = cb->args[2]; |
| 5038 | int err; |
| 5039 | |
| 5040 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5041 | if (err) |
| 5042 | return err; |
| 5043 | |
| 5044 | if (!rdev->ops->dump_mpp) { |
| 5045 | err = -EOPNOTSUPP; |
| 5046 | goto out_err; |
| 5047 | } |
| 5048 | |
| 5049 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5050 | err = -EOPNOTSUPP; |
| 5051 | goto out_err; |
| 5052 | } |
| 5053 | |
| 5054 | while (1) { |
| 5055 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5056 | mpp, &pinfo); |
| 5057 | if (err == -ENOENT) |
| 5058 | break; |
| 5059 | if (err) |
| 5060 | goto out_err; |
| 5061 | |
| 5062 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5063 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5064 | wdev->netdev, dst, mpp, |
| 5065 | &pinfo) < 0) |
| 5066 | goto out; |
| 5067 | |
| 5068 | path_idx++; |
| 5069 | } |
| 5070 | |
| 5071 | out: |
| 5072 | cb->args[2] = path_idx; |
| 5073 | err = skb->len; |
| 5074 | out_err: |
| 5075 | nl80211_finish_wdev_dump(rdev); |
| 5076 | return err; |
| 5077 | } |
| 5078 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5079 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5082 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5083 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5084 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5085 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5086 | |
| 5087 | memset(¶ms, 0, sizeof(params)); |
| 5088 | /* default to not changing parameters */ |
| 5089 | params.use_cts_prot = -1; |
| 5090 | params.use_short_preamble = -1; |
| 5091 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5092 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5093 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5094 | params.p2p_ctwindow = -1; |
| 5095 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5096 | |
| 5097 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5098 | params.use_cts_prot = |
| 5099 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5100 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5101 | params.use_short_preamble = |
| 5102 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5103 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5104 | params.use_short_slot_time = |
| 5105 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5106 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5107 | params.basic_rates = |
| 5108 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5109 | params.basic_rates_len = |
| 5110 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5111 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5112 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5113 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5114 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5115 | params.ht_opmode = |
| 5116 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5117 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5118 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5119 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5120 | return -EINVAL; |
| 5121 | params.p2p_ctwindow = |
| 5122 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5123 | if (params.p2p_ctwindow < 0) |
| 5124 | return -EINVAL; |
| 5125 | if (params.p2p_ctwindow != 0 && |
| 5126 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5127 | return -EINVAL; |
| 5128 | } |
| 5129 | |
| 5130 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5131 | u8 tmp; |
| 5132 | |
| 5133 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5134 | return -EINVAL; |
| 5135 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5136 | if (tmp > 1) |
| 5137 | return -EINVAL; |
| 5138 | params.p2p_opp_ps = tmp; |
| 5139 | if (params.p2p_opp_ps && |
| 5140 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5141 | return -EINVAL; |
| 5142 | } |
| 5143 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | if (!rdev->ops->change_bss) |
| 5145 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5146 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5147 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5148 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5149 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5150 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5151 | wdev_lock(wdev); |
| 5152 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5153 | wdev_unlock(wdev); |
| 5154 | |
| 5155 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5156 | } |
| 5157 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5158 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5159 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5160 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5161 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5162 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5163 | u32 owner_nlportid; |
| 5164 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5165 | /* |
| 5166 | * You should only get this when cfg80211 hasn't yet initialized |
| 5167 | * completely when built-in to the kernel right between the time |
| 5168 | * window between nl80211_init() and regulatory_init(), if that is |
| 5169 | * even possible. |
| 5170 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5171 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5172 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5173 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5174 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5175 | user_reg_hint_type = |
| 5176 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5177 | else |
| 5178 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5179 | |
| 5180 | switch (user_reg_hint_type) { |
| 5181 | case NL80211_USER_REG_HINT_USER: |
| 5182 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5183 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5184 | return -EINVAL; |
| 5185 | |
| 5186 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5187 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5188 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5189 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5190 | owner_nlportid = info->snd_portid; |
| 5191 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5192 | } else { |
| 5193 | owner_nlportid = 0; |
| 5194 | is_indoor = true; |
| 5195 | } |
| 5196 | |
| 5197 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5198 | default: |
| 5199 | return -EINVAL; |
| 5200 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5203 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5204 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5205 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5207 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5208 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5209 | struct mesh_config cur_params; |
| 5210 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5211 | void *hdr; |
| 5212 | struct nlattr *pinfoattr; |
| 5213 | struct sk_buff *msg; |
| 5214 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5215 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5216 | return -EOPNOTSUPP; |
| 5217 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5218 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5219 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5220 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5221 | wdev_lock(wdev); |
| 5222 | /* If not connected, get default parameters */ |
| 5223 | if (!wdev->mesh_id_len) |
| 5224 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5225 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5226 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5227 | wdev_unlock(wdev); |
| 5228 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5229 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5231 | |
| 5232 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5234 | if (!msg) |
| 5235 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5236 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5237 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5238 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5239 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5240 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5241 | if (!pinfoattr) |
| 5242 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5243 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5244 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5245 | cur_params.dot11MeshRetryTimeout) || |
| 5246 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5247 | cur_params.dot11MeshConfirmTimeout) || |
| 5248 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5249 | cur_params.dot11MeshHoldingTimeout) || |
| 5250 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5251 | cur_params.dot11MeshMaxPeerLinks) || |
| 5252 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5253 | cur_params.dot11MeshMaxRetries) || |
| 5254 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5255 | cur_params.dot11MeshTTL) || |
| 5256 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5257 | cur_params.element_ttl) || |
| 5258 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5259 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5260 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5261 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5262 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5263 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5264 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5265 | cur_params.path_refresh_time) || |
| 5266 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5267 | cur_params.min_discovery_timeout) || |
| 5268 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5269 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5270 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5271 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5272 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5273 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5274 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5275 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5276 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5277 | cur_params.dot11MeshHWMPRootMode) || |
| 5278 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5279 | cur_params.dot11MeshHWMPRannInterval) || |
| 5280 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5281 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5282 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5283 | cur_params.dot11MeshForwarding) || |
| 5284 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5285 | cur_params.rssi_threshold) || |
| 5286 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5287 | cur_params.ht_opmode) || |
| 5288 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5289 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5290 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5291 | cur_params.dot11MeshHWMProotInterval) || |
| 5292 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5293 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5294 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5295 | cur_params.power_mode) || |
| 5296 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5297 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5298 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5299 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5300 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5301 | nla_nest_end(msg, pinfoattr); |
| 5302 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5303 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5304 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5305 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5306 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5307 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5308 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5309 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5312 | 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] | 5313 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5314 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5315 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5316 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5317 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5318 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5319 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5320 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5321 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5322 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5323 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5324 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5325 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5326 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5327 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5328 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5329 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5330 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5331 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5332 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5333 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5334 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5335 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5336 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5337 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5338 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5339 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5340 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5341 | }; |
| 5342 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5343 | static const struct nla_policy |
| 5344 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5345 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5346 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5347 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5348 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5349 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5350 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5351 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5352 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5353 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5354 | }; |
| 5355 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5356 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5357 | { |
| 5358 | u8 val = nla_get_u8(nla); |
| 5359 | if (val < min || val > max) |
| 5360 | return -EINVAL; |
| 5361 | *out = val; |
| 5362 | return 0; |
| 5363 | } |
| 5364 | |
| 5365 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5366 | { |
| 5367 | u8 val = nla_get_u8(nla); |
| 5368 | if (val < min || val > max) |
| 5369 | return -EINVAL; |
| 5370 | *out = val; |
| 5371 | return 0; |
| 5372 | } |
| 5373 | |
| 5374 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5375 | { |
| 5376 | u16 val = nla_get_u16(nla); |
| 5377 | if (val < min || val > max) |
| 5378 | return -EINVAL; |
| 5379 | *out = val; |
| 5380 | return 0; |
| 5381 | } |
| 5382 | |
| 5383 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5384 | { |
| 5385 | u32 val = nla_get_u32(nla); |
| 5386 | if (val < min || val > max) |
| 5387 | return -EINVAL; |
| 5388 | *out = val; |
| 5389 | return 0; |
| 5390 | } |
| 5391 | |
| 5392 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5393 | { |
| 5394 | s32 val = nla_get_s32(nla); |
| 5395 | if (val < min || val > max) |
| 5396 | return -EINVAL; |
| 5397 | *out = val; |
| 5398 | return 0; |
| 5399 | } |
| 5400 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5401 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5402 | enum nl80211_mesh_power_mode min, |
| 5403 | enum nl80211_mesh_power_mode max, |
| 5404 | enum nl80211_mesh_power_mode *out) |
| 5405 | { |
| 5406 | u32 val = nla_get_u32(nla); |
| 5407 | if (val < min || val > max) |
| 5408 | return -EINVAL; |
| 5409 | *out = val; |
| 5410 | return 0; |
| 5411 | } |
| 5412 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5413 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5414 | struct mesh_config *cfg, |
| 5415 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5416 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5417 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5418 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5419 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5420 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5421 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5422 | do { \ |
| 5423 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5424 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5425 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5426 | mask |= (1 << (attr - 1)); \ |
| 5427 | } \ |
| 5428 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5429 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5430 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5431 | return -EINVAL; |
| 5432 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5433 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5434 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5435 | return -EINVAL; |
| 5436 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5437 | /* This makes sure that there aren't more than 32 mesh config |
| 5438 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5439 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5440 | |
| 5441 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5442 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5443 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5444 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5445 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5446 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5447 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5448 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5449 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5450 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5451 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5452 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5453 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5454 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5455 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5456 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5457 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5458 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5459 | 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] | 5460 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5461 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5462 | 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] | 5463 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5464 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5465 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5466 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5467 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5468 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5469 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5470 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5471 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5472 | 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] | 5473 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5474 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5475 | 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] | 5476 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5477 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5478 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5479 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5480 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5481 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5482 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5483 | 1, 65535, mask, |
| 5484 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5485 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5486 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5487 | 1, 65535, mask, |
| 5488 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5489 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5490 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5491 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5492 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5493 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5494 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5495 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5496 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5497 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5498 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5499 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5500 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5501 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5502 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5503 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5504 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5505 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5506 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5507 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5508 | 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] | 5509 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5510 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5511 | /* |
| 5512 | * Check HT operation mode based on |
| 5513 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5514 | */ |
| 5515 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5516 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5517 | |
| 5518 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5519 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5520 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5521 | return -EINVAL; |
| 5522 | |
| 5523 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5524 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5525 | return -EINVAL; |
| 5526 | |
| 5527 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5528 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5529 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5530 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 5531 | return -EINVAL; |
| 5532 | break; |
| 5533 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 5534 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 5535 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5536 | return -EINVAL; |
| 5537 | break; |
| 5538 | } |
| 5539 | cfg->ht_opmode = ht_opmode; |
| 5540 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5541 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5542 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5543 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5544 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5545 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5546 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5547 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5548 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5549 | dot11MeshHWMPconfirmationInterval, |
| 5550 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5551 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5552 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5553 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5554 | NL80211_MESH_POWER_ACTIVE, |
| 5555 | NL80211_MESH_POWER_MAX, |
| 5556 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5557 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5558 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5559 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5560 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5561 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5562 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5563 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5564 | if (mask_out) |
| 5565 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5566 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5567 | return 0; |
| 5568 | |
| 5569 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5570 | } |
| 5571 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5572 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5573 | struct mesh_setup *setup) |
| 5574 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5576 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5577 | |
| 5578 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5579 | return -EINVAL; |
| 5580 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5581 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5582 | nl80211_mesh_setup_params_policy)) |
| 5583 | return -EINVAL; |
| 5584 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5585 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5586 | setup->sync_method = |
| 5587 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5588 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5589 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5590 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5591 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5592 | setup->path_sel_proto = |
| 5593 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5594 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5595 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5596 | |
| 5597 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5598 | setup->path_metric = |
| 5599 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5600 | IEEE80211_PATH_METRIC_VENDOR : |
| 5601 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5602 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5603 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5604 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5605 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5606 | if (!is_valid_ie_attr(ieattr)) |
| 5607 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5608 | setup->ie = nla_data(ieattr); |
| 5609 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5610 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5611 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5612 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5613 | return -EINVAL; |
| 5614 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5615 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5616 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5617 | if (setup->is_secure) |
| 5618 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5619 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5620 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5621 | if (!setup->user_mpm) |
| 5622 | return -EINVAL; |
| 5623 | setup->auth_id = |
| 5624 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5625 | } |
| 5626 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5627 | return 0; |
| 5628 | } |
| 5629 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5630 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5631 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5632 | { |
| 5633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5634 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5635 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5636 | struct mesh_config cfg; |
| 5637 | u32 mask; |
| 5638 | int err; |
| 5639 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5640 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5641 | return -EOPNOTSUPP; |
| 5642 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5643 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5644 | return -EOPNOTSUPP; |
| 5645 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5646 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5647 | if (err) |
| 5648 | return err; |
| 5649 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5650 | wdev_lock(wdev); |
| 5651 | if (!wdev->mesh_id_len) |
| 5652 | err = -ENOLINK; |
| 5653 | |
| 5654 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5655 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5656 | |
| 5657 | wdev_unlock(wdev); |
| 5658 | |
| 5659 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5660 | } |
| 5661 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5662 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5663 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5664 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5665 | struct nlattr *nl_reg_rules; |
| 5666 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5667 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5668 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5669 | (regdom->dfs_region && |
| 5670 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5671 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5672 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5673 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5674 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5675 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5676 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5677 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5678 | struct nlattr *nl_reg_rule; |
| 5679 | const struct ieee80211_reg_rule *reg_rule; |
| 5680 | const struct ieee80211_freq_range *freq_range; |
| 5681 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5682 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5683 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5684 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5685 | freq_range = ®_rule->freq_range; |
| 5686 | power_rule = ®_rule->power_rule; |
| 5687 | |
| 5688 | nl_reg_rule = nla_nest_start(msg, i); |
| 5689 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5690 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5691 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5692 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5693 | if (!max_bandwidth_khz) |
| 5694 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5695 | reg_rule); |
| 5696 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5697 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5698 | reg_rule->flags) || |
| 5699 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5700 | freq_range->start_freq_khz) || |
| 5701 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5702 | freq_range->end_freq_khz) || |
| 5703 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5704 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5705 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5706 | power_rule->max_antenna_gain) || |
| 5707 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5708 | power_rule->max_eirp) || |
| 5709 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5710 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5711 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5712 | |
| 5713 | nla_nest_end(msg, nl_reg_rule); |
| 5714 | } |
| 5715 | |
| 5716 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5717 | return 0; |
| 5718 | |
| 5719 | nla_put_failure: |
| 5720 | return -EMSGSIZE; |
| 5721 | } |
| 5722 | |
| 5723 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5724 | { |
| 5725 | const struct ieee80211_regdomain *regdom = NULL; |
| 5726 | struct cfg80211_registered_device *rdev; |
| 5727 | struct wiphy *wiphy = NULL; |
| 5728 | struct sk_buff *msg; |
| 5729 | void *hdr; |
| 5730 | |
| 5731 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5732 | if (!msg) |
| 5733 | return -ENOBUFS; |
| 5734 | |
| 5735 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5736 | NL80211_CMD_GET_REG); |
| 5737 | if (!hdr) |
| 5738 | goto put_failure; |
| 5739 | |
| 5740 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5741 | bool self_managed; |
| 5742 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5743 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5744 | if (IS_ERR(rdev)) { |
| 5745 | nlmsg_free(msg); |
| 5746 | return PTR_ERR(rdev); |
| 5747 | } |
| 5748 | |
| 5749 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5750 | self_managed = wiphy->regulatory_flags & |
| 5751 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5752 | regdom = get_wiphy_regdom(wiphy); |
| 5753 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5754 | /* a self-managed-reg device must have a private regdom */ |
| 5755 | if (WARN_ON(!regdom && self_managed)) { |
| 5756 | nlmsg_free(msg); |
| 5757 | return -EINVAL; |
| 5758 | } |
| 5759 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5760 | if (regdom && |
| 5761 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5762 | goto nla_put_failure; |
| 5763 | } |
| 5764 | |
| 5765 | if (!wiphy && reg_last_request_cell_base() && |
| 5766 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5767 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5768 | goto nla_put_failure; |
| 5769 | |
| 5770 | rcu_read_lock(); |
| 5771 | |
| 5772 | if (!regdom) |
| 5773 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5774 | |
| 5775 | if (nl80211_put_regdom(regdom, msg)) |
| 5776 | goto nla_put_failure_rcu; |
| 5777 | |
| 5778 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5779 | |
| 5780 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5781 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5782 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5783 | nla_put_failure_rcu: |
| 5784 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5785 | nla_put_failure: |
| 5786 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5787 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5788 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5789 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5790 | } |
| 5791 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5792 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5793 | u32 seq, int flags, struct wiphy *wiphy, |
| 5794 | const struct ieee80211_regdomain *regdom) |
| 5795 | { |
| 5796 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5797 | NL80211_CMD_GET_REG); |
| 5798 | |
| 5799 | if (!hdr) |
| 5800 | return -1; |
| 5801 | |
| 5802 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5803 | |
| 5804 | if (nl80211_put_regdom(regdom, msg)) |
| 5805 | goto nla_put_failure; |
| 5806 | |
| 5807 | if (!wiphy && reg_last_request_cell_base() && |
| 5808 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5809 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5810 | goto nla_put_failure; |
| 5811 | |
| 5812 | if (wiphy && |
| 5813 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5814 | goto nla_put_failure; |
| 5815 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5816 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5817 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5818 | goto nla_put_failure; |
| 5819 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5820 | genlmsg_end(msg, hdr); |
| 5821 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5822 | |
| 5823 | nla_put_failure: |
| 5824 | genlmsg_cancel(msg, hdr); |
| 5825 | return -EMSGSIZE; |
| 5826 | } |
| 5827 | |
| 5828 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5829 | struct netlink_callback *cb) |
| 5830 | { |
| 5831 | const struct ieee80211_regdomain *regdom = NULL; |
| 5832 | struct cfg80211_registered_device *rdev; |
| 5833 | int err, reg_idx, start = cb->args[2]; |
| 5834 | |
| 5835 | rtnl_lock(); |
| 5836 | |
| 5837 | if (cfg80211_regdomain && start == 0) { |
| 5838 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5839 | NLM_F_MULTI, NULL, |
| 5840 | rtnl_dereference(cfg80211_regdomain)); |
| 5841 | if (err < 0) |
| 5842 | goto out_err; |
| 5843 | } |
| 5844 | |
| 5845 | /* the global regdom is idx 0 */ |
| 5846 | reg_idx = 1; |
| 5847 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5848 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5849 | if (!regdom) |
| 5850 | continue; |
| 5851 | |
| 5852 | if (++reg_idx <= start) |
| 5853 | continue; |
| 5854 | |
| 5855 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5856 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5857 | if (err < 0) { |
| 5858 | reg_idx--; |
| 5859 | break; |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | cb->args[2] = reg_idx; |
| 5864 | err = skb->len; |
| 5865 | out_err: |
| 5866 | rtnl_unlock(); |
| 5867 | return err; |
| 5868 | } |
| 5869 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5870 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 5871 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 5872 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5873 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5874 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5875 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5876 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5877 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5878 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 5879 | }; |
| 5880 | |
| 5881 | static int parse_reg_rule(struct nlattr *tb[], |
| 5882 | struct ieee80211_reg_rule *reg_rule) |
| 5883 | { |
| 5884 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 5885 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 5886 | |
| 5887 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 5888 | return -EINVAL; |
| 5889 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 5890 | return -EINVAL; |
| 5891 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 5892 | return -EINVAL; |
| 5893 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 5894 | return -EINVAL; |
| 5895 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 5896 | return -EINVAL; |
| 5897 | |
| 5898 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 5899 | |
| 5900 | freq_range->start_freq_khz = |
| 5901 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 5902 | freq_range->end_freq_khz = |
| 5903 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 5904 | freq_range->max_bandwidth_khz = |
| 5905 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 5906 | |
| 5907 | power_rule->max_eirp = |
| 5908 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 5909 | |
| 5910 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 5911 | power_rule->max_antenna_gain = |
| 5912 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 5913 | |
| 5914 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 5915 | reg_rule->dfs_cac_ms = |
| 5916 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 5917 | |
| 5918 | return 0; |
| 5919 | } |
| 5920 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5921 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5922 | { |
| 5923 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5924 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5925 | char *alpha2; |
| 5926 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5927 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5928 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5929 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5930 | |
| 5931 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5932 | return -EINVAL; |
| 5933 | |
| 5934 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5935 | return -EINVAL; |
| 5936 | |
| 5937 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5938 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5939 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5940 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5941 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5942 | 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] | 5943 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5944 | num_rules++; |
| 5945 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5946 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5949 | if (!reg_is_valid_request(alpha2)) |
| 5950 | return -EINVAL; |
| 5951 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5952 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5953 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5954 | |
| 5955 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5956 | if (!rd) |
| 5957 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5958 | |
| 5959 | rd->n_reg_rules = num_rules; |
| 5960 | rd->alpha2[0] = alpha2[0]; |
| 5961 | rd->alpha2[1] = alpha2[1]; |
| 5962 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5963 | /* |
| 5964 | * Disable DFS master mode if the DFS region was |
| 5965 | * not supported or known on this kernel. |
| 5966 | */ |
| 5967 | if (reg_supported_dfs_region(dfs_region)) |
| 5968 | rd->dfs_region = dfs_region; |
| 5969 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5970 | 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] | 5971 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5972 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5973 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5974 | reg_rule_policy); |
| 5975 | if (r) |
| 5976 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5977 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5978 | if (r) |
| 5979 | goto bad_reg; |
| 5980 | |
| 5981 | rule_idx++; |
| 5982 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5983 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5984 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5985 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5986 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5987 | } |
| 5988 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 5989 | /* set_regdom takes ownership of rd */ |
| 5990 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5991 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5992 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5993 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5994 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5995 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5996 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5997 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5998 | { |
| 5999 | struct nlattr *attr1, *attr2; |
| 6000 | int n_channels = 0, tmp1, tmp2; |
| 6001 | |
| 6002 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6003 | n_channels++; |
| 6004 | /* |
| 6005 | * Some hardware has a limited channel list for |
| 6006 | * scanning, and it is pretty much nonsensical |
| 6007 | * to scan for a channel twice, so disallow that |
| 6008 | * and don't require drivers to check that the |
| 6009 | * channel list they get isn't longer than what |
| 6010 | * they can scan, as long as they can scan all |
| 6011 | * the channels they registered at once. |
| 6012 | */ |
| 6013 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6014 | if (attr1 != attr2 && |
| 6015 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6016 | return 0; |
| 6017 | } |
| 6018 | |
| 6019 | return n_channels; |
| 6020 | } |
| 6021 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6022 | 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] | 6023 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6024 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6028 | struct cfg80211_bss_selection *bss_select) |
| 6029 | { |
| 6030 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6031 | struct nlattr *nest; |
| 6032 | int err; |
| 6033 | bool found = false; |
| 6034 | int i; |
| 6035 | |
| 6036 | /* only process one nested attribute */ |
| 6037 | nest = nla_data(nla); |
| 6038 | if (!nla_ok(nest, nla_len(nest))) |
| 6039 | return -EINVAL; |
| 6040 | |
| 6041 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), |
| 6042 | nla_len(nest), nl80211_bss_select_policy); |
| 6043 | if (err) |
| 6044 | return err; |
| 6045 | |
| 6046 | /* only one attribute may be given */ |
| 6047 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6048 | if (attr[i]) { |
| 6049 | if (found) |
| 6050 | return -EINVAL; |
| 6051 | found = true; |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6056 | |
| 6057 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6058 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6059 | |
| 6060 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6061 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6062 | bss_select->param.band_pref = |
| 6063 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6064 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6065 | return -EINVAL; |
| 6066 | } |
| 6067 | |
| 6068 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6069 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6070 | |
| 6071 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6072 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6073 | bss_select->param.adjust.band = adj_param->band; |
| 6074 | bss_select->param.adjust.delta = adj_param->delta; |
| 6075 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6076 | return -EINVAL; |
| 6077 | } |
| 6078 | |
| 6079 | /* user-space did not provide behaviour attribute */ |
| 6080 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6081 | return -EINVAL; |
| 6082 | |
| 6083 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6084 | return -EINVAL; |
| 6085 | |
| 6086 | return 0; |
| 6087 | } |
| 6088 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6089 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6090 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6091 | { |
| 6092 | int i; |
| 6093 | |
| 6094 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6095 | eth_zero_addr(mac_addr); |
| 6096 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6097 | mac_addr[0] = 0x2; |
| 6098 | mac_addr_mask[0] = 0x3; |
| 6099 | |
| 6100 | return 0; |
| 6101 | } |
| 6102 | |
| 6103 | /* need both or none */ |
| 6104 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6105 | return -EINVAL; |
| 6106 | |
| 6107 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6108 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6109 | |
| 6110 | /* don't allow or configure an mcast address */ |
| 6111 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6112 | is_multicast_ether_addr(mac_addr)) |
| 6113 | return -EINVAL; |
| 6114 | |
| 6115 | /* |
| 6116 | * allow users to pass a MAC address that has bits set outside |
| 6117 | * of the mask, but don't bother drivers with having to deal |
| 6118 | * with such bits |
| 6119 | */ |
| 6120 | for (i = 0; i < ETH_ALEN; i++) |
| 6121 | mac_addr[i] &= mac_addr_mask[i]; |
| 6122 | |
| 6123 | return 0; |
| 6124 | } |
| 6125 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6126 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6127 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6129 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6130 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6131 | struct nlattr *attr; |
| 6132 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6133 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6134 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6135 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6136 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6137 | return -EINVAL; |
| 6138 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6139 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6141 | if (!rdev->ops->scan) |
| 6142 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6143 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6144 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6145 | err = -EBUSY; |
| 6146 | goto unlock; |
| 6147 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6148 | |
| 6149 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6150 | n_channels = validate_scan_freqs( |
| 6151 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6152 | if (!n_channels) { |
| 6153 | err = -EINVAL; |
| 6154 | goto unlock; |
| 6155 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6156 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6157 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6161 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6162 | n_ssids++; |
| 6163 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6164 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6165 | err = -EINVAL; |
| 6166 | goto unlock; |
| 6167 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6168 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6169 | if (info->attrs[NL80211_ATTR_IE]) |
| 6170 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6171 | else |
| 6172 | ie_len = 0; |
| 6173 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6174 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6175 | err = -EINVAL; |
| 6176 | goto unlock; |
| 6177 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6178 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6179 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6180 | + sizeof(*request->ssids) * n_ssids |
| 6181 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6182 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6183 | if (!request) { |
| 6184 | err = -ENOMEM; |
| 6185 | goto unlock; |
| 6186 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6187 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6188 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6189 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6190 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6191 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6192 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6193 | request->ie = (void *)(request->ssids + n_ssids); |
| 6194 | else |
| 6195 | request->ie = (void *)(request->channels + n_channels); |
| 6196 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6197 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6198 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6199 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6200 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6201 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6202 | struct ieee80211_channel *chan; |
| 6203 | |
| 6204 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6205 | |
| 6206 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6207 | err = -EINVAL; |
| 6208 | goto out_free; |
| 6209 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6210 | |
| 6211 | /* ignore disabled channels */ |
| 6212 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6213 | continue; |
| 6214 | |
| 6215 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6216 | i++; |
| 6217 | } |
| 6218 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6219 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6220 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6221 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6222 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6223 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6224 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6225 | if (!wiphy->bands[band]) |
| 6226 | continue; |
| 6227 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6228 | struct ieee80211_channel *chan; |
| 6229 | |
| 6230 | chan = &wiphy->bands[band]->channels[j]; |
| 6231 | |
| 6232 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6233 | continue; |
| 6234 | |
| 6235 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6236 | i++; |
| 6237 | } |
| 6238 | } |
| 6239 | } |
| 6240 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6241 | if (!i) { |
| 6242 | err = -EINVAL; |
| 6243 | goto out_free; |
| 6244 | } |
| 6245 | |
| 6246 | request->n_channels = i; |
| 6247 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6248 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6249 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6250 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6251 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6252 | err = -EINVAL; |
| 6253 | goto out_free; |
| 6254 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6255 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6256 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6257 | i++; |
| 6258 | } |
| 6259 | } |
| 6260 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6261 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6262 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6263 | memcpy((void *)request->ie, |
| 6264 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6265 | request->ie_len); |
| 6266 | } |
| 6267 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6268 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6269 | if (wiphy->bands[i]) |
| 6270 | request->rates[i] = |
| 6271 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6272 | |
| 6273 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6274 | nla_for_each_nested(attr, |
| 6275 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6276 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6277 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6278 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6279 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6280 | err = -EINVAL; |
| 6281 | goto out_free; |
| 6282 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6283 | |
| 6284 | if (!wiphy->bands[band]) |
| 6285 | continue; |
| 6286 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6287 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6288 | nla_data(attr), |
| 6289 | nla_len(attr), |
| 6290 | &request->rates[band]); |
| 6291 | if (err) |
| 6292 | goto out_free; |
| 6293 | } |
| 6294 | } |
| 6295 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6296 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6297 | if (!wiphy_ext_feature_isset(wiphy, |
| 6298 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6299 | err = -EOPNOTSUPP; |
| 6300 | goto out_free; |
| 6301 | } |
| 6302 | |
| 6303 | request->duration = |
| 6304 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6305 | request->duration_mandatory = |
| 6306 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6307 | } |
| 6308 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6309 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6310 | request->flags = nla_get_u32( |
| 6311 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6312 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6313 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6314 | err = -EOPNOTSUPP; |
| 6315 | goto out_free; |
| 6316 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6317 | |
| 6318 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6319 | if (!(wiphy->features & |
| 6320 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6321 | err = -EOPNOTSUPP; |
| 6322 | goto out_free; |
| 6323 | } |
| 6324 | |
| 6325 | if (wdev->current_bss) { |
| 6326 | err = -EOPNOTSUPP; |
| 6327 | goto out_free; |
| 6328 | } |
| 6329 | |
| 6330 | err = nl80211_parse_random_mac(info->attrs, |
| 6331 | request->mac_addr, |
| 6332 | request->mac_addr_mask); |
| 6333 | if (err) |
| 6334 | goto out_free; |
| 6335 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6336 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6337 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6338 | request->no_cck = |
| 6339 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6340 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6341 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6342 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6343 | ETH_ALEN); |
| 6344 | else |
| 6345 | eth_broadcast_addr(request->bssid); |
| 6346 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6347 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6348 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6349 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6350 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6351 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6352 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6353 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6354 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6355 | nl80211_send_scan_start(rdev, wdev); |
| 6356 | if (wdev->netdev) |
| 6357 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6358 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6359 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6360 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6361 | kfree(request); |
| 6362 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6363 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6364 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6365 | return err; |
| 6366 | } |
| 6367 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6368 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6369 | { |
| 6370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6371 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6372 | |
| 6373 | if (!rdev->ops->abort_scan) |
| 6374 | return -EOPNOTSUPP; |
| 6375 | |
| 6376 | if (rdev->scan_msg) |
| 6377 | return 0; |
| 6378 | |
| 6379 | if (!rdev->scan_req) |
| 6380 | return -ENOENT; |
| 6381 | |
| 6382 | rdev_abort_scan(rdev, wdev); |
| 6383 | return 0; |
| 6384 | } |
| 6385 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6386 | static int |
| 6387 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6388 | struct cfg80211_sched_scan_request *request, |
| 6389 | struct nlattr **attrs) |
| 6390 | { |
| 6391 | int tmp, err, i = 0; |
| 6392 | struct nlattr *attr; |
| 6393 | |
| 6394 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6395 | u32 interval; |
| 6396 | |
| 6397 | /* |
| 6398 | * If scan plans are not specified, |
| 6399 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6400 | * case one scan plan will be set with the specified scan |
| 6401 | * interval and infinite number of iterations. |
| 6402 | */ |
| 6403 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6404 | return -EINVAL; |
| 6405 | |
| 6406 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6407 | if (!interval) |
| 6408 | return -EINVAL; |
| 6409 | |
| 6410 | request->scan_plans[0].interval = |
| 6411 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6412 | if (!request->scan_plans[0].interval) |
| 6413 | return -EINVAL; |
| 6414 | |
| 6415 | if (request->scan_plans[0].interval > |
| 6416 | wiphy->max_sched_scan_plan_interval) |
| 6417 | request->scan_plans[0].interval = |
| 6418 | wiphy->max_sched_scan_plan_interval; |
| 6419 | |
| 6420 | return 0; |
| 6421 | } |
| 6422 | |
| 6423 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6424 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6425 | |
| 6426 | if (WARN_ON(i >= n_plans)) |
| 6427 | return -EINVAL; |
| 6428 | |
| 6429 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6430 | nla_data(attr), nla_len(attr), |
| 6431 | nl80211_plan_policy); |
| 6432 | if (err) |
| 6433 | return err; |
| 6434 | |
| 6435 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6436 | return -EINVAL; |
| 6437 | |
| 6438 | request->scan_plans[i].interval = |
| 6439 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6440 | if (!request->scan_plans[i].interval || |
| 6441 | request->scan_plans[i].interval > |
| 6442 | wiphy->max_sched_scan_plan_interval) |
| 6443 | return -EINVAL; |
| 6444 | |
| 6445 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6446 | request->scan_plans[i].iterations = |
| 6447 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6448 | if (!request->scan_plans[i].iterations || |
| 6449 | (request->scan_plans[i].iterations > |
| 6450 | wiphy->max_sched_scan_plan_iterations)) |
| 6451 | return -EINVAL; |
| 6452 | } else if (i < n_plans - 1) { |
| 6453 | /* |
| 6454 | * All scan plans but the last one must specify |
| 6455 | * a finite number of iterations |
| 6456 | */ |
| 6457 | return -EINVAL; |
| 6458 | } |
| 6459 | |
| 6460 | i++; |
| 6461 | } |
| 6462 | |
| 6463 | /* |
| 6464 | * The last scan plan must not specify the number of |
| 6465 | * iterations, it is supposed to run infinitely |
| 6466 | */ |
| 6467 | if (request->scan_plans[n_plans - 1].iterations) |
| 6468 | return -EINVAL; |
| 6469 | |
| 6470 | return 0; |
| 6471 | } |
| 6472 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6473 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6474 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6475 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6476 | { |
| 6477 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6478 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6479 | 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] | 6480 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6481 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6482 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6483 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6484 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6485 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6486 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6487 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6488 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6489 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6490 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6491 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6492 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6493 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6494 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6495 | } |
| 6496 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6497 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6498 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6499 | tmp) |
| 6500 | n_ssids++; |
| 6501 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6502 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6503 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6504 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6505 | /* |
| 6506 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6507 | * the old implementation, matchsets containing only the RSSI attribute |
| 6508 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6509 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6510 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6511 | * older userspace that treated a matchset with only the RSSI as the |
| 6512 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6513 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6514 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6515 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6516 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6517 | tmp) { |
| 6518 | struct nlattr *rssi; |
| 6519 | |
| 6520 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6521 | nla_data(attr), nla_len(attr), |
| 6522 | nl80211_match_policy); |
| 6523 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6524 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6525 | /* add other standalone attributes here */ |
| 6526 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6527 | n_match_sets++; |
| 6528 | continue; |
| 6529 | } |
| 6530 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6531 | if (rssi) |
| 6532 | default_match_rssi = nla_get_s32(rssi); |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /* However, if there's no other matchset, add the RSSI one */ |
| 6537 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6538 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6539 | |
| 6540 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6541 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6542 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6543 | if (attrs[NL80211_ATTR_IE]) |
| 6544 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6545 | else |
| 6546 | ie_len = 0; |
| 6547 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6548 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6549 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6550 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6551 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6552 | /* |
| 6553 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6554 | * each scan plan already specifies its own interval |
| 6555 | */ |
| 6556 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6557 | return ERR_PTR(-EINVAL); |
| 6558 | |
| 6559 | nla_for_each_nested(attr, |
| 6560 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6561 | n_plans++; |
| 6562 | } else { |
| 6563 | /* |
| 6564 | * The scan interval attribute is kept for backward |
| 6565 | * compatibility. If no scan plans are specified and sched scan |
| 6566 | * interval is specified, one scan plan will be set with this |
| 6567 | * scan interval and infinite number of iterations. |
| 6568 | */ |
| 6569 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6570 | return ERR_PTR(-EINVAL); |
| 6571 | |
| 6572 | n_plans = 1; |
| 6573 | } |
| 6574 | |
| 6575 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6576 | return ERR_PTR(-EINVAL); |
| 6577 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6578 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6579 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6580 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6581 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6582 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6583 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6584 | if (!request) |
| 6585 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6586 | |
| 6587 | if (n_ssids) |
| 6588 | request->ssids = (void *)&request->channels[n_channels]; |
| 6589 | request->n_ssids = n_ssids; |
| 6590 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6591 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6592 | request->ie = (void *)(request->ssids + n_ssids); |
| 6593 | else |
| 6594 | request->ie = (void *)(request->channels + n_channels); |
| 6595 | } |
| 6596 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6597 | if (n_match_sets) { |
| 6598 | if (request->ie) |
| 6599 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6600 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6601 | request->match_sets = |
| 6602 | (void *)(request->ssids + n_ssids); |
| 6603 | else |
| 6604 | request->match_sets = |
| 6605 | (void *)(request->channels + n_channels); |
| 6606 | } |
| 6607 | request->n_match_sets = n_match_sets; |
| 6608 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6609 | if (n_match_sets) |
| 6610 | request->scan_plans = (void *)(request->match_sets + |
| 6611 | n_match_sets); |
| 6612 | else if (request->ie) |
| 6613 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6614 | else if (n_ssids) |
| 6615 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6616 | else |
| 6617 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6618 | |
| 6619 | request->n_scan_plans = n_plans; |
| 6620 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6621 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6622 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6623 | /* user specified, bail out if channel not found */ |
| 6624 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6625 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6626 | tmp) { |
| 6627 | struct ieee80211_channel *chan; |
| 6628 | |
| 6629 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6630 | |
| 6631 | if (!chan) { |
| 6632 | err = -EINVAL; |
| 6633 | goto out_free; |
| 6634 | } |
| 6635 | |
| 6636 | /* ignore disabled channels */ |
| 6637 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6638 | continue; |
| 6639 | |
| 6640 | request->channels[i] = chan; |
| 6641 | i++; |
| 6642 | } |
| 6643 | } else { |
| 6644 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6645 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6646 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6647 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6648 | if (!wiphy->bands[band]) |
| 6649 | continue; |
| 6650 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6651 | struct ieee80211_channel *chan; |
| 6652 | |
| 6653 | chan = &wiphy->bands[band]->channels[j]; |
| 6654 | |
| 6655 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6656 | continue; |
| 6657 | |
| 6658 | request->channels[i] = chan; |
| 6659 | i++; |
| 6660 | } |
| 6661 | } |
| 6662 | } |
| 6663 | |
| 6664 | if (!i) { |
| 6665 | err = -EINVAL; |
| 6666 | goto out_free; |
| 6667 | } |
| 6668 | |
| 6669 | request->n_channels = i; |
| 6670 | |
| 6671 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6672 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6673 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6674 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6675 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6676 | err = -EINVAL; |
| 6677 | goto out_free; |
| 6678 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6679 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6680 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6681 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6682 | i++; |
| 6683 | } |
| 6684 | } |
| 6685 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6686 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6687 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6688 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6689 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6690 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6691 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6692 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6693 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6694 | nla_data(attr), nla_len(attr), |
| 6695 | nl80211_match_policy); |
| 6696 | if (err) |
| 6697 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6698 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6699 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6700 | if (WARN_ON(i >= n_match_sets)) { |
| 6701 | /* this indicates a programming error, |
| 6702 | * the loop above should have verified |
| 6703 | * things properly |
| 6704 | */ |
| 6705 | err = -EINVAL; |
| 6706 | goto out_free; |
| 6707 | } |
| 6708 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6709 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6710 | err = -EINVAL; |
| 6711 | goto out_free; |
| 6712 | } |
| 6713 | memcpy(request->match_sets[i].ssid.ssid, |
| 6714 | nla_data(ssid), nla_len(ssid)); |
| 6715 | request->match_sets[i].ssid.ssid_len = |
| 6716 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 6717 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6718 | request->match_sets[i].rssi_thold = |
| 6719 | default_match_rssi; |
| 6720 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6721 | if (rssi) |
| 6722 | request->match_sets[i].rssi_thold = |
| 6723 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6724 | } |
| 6725 | i++; |
| 6726 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6727 | |
| 6728 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6729 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6730 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6731 | |
| 6732 | request->min_rssi_thold = INT_MAX; |
| 6733 | for (i = 0; i < n_match_sets; i++) |
| 6734 | request->min_rssi_thold = |
| 6735 | min(request->match_sets[i].rssi_thold, |
| 6736 | request->min_rssi_thold); |
| 6737 | } else { |
| 6738 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6739 | } |
| 6740 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6741 | if (ie_len) { |
| 6742 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6743 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6744 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6745 | request->ie_len); |
| 6746 | } |
| 6747 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6748 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6749 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6750 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6751 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6752 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6753 | err = -EOPNOTSUPP; |
| 6754 | goto out_free; |
| 6755 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6756 | |
| 6757 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6758 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6759 | |
| 6760 | if (!wdev) /* must be net-detect */ |
| 6761 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6762 | |
| 6763 | if (!(wiphy->features & flg)) { |
| 6764 | err = -EOPNOTSUPP; |
| 6765 | goto out_free; |
| 6766 | } |
| 6767 | |
| 6768 | if (wdev && wdev->current_bss) { |
| 6769 | err = -EOPNOTSUPP; |
| 6770 | goto out_free; |
| 6771 | } |
| 6772 | |
| 6773 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6774 | request->mac_addr_mask); |
| 6775 | if (err) |
| 6776 | goto out_free; |
| 6777 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6778 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6779 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6780 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6781 | request->delay = |
| 6782 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6783 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6784 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 6785 | if (err) |
| 6786 | goto out_free; |
| 6787 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6788 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6789 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6790 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6791 | |
| 6792 | out_free: |
| 6793 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6794 | return ERR_PTR(err); |
| 6795 | } |
| 6796 | |
| 6797 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6798 | struct genl_info *info) |
| 6799 | { |
| 6800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6801 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6803 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6804 | int err; |
| 6805 | |
| 6806 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6807 | !rdev->ops->sched_scan_start) |
| 6808 | return -EOPNOTSUPP; |
| 6809 | |
| 6810 | if (rdev->sched_scan_req) |
| 6811 | return -EINPROGRESS; |
| 6812 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6813 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6814 | info->attrs); |
| 6815 | |
| 6816 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6817 | if (err) |
| 6818 | goto out_err; |
| 6819 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6820 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6821 | if (err) |
| 6822 | goto out_free; |
| 6823 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6824 | sched_scan_req->dev = dev; |
| 6825 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6826 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6827 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6828 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6829 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6830 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6831 | |
| 6832 | nl80211_send_sched_scan(rdev, dev, |
| 6833 | NL80211_CMD_START_SCHED_SCAN); |
| 6834 | return 0; |
| 6835 | |
| 6836 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6837 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6838 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6839 | return err; |
| 6840 | } |
| 6841 | |
| 6842 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6843 | struct genl_info *info) |
| 6844 | { |
| 6845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6846 | |
| 6847 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6848 | !rdev->ops->sched_scan_stop) |
| 6849 | return -EOPNOTSUPP; |
| 6850 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6851 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6852 | } |
| 6853 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6854 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6855 | struct genl_info *info) |
| 6856 | { |
| 6857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6858 | struct net_device *dev = info->user_ptr[1]; |
| 6859 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6860 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6861 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6862 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6863 | int err; |
| 6864 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6865 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6866 | if (dfs_region == NL80211_DFS_UNSET) |
| 6867 | return -EINVAL; |
| 6868 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6869 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6870 | if (err) |
| 6871 | return err; |
| 6872 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6873 | if (netif_carrier_ok(dev)) |
| 6874 | return -EBUSY; |
| 6875 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6876 | if (wdev->cac_started) |
| 6877 | return -EBUSY; |
| 6878 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6879 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6880 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6881 | if (err < 0) |
| 6882 | return err; |
| 6883 | |
| 6884 | if (err == 0) |
| 6885 | return -EINVAL; |
| 6886 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6887 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6888 | return -EINVAL; |
| 6889 | |
| 6890 | if (!rdev->ops->start_radar_detection) |
| 6891 | return -EOPNOTSUPP; |
| 6892 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6893 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6894 | if (WARN_ON(!cac_time_ms)) |
| 6895 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6896 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 6897 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6898 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6899 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6900 | wdev->cac_started = true; |
| 6901 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6902 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6903 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6904 | return err; |
| 6905 | } |
| 6906 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6907 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6908 | { |
| 6909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6910 | struct net_device *dev = info->user_ptr[1]; |
| 6911 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6912 | struct cfg80211_csa_settings params; |
| 6913 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6914 | * function is called under RTNL lock, so this should not be a problem. |
| 6915 | */ |
| 6916 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6917 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6918 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6919 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6920 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6921 | |
| 6922 | if (!rdev->ops->channel_switch || |
| 6923 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6924 | return -EOPNOTSUPP; |
| 6925 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6926 | switch (dev->ieee80211_ptr->iftype) { |
| 6927 | case NL80211_IFTYPE_AP: |
| 6928 | case NL80211_IFTYPE_P2P_GO: |
| 6929 | need_new_beacon = true; |
| 6930 | |
| 6931 | /* useless if AP is not running */ |
| 6932 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6933 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6934 | break; |
| 6935 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6936 | if (!wdev->ssid_len) |
| 6937 | return -ENOTCONN; |
| 6938 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6939 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6940 | if (!wdev->mesh_id_len) |
| 6941 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6942 | break; |
| 6943 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6944 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6945 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6946 | |
| 6947 | memset(¶ms, 0, sizeof(params)); |
| 6948 | |
| 6949 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6950 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6951 | return -EINVAL; |
| 6952 | |
| 6953 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6954 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6955 | return -EINVAL; |
| 6956 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6957 | /* Even though the attribute is u32, the specification says |
| 6958 | * u8, so let's make sure we don't overflow. |
| 6959 | */ |
| 6960 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6961 | if (cs_count > 255) |
| 6962 | return -EINVAL; |
| 6963 | |
| 6964 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6965 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6966 | if (!need_new_beacon) |
| 6967 | goto skip_beacons; |
| 6968 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6969 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6970 | if (err) |
| 6971 | return err; |
| 6972 | |
| 6973 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6974 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6975 | nl80211_policy); |
| 6976 | if (err) |
| 6977 | return err; |
| 6978 | |
| 6979 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6980 | if (err) |
| 6981 | return err; |
| 6982 | |
| 6983 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6984 | return -EINVAL; |
| 6985 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6986 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6987 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6988 | return -EINVAL; |
| 6989 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6990 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6991 | if (rdev->wiphy.max_num_csa_counters && |
| 6992 | (params.n_counter_offsets_beacon > |
| 6993 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6994 | return -EINVAL; |
| 6995 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6996 | params.counter_offsets_beacon = |
| 6997 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6998 | |
| 6999 | /* sanity checks - counters should fit and be the same */ |
| 7000 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7001 | u16 offset = params.counter_offsets_beacon[i]; |
| 7002 | |
| 7003 | if (offset >= params.beacon_csa.tail_len) |
| 7004 | return -EINVAL; |
| 7005 | |
| 7006 | if (params.beacon_csa.tail[offset] != params.count) |
| 7007 | return -EINVAL; |
| 7008 | } |
| 7009 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7010 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7011 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7012 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7013 | return -EINVAL; |
| 7014 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7015 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7016 | if (rdev->wiphy.max_num_csa_counters && |
| 7017 | (params.n_counter_offsets_beacon > |
| 7018 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7019 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7020 | |
| 7021 | params.counter_offsets_presp = |
| 7022 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7023 | |
| 7024 | /* sanity checks - counters should fit and be the same */ |
| 7025 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7026 | u16 offset = params.counter_offsets_presp[i]; |
| 7027 | |
| 7028 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7029 | return -EINVAL; |
| 7030 | |
| 7031 | if (params.beacon_csa.probe_resp[offset] != |
| 7032 | params.count) |
| 7033 | return -EINVAL; |
| 7034 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7035 | } |
| 7036 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7037 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7038 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7039 | if (err) |
| 7040 | return err; |
| 7041 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7042 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7043 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7044 | return -EINVAL; |
| 7045 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7046 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7047 | ¶ms.chandef, |
| 7048 | wdev->iftype); |
| 7049 | if (err < 0) |
| 7050 | return err; |
| 7051 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 7052 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7053 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7054 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7055 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7056 | params.block_tx = true; |
| 7057 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7058 | wdev_lock(wdev); |
| 7059 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7060 | wdev_unlock(wdev); |
| 7061 | |
| 7062 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7063 | } |
| 7064 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7065 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7066 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7067 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7068 | struct wireless_dev *wdev, |
| 7069 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7070 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7071 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7072 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7073 | void *hdr; |
| 7074 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7075 | |
| 7076 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7077 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7078 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7079 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7080 | if (!hdr) |
| 7081 | return -1; |
| 7082 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7083 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7084 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7085 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7086 | goto nla_put_failure; |
| 7087 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7088 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7089 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7090 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7091 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7092 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7093 | |
| 7094 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7095 | if (!bss) |
| 7096 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7097 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7098 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7099 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7100 | |
| 7101 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7102 | /* indicate whether we have probe response data or not */ |
| 7103 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7104 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7105 | goto fail_unlock_rcu; |
| 7106 | |
| 7107 | /* this pointer prefers to be pointed to probe response data |
| 7108 | * but is always valid |
| 7109 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7110 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7111 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7112 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7113 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7114 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7115 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7116 | ies->len, ies->data)) |
| 7117 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7118 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7119 | |
| 7120 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7121 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7122 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7123 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7124 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7125 | goto fail_unlock_rcu; |
| 7126 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7127 | ies->len, ies->data)) |
| 7128 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7129 | } |
| 7130 | rcu_read_unlock(); |
| 7131 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7132 | if (res->beacon_interval && |
| 7133 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7134 | goto nla_put_failure; |
| 7135 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7136 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7137 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7138 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7139 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7140 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7141 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7142 | if (intbss->parent_tsf && |
| 7143 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7144 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7145 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7146 | intbss->parent_bssid))) |
| 7147 | goto nla_put_failure; |
| 7148 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7149 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7150 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7151 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7152 | goto nla_put_failure; |
| 7153 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7154 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7155 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7156 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7157 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7158 | break; |
| 7159 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7160 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7161 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7162 | break; |
| 7163 | default: |
| 7164 | break; |
| 7165 | } |
| 7166 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7167 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7168 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7169 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7170 | if (intbss == wdev->current_bss && |
| 7171 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7172 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7173 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7174 | break; |
| 7175 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7176 | if (intbss == wdev->current_bss && |
| 7177 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7178 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7179 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7180 | break; |
| 7181 | default: |
| 7182 | break; |
| 7183 | } |
| 7184 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7185 | nla_nest_end(msg, bss); |
| 7186 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7187 | genlmsg_end(msg, hdr); |
| 7188 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7189 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7190 | fail_unlock_rcu: |
| 7191 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7192 | nla_put_failure: |
| 7193 | genlmsg_cancel(msg, hdr); |
| 7194 | return -EMSGSIZE; |
| 7195 | } |
| 7196 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7197 | 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] | 7198 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7199 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7200 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7201 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7202 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7203 | int err; |
| 7204 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7205 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7206 | if (err) |
| 7207 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7208 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7209 | wdev_lock(wdev); |
| 7210 | spin_lock_bh(&rdev->bss_lock); |
| 7211 | cfg80211_bss_expire(rdev); |
| 7212 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7213 | cb->seq = rdev->bss_generation; |
| 7214 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7215 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7216 | if (++idx <= start) |
| 7217 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7218 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7219 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7220 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7221 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7222 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7226 | spin_unlock_bh(&rdev->bss_lock); |
| 7227 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7228 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7229 | cb->args[2] = idx; |
| 7230 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7231 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7232 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7233 | } |
| 7234 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7235 | 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] | 7236 | int flags, struct net_device *dev, |
| 7237 | bool allow_radio_stats, |
| 7238 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7239 | { |
| 7240 | void *hdr; |
| 7241 | struct nlattr *infoattr; |
| 7242 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7243 | /* skip radio stats if userspace didn't request them */ |
| 7244 | if (!survey->channel && !allow_radio_stats) |
| 7245 | return 0; |
| 7246 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7247 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7248 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7249 | if (!hdr) |
| 7250 | return -ENOMEM; |
| 7251 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7252 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7253 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7254 | |
| 7255 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7256 | if (!infoattr) |
| 7257 | goto nla_put_failure; |
| 7258 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7259 | if (survey->channel && |
| 7260 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7261 | survey->channel->center_freq)) |
| 7262 | goto nla_put_failure; |
| 7263 | |
| 7264 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7265 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7266 | goto nla_put_failure; |
| 7267 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7268 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7269 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7270 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7271 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7272 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7273 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7274 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7275 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7276 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7277 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7278 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7279 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7280 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7281 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7282 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7283 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7284 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7285 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7286 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7287 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7288 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7289 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7290 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7291 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7292 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7293 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7294 | |
| 7295 | nla_nest_end(msg, infoattr); |
| 7296 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7297 | genlmsg_end(msg, hdr); |
| 7298 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7299 | |
| 7300 | nla_put_failure: |
| 7301 | genlmsg_cancel(msg, hdr); |
| 7302 | return -EMSGSIZE; |
| 7303 | } |
| 7304 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7305 | 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] | 7306 | { |
| 7307 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7308 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7309 | struct wireless_dev *wdev; |
| 7310 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7311 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7312 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7313 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7314 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7315 | if (res) |
| 7316 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7317 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7318 | /* prepare_wdev_dump parsed the attributes */ |
| 7319 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 7320 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7321 | if (!wdev->netdev) { |
| 7322 | res = -EINVAL; |
| 7323 | goto out_err; |
| 7324 | } |
| 7325 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7326 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7327 | res = -EOPNOTSUPP; |
| 7328 | goto out_err; |
| 7329 | } |
| 7330 | |
| 7331 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7332 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7333 | if (res == -ENOENT) |
| 7334 | break; |
| 7335 | if (res) |
| 7336 | goto out_err; |
| 7337 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7338 | /* don't send disabled channels, but do send non-channel data */ |
| 7339 | if (survey.channel && |
| 7340 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7341 | survey_idx++; |
| 7342 | continue; |
| 7343 | } |
| 7344 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7345 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7346 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7347 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7348 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7349 | goto out; |
| 7350 | survey_idx++; |
| 7351 | } |
| 7352 | |
| 7353 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7354 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7355 | res = skb->len; |
| 7356 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7357 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7358 | return res; |
| 7359 | } |
| 7360 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7361 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7362 | { |
| 7363 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7364 | NL80211_WPA_VERSION_2)); |
| 7365 | } |
| 7366 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7367 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7368 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7370 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7371 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7372 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 7373 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7374 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7375 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7376 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7377 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7378 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7379 | return -EINVAL; |
| 7380 | |
| 7381 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7382 | return -EINVAL; |
| 7383 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7384 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7385 | return -EINVAL; |
| 7386 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7387 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7388 | return -EINVAL; |
| 7389 | |
| 7390 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7391 | return -EINVAL; |
| 7392 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7393 | err = nl80211_parse_key(info, &key); |
| 7394 | if (err) |
| 7395 | return err; |
| 7396 | |
| 7397 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7398 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7399 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7400 | if (!key.p.key || !key.p.key_len) |
| 7401 | return -EINVAL; |
| 7402 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7403 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7404 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7405 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7406 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 7407 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7408 | return -EINVAL; |
| 7409 | } else { |
| 7410 | key.p.key_len = 0; |
| 7411 | key.p.key = NULL; |
| 7412 | } |
| 7413 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7414 | if (key.idx >= 0) { |
| 7415 | int i; |
| 7416 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7417 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7418 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7419 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7420 | ok = true; |
| 7421 | break; |
| 7422 | } |
| 7423 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7424 | if (!ok) |
| 7425 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7426 | } |
| 7427 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7428 | if (!rdev->ops->auth) |
| 7429 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7430 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7431 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7432 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7433 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7434 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7435 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7436 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7437 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7438 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7439 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7440 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7441 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7442 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7443 | |
| 7444 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7445 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7446 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7447 | } |
| 7448 | |
| 7449 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7450 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7451 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7452 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7453 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7454 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7455 | return -EINVAL; |
| 7456 | |
| 7457 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7458 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7459 | return -EINVAL; |
| 7460 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7461 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7462 | /* need to include at least Auth Transaction and Status Code */ |
| 7463 | if (sae_data_len < 4) |
| 7464 | return -EINVAL; |
| 7465 | } |
| 7466 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7467 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7468 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7469 | /* |
| 7470 | * Since we no longer track auth state, ignore |
| 7471 | * requests to only change local state. |
| 7472 | */ |
| 7473 | if (local_state_change) |
| 7474 | return 0; |
| 7475 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7476 | wdev_lock(dev->ieee80211_ptr); |
| 7477 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7478 | ssid, ssid_len, ie, ie_len, |
| 7479 | key.p.key, key.p.key_len, key.idx, |
| 7480 | sae_data, sae_data_len); |
| 7481 | wdev_unlock(dev->ieee80211_ptr); |
| 7482 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7483 | } |
| 7484 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7485 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7486 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7487 | struct cfg80211_crypto_settings *settings, |
| 7488 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7489 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7490 | memset(settings, 0, sizeof(*settings)); |
| 7491 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7492 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7493 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7494 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7495 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7496 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7497 | proto = nla_get_u16( |
| 7498 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7499 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7500 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7501 | proto != ETH_P_PAE) |
| 7502 | return -EINVAL; |
| 7503 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7504 | settings->control_port_no_encrypt = true; |
| 7505 | } else |
| 7506 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7507 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7508 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7509 | void *data; |
| 7510 | int len, i; |
| 7511 | |
| 7512 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7513 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7514 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7515 | |
| 7516 | if (len % sizeof(u32)) |
| 7517 | return -EINVAL; |
| 7518 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7519 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7520 | return -EINVAL; |
| 7521 | |
| 7522 | memcpy(settings->ciphers_pairwise, data, len); |
| 7523 | |
| 7524 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7525 | if (!cfg80211_supported_cipher_suite( |
| 7526 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7527 | settings->ciphers_pairwise[i])) |
| 7528 | return -EINVAL; |
| 7529 | } |
| 7530 | |
| 7531 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7532 | settings->cipher_group = |
| 7533 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7534 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7535 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7536 | return -EINVAL; |
| 7537 | } |
| 7538 | |
| 7539 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7540 | settings->wpa_versions = |
| 7541 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7542 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7543 | return -EINVAL; |
| 7544 | } |
| 7545 | |
| 7546 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7547 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7548 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7549 | |
| 7550 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7551 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7552 | settings->n_akm_suites = len / sizeof(u32); |
| 7553 | |
| 7554 | if (len % sizeof(u32)) |
| 7555 | return -EINVAL; |
| 7556 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7557 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7558 | return -EINVAL; |
| 7559 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7560 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | return 0; |
| 7564 | } |
| 7565 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7566 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7567 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7569 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7570 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7571 | struct cfg80211_assoc_request req = {}; |
| 7572 | const u8 *bssid, *ssid; |
| 7573 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7574 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7575 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7576 | return -EINVAL; |
| 7577 | |
| 7578 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7579 | !info->attrs[NL80211_ATTR_SSID] || |
| 7580 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7581 | return -EINVAL; |
| 7582 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7583 | if (!rdev->ops->assoc) |
| 7584 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7585 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7586 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7587 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7588 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7589 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7590 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7591 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7592 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7593 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7594 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7595 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7596 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7597 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7598 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7599 | |
| 7600 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7601 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7602 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7603 | } |
| 7604 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7605 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7606 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7607 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7608 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7609 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7610 | else if (mfp != NL80211_MFP_NO) |
| 7611 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7612 | } |
| 7613 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7614 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7615 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7616 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7617 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7618 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7619 | |
| 7620 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7621 | memcpy(&req.ht_capa_mask, |
| 7622 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7623 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7624 | |
| 7625 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7626 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7627 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7628 | memcpy(&req.ht_capa, |
| 7629 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7630 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7631 | } |
| 7632 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7633 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7634 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7635 | |
| 7636 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7637 | memcpy(&req.vht_capa_mask, |
| 7638 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7639 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7640 | |
| 7641 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7642 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7643 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7644 | memcpy(&req.vht_capa, |
| 7645 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7646 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7647 | } |
| 7648 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7649 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 7650 | if (!((rdev->wiphy.features & |
| 7651 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 7652 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 7653 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 7654 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7655 | return -EINVAL; |
| 7656 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7657 | } |
| 7658 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7659 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7660 | if (!err) { |
| 7661 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7662 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7663 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7664 | wdev_unlock(dev->ieee80211_ptr); |
| 7665 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7666 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7667 | return err; |
| 7668 | } |
| 7669 | |
| 7670 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7671 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7673 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7674 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7675 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7676 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7677 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7678 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7679 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7680 | return -EINVAL; |
| 7681 | |
| 7682 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7683 | return -EINVAL; |
| 7684 | |
| 7685 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7686 | return -EINVAL; |
| 7687 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7688 | if (!rdev->ops->deauth) |
| 7689 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7690 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7691 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7692 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7693 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7694 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7695 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7696 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7697 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7698 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7699 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7700 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7701 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7702 | |
| 7703 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7704 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7705 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7706 | } |
| 7707 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7708 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7709 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7710 | wdev_lock(dev->ieee80211_ptr); |
| 7711 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7712 | local_state_change); |
| 7713 | wdev_unlock(dev->ieee80211_ptr); |
| 7714 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7715 | } |
| 7716 | |
| 7717 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7718 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7720 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7721 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7722 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7723 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7724 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7725 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7726 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7727 | return -EINVAL; |
| 7728 | |
| 7729 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7730 | return -EINVAL; |
| 7731 | |
| 7732 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7733 | return -EINVAL; |
| 7734 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7735 | if (!rdev->ops->disassoc) |
| 7736 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7737 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7738 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7739 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7740 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7741 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7742 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7743 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7744 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7745 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7746 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7747 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7748 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7749 | |
| 7750 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7751 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7752 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7753 | } |
| 7754 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7755 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7756 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7757 | wdev_lock(dev->ieee80211_ptr); |
| 7758 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7759 | local_state_change); |
| 7760 | wdev_unlock(dev->ieee80211_ptr); |
| 7761 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7762 | } |
| 7763 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7764 | static bool |
| 7765 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7766 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7767 | int rateval) |
| 7768 | { |
| 7769 | struct wiphy *wiphy = &rdev->wiphy; |
| 7770 | bool found = false; |
| 7771 | int band, i; |
| 7772 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7773 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7774 | struct ieee80211_supported_band *sband; |
| 7775 | |
| 7776 | sband = wiphy->bands[band]; |
| 7777 | if (!sband) |
| 7778 | continue; |
| 7779 | |
| 7780 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7781 | if (sband->bitrates[i].bitrate == rateval) { |
| 7782 | mcast_rate[band] = i + 1; |
| 7783 | found = true; |
| 7784 | break; |
| 7785 | } |
| 7786 | } |
| 7787 | } |
| 7788 | |
| 7789 | return found; |
| 7790 | } |
| 7791 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7792 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7793 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7795 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7796 | struct cfg80211_ibss_params ibss; |
| 7797 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7798 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7799 | int err; |
| 7800 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7801 | memset(&ibss, 0, sizeof(ibss)); |
| 7802 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7803 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7804 | return -EINVAL; |
| 7805 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7806 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7807 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7808 | return -EINVAL; |
| 7809 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7810 | ibss.beacon_interval = 100; |
| 7811 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 7812 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7813 | ibss.beacon_interval = |
| 7814 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 7815 | |
| 7816 | err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval); |
| 7817 | if (err) |
| 7818 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7819 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7820 | if (!rdev->ops->join_ibss) |
| 7821 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7822 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7823 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7824 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7825 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7826 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7827 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7828 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7829 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7830 | |
| 7831 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7832 | return -EINVAL; |
| 7833 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7834 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7835 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7836 | |
| 7837 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7838 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7839 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7840 | } |
| 7841 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7842 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7843 | if (err) |
| 7844 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7845 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7846 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7847 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7848 | return -EINVAL; |
| 7849 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7850 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7851 | case NL80211_CHAN_WIDTH_5: |
| 7852 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7853 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7854 | break; |
| 7855 | case NL80211_CHAN_WIDTH_20: |
| 7856 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7857 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7858 | return -EINVAL; |
| 7859 | break; |
| 7860 | case NL80211_CHAN_WIDTH_80: |
| 7861 | case NL80211_CHAN_WIDTH_80P80: |
| 7862 | case NL80211_CHAN_WIDTH_160: |
| 7863 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7864 | return -EINVAL; |
| 7865 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7866 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7867 | return -EINVAL; |
| 7868 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7869 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7870 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7871 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7872 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7873 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7874 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7875 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7876 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7877 | u8 *rates = |
| 7878 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7879 | int n_rates = |
| 7880 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7881 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7882 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7883 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7884 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7885 | &ibss.basic_rates); |
| 7886 | if (err) |
| 7887 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7888 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7889 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7890 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7891 | memcpy(&ibss.ht_capa_mask, |
| 7892 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7893 | sizeof(ibss.ht_capa_mask)); |
| 7894 | |
| 7895 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7896 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7897 | return -EINVAL; |
| 7898 | memcpy(&ibss.ht_capa, |
| 7899 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7900 | sizeof(ibss.ht_capa)); |
| 7901 | } |
| 7902 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7903 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7904 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7905 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7906 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7907 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7908 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7909 | bool no_ht = false; |
| 7910 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7911 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7912 | info->attrs[NL80211_ATTR_KEYS], |
| 7913 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7914 | if (IS_ERR(connkeys)) |
| 7915 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7916 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7917 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7918 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 7919 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7920 | return -EINVAL; |
| 7921 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7922 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7923 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7924 | ibss.control_port = |
| 7925 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7926 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7927 | ibss.userspace_handles_dfs = |
| 7928 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7929 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7930 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7931 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7932 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7933 | return err; |
| 7934 | } |
| 7935 | |
| 7936 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7937 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7939 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7940 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7941 | if (!rdev->ops->leave_ibss) |
| 7942 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7944 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7945 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7946 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7947 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7948 | } |
| 7949 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7950 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7951 | { |
| 7952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7953 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7954 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7955 | u32 nla_rate; |
| 7956 | int err; |
| 7957 | |
| 7958 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7959 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7960 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7961 | return -EOPNOTSUPP; |
| 7962 | |
| 7963 | if (!rdev->ops->set_mcast_rate) |
| 7964 | return -EOPNOTSUPP; |
| 7965 | |
| 7966 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7967 | |
| 7968 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7969 | return -EINVAL; |
| 7970 | |
| 7971 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7972 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7973 | return -EINVAL; |
| 7974 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7975 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7976 | |
| 7977 | return err; |
| 7978 | } |
| 7979 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7980 | static struct sk_buff * |
| 7981 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7982 | struct wireless_dev *wdev, int approxlen, |
| 7983 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7984 | enum nl80211_attrs attr, |
| 7985 | const struct nl80211_vendor_cmd_info *info, |
| 7986 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7987 | { |
| 7988 | struct sk_buff *skb; |
| 7989 | void *hdr; |
| 7990 | struct nlattr *data; |
| 7991 | |
| 7992 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7993 | if (!skb) |
| 7994 | return NULL; |
| 7995 | |
| 7996 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7997 | if (!hdr) { |
| 7998 | kfree_skb(skb); |
| 7999 | return NULL; |
| 8000 | } |
| 8001 | |
| 8002 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8003 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8004 | |
| 8005 | if (info) { |
| 8006 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8007 | info->vendor_id)) |
| 8008 | goto nla_put_failure; |
| 8009 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8010 | info->subcmd)) |
| 8011 | goto nla_put_failure; |
| 8012 | } |
| 8013 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8014 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8015 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8016 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8017 | goto nla_put_failure; |
| 8018 | if (wdev->netdev && |
| 8019 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8020 | wdev->netdev->ifindex)) |
| 8021 | goto nla_put_failure; |
| 8022 | } |
| 8023 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8024 | data = nla_nest_start(skb, attr); |
| 8025 | |
| 8026 | ((void **)skb->cb)[0] = rdev; |
| 8027 | ((void **)skb->cb)[1] = hdr; |
| 8028 | ((void **)skb->cb)[2] = data; |
| 8029 | |
| 8030 | return skb; |
| 8031 | |
| 8032 | nla_put_failure: |
| 8033 | kfree_skb(skb); |
| 8034 | return NULL; |
| 8035 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8036 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8037 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8038 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8039 | enum nl80211_commands cmd, |
| 8040 | enum nl80211_attrs attr, |
| 8041 | int vendor_event_idx, |
| 8042 | int approxlen, gfp_t gfp) |
| 8043 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8044 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8045 | const struct nl80211_vendor_cmd_info *info; |
| 8046 | |
| 8047 | switch (cmd) { |
| 8048 | case NL80211_CMD_TESTMODE: |
| 8049 | if (WARN_ON(vendor_event_idx != -1)) |
| 8050 | return NULL; |
| 8051 | info = NULL; |
| 8052 | break; |
| 8053 | case NL80211_CMD_VENDOR: |
| 8054 | if (WARN_ON(vendor_event_idx < 0 || |
| 8055 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8056 | return NULL; |
| 8057 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8058 | break; |
| 8059 | default: |
| 8060 | WARN_ON(1); |
| 8061 | return NULL; |
| 8062 | } |
| 8063 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8064 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8065 | cmd, attr, info, gfp); |
| 8066 | } |
| 8067 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8068 | |
| 8069 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8070 | { |
| 8071 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8072 | void *hdr = ((void **)skb->cb)[1]; |
| 8073 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8074 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8075 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8076 | /* clear CB data for netlink core to own from now on */ |
| 8077 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8078 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8079 | nla_nest_end(skb, data); |
| 8080 | genlmsg_end(skb, hdr); |
| 8081 | |
| 8082 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8083 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8084 | |
| 8085 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8086 | mcgrp, gfp); |
| 8087 | } |
| 8088 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8089 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8090 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8091 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8092 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8094 | struct wireless_dev *wdev = |
| 8095 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8096 | int err; |
| 8097 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8098 | if (!rdev->ops->testmode_cmd) |
| 8099 | return -EOPNOTSUPP; |
| 8100 | |
| 8101 | if (IS_ERR(wdev)) { |
| 8102 | err = PTR_ERR(wdev); |
| 8103 | if (err != -EINVAL) |
| 8104 | return err; |
| 8105 | wdev = NULL; |
| 8106 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8107 | return -EINVAL; |
| 8108 | } |
| 8109 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8110 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8111 | return -EINVAL; |
| 8112 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8113 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8114 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8115 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8116 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8117 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8118 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8119 | return err; |
| 8120 | } |
| 8121 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8122 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8123 | struct netlink_callback *cb) |
| 8124 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8125 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8126 | int err; |
| 8127 | long phy_idx; |
| 8128 | void *data = NULL; |
| 8129 | int data_len = 0; |
| 8130 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8131 | rtnl_lock(); |
| 8132 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8133 | if (cb->args[0]) { |
| 8134 | /* |
| 8135 | * 0 is a valid index, but not valid for args[0], |
| 8136 | * so we need to offset by 1. |
| 8137 | */ |
| 8138 | phy_idx = cb->args[0] - 1; |
| 8139 | } else { |
| 8140 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 8141 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 8142 | nl80211_policy); |
| 8143 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8144 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8145 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8146 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 8147 | nl80211_fam.attrbuf); |
| 8148 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8149 | err = PTR_ERR(rdev); |
| 8150 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8151 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8152 | phy_idx = rdev->wiphy_idx; |
| 8153 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8154 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8155 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 8156 | cb->args[1] = |
| 8157 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 8158 | } |
| 8159 | |
| 8160 | if (cb->args[1]) { |
| 8161 | data = nla_data((void *)cb->args[1]); |
| 8162 | data_len = nla_len((void *)cb->args[1]); |
| 8163 | } |
| 8164 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8165 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8166 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8167 | err = -ENOENT; |
| 8168 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8169 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8170 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8171 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8172 | err = -EOPNOTSUPP; |
| 8173 | goto out_err; |
| 8174 | } |
| 8175 | |
| 8176 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8177 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8178 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8179 | NL80211_CMD_TESTMODE); |
| 8180 | struct nlattr *tmdata; |
| 8181 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8182 | if (!hdr) |
| 8183 | break; |
| 8184 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8185 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8186 | genlmsg_cancel(skb, hdr); |
| 8187 | break; |
| 8188 | } |
| 8189 | |
| 8190 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8191 | if (!tmdata) { |
| 8192 | genlmsg_cancel(skb, hdr); |
| 8193 | break; |
| 8194 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8195 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8196 | nla_nest_end(skb, tmdata); |
| 8197 | |
| 8198 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8199 | genlmsg_cancel(skb, hdr); |
| 8200 | break; |
| 8201 | } else if (err) { |
| 8202 | genlmsg_cancel(skb, hdr); |
| 8203 | goto out_err; |
| 8204 | } |
| 8205 | |
| 8206 | genlmsg_end(skb, hdr); |
| 8207 | } |
| 8208 | |
| 8209 | err = skb->len; |
| 8210 | /* see above */ |
| 8211 | cb->args[0] = phy_idx + 1; |
| 8212 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8213 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8214 | return err; |
| 8215 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8216 | #endif |
| 8217 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8218 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8219 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8220 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8221 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8222 | struct cfg80211_connect_params connect; |
| 8223 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8224 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8225 | int err; |
| 8226 | |
| 8227 | memset(&connect, 0, sizeof(connect)); |
| 8228 | |
| 8229 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8230 | return -EINVAL; |
| 8231 | |
| 8232 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8233 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8234 | return -EINVAL; |
| 8235 | |
| 8236 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8237 | connect.auth_type = |
| 8238 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8239 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8240 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8241 | return -EINVAL; |
| 8242 | } else |
| 8243 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8244 | |
| 8245 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8246 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8247 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8248 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8249 | if (err) |
| 8250 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8251 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8252 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8253 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8254 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8255 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8256 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8257 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8258 | connect.bg_scan_period = -1; |
| 8259 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8260 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8261 | connect.bg_scan_period = |
| 8262 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8263 | } |
| 8264 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8265 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8266 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8267 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8268 | connect.bssid_hint = |
| 8269 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8270 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8271 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8272 | |
| 8273 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8274 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8275 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8276 | } |
| 8277 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8278 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8279 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8280 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8281 | connect.mfp != NL80211_MFP_NO) |
| 8282 | return -EINVAL; |
| 8283 | } else { |
| 8284 | connect.mfp = NL80211_MFP_NO; |
| 8285 | } |
| 8286 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8287 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8288 | connect.prev_bssid = |
| 8289 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8290 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8291 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8292 | connect.channel = nl80211_get_valid_chan( |
| 8293 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8294 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8295 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8296 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8297 | connect.channel_hint = nl80211_get_valid_chan( |
| 8298 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8299 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8300 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8301 | } |
| 8302 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8303 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8304 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8305 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8306 | if (IS_ERR(connkeys)) |
| 8307 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8308 | } |
| 8309 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8310 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8311 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8312 | |
| 8313 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8314 | memcpy(&connect.ht_capa_mask, |
| 8315 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8316 | sizeof(connect.ht_capa_mask)); |
| 8317 | |
| 8318 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8319 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8320 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8321 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8322 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8323 | memcpy(&connect.ht_capa, |
| 8324 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8325 | sizeof(connect.ht_capa)); |
| 8326 | } |
| 8327 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8328 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8329 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8330 | |
| 8331 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8332 | memcpy(&connect.vht_capa_mask, |
| 8333 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8334 | sizeof(connect.vht_capa_mask)); |
| 8335 | |
| 8336 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8337 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8338 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8339 | return -EINVAL; |
| 8340 | } |
| 8341 | memcpy(&connect.vht_capa, |
| 8342 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8343 | sizeof(connect.vht_capa)); |
| 8344 | } |
| 8345 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8346 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8347 | if (!((rdev->wiphy.features & |
| 8348 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8349 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8350 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8351 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8352 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8353 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8354 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8355 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8356 | } |
| 8357 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8358 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8359 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8360 | kzfree(connkeys); |
| 8361 | return -EOPNOTSUPP; |
| 8362 | } |
| 8363 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8364 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8365 | /* bss selection makes no sense if bssid is set */ |
| 8366 | if (connect.bssid) { |
| 8367 | kzfree(connkeys); |
| 8368 | return -EINVAL; |
| 8369 | } |
| 8370 | |
| 8371 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8372 | wiphy, &connect.bss_select); |
| 8373 | if (err) { |
| 8374 | kzfree(connkeys); |
| 8375 | return err; |
| 8376 | } |
| 8377 | } |
| 8378 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8379 | wdev_lock(dev->ieee80211_ptr); |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8380 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8381 | connect.prev_bssid); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8382 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8383 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8384 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8385 | return err; |
| 8386 | } |
| 8387 | |
| 8388 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8389 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8391 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8392 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8393 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8394 | |
| 8395 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8396 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8397 | else |
| 8398 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8399 | |
| 8400 | if (reason == 0) |
| 8401 | return -EINVAL; |
| 8402 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8405 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8406 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8407 | wdev_lock(dev->ieee80211_ptr); |
| 8408 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8409 | wdev_unlock(dev->ieee80211_ptr); |
| 8410 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8411 | } |
| 8412 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8413 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8414 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8416 | struct net *net; |
| 8417 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8418 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8419 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8420 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8421 | |
| 8422 | net = get_net_ns_by_pid(pid); |
| 8423 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8424 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8425 | |
| 8426 | net = get_net_ns_by_fd(fd); |
| 8427 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8428 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8429 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8430 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8431 | if (IS_ERR(net)) |
| 8432 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8433 | |
| 8434 | err = 0; |
| 8435 | |
| 8436 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8437 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8438 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8439 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8440 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8441 | return err; |
| 8442 | } |
| 8443 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8444 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8447 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8448 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8449 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8450 | struct cfg80211_pmksa pmksa; |
| 8451 | |
| 8452 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8453 | |
| 8454 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8455 | return -EINVAL; |
| 8456 | |
| 8457 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8458 | return -EINVAL; |
| 8459 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8460 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8461 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8462 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8463 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8464 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8465 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8466 | |
| 8467 | switch (info->genlhdr->cmd) { |
| 8468 | case NL80211_CMD_SET_PMKSA: |
| 8469 | rdev_ops = rdev->ops->set_pmksa; |
| 8470 | break; |
| 8471 | case NL80211_CMD_DEL_PMKSA: |
| 8472 | rdev_ops = rdev->ops->del_pmksa; |
| 8473 | break; |
| 8474 | default: |
| 8475 | WARN_ON(1); |
| 8476 | break; |
| 8477 | } |
| 8478 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8479 | if (!rdev_ops) |
| 8480 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8482 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8483 | } |
| 8484 | |
| 8485 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8486 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8488 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8489 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8490 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8492 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8493 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8494 | if (!rdev->ops->flush_pmksa) |
| 8495 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8496 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8497 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8498 | } |
| 8499 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8500 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8501 | { |
| 8502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8503 | struct net_device *dev = info->user_ptr[1]; |
| 8504 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8505 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8506 | u16 status_code; |
| 8507 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8508 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8509 | |
| 8510 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8511 | !rdev->ops->tdls_mgmt) |
| 8512 | return -EOPNOTSUPP; |
| 8513 | |
| 8514 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8515 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8516 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8517 | !info->attrs[NL80211_ATTR_IE] || |
| 8518 | !info->attrs[NL80211_ATTR_MAC]) |
| 8519 | return -EINVAL; |
| 8520 | |
| 8521 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8522 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8523 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8524 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8525 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8526 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8527 | peer_capability = |
| 8528 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8529 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8530 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8531 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8532 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8533 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8534 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8535 | } |
| 8536 | |
| 8537 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8538 | { |
| 8539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8540 | struct net_device *dev = info->user_ptr[1]; |
| 8541 | enum nl80211_tdls_operation operation; |
| 8542 | u8 *peer; |
| 8543 | |
| 8544 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8545 | !rdev->ops->tdls_oper) |
| 8546 | return -EOPNOTSUPP; |
| 8547 | |
| 8548 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8549 | !info->attrs[NL80211_ATTR_MAC]) |
| 8550 | return -EINVAL; |
| 8551 | |
| 8552 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8553 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8554 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8555 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8556 | } |
| 8557 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8558 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8559 | struct genl_info *info) |
| 8560 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8561 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8562 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8563 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8564 | struct sk_buff *msg; |
| 8565 | void *hdr; |
| 8566 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8567 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8568 | int err; |
| 8569 | |
| 8570 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8571 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8572 | return -EINVAL; |
| 8573 | |
| 8574 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8575 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8576 | if (!rdev->ops->remain_on_channel || |
| 8577 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8578 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8579 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8580 | /* |
| 8581 | * We should be on that channel for at least a minimum amount of |
| 8582 | * time (10ms) but no longer than the driver supports. |
| 8583 | */ |
| 8584 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8585 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8586 | return -EINVAL; |
| 8587 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8588 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8589 | if (err) |
| 8590 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8591 | |
| 8592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8593 | if (!msg) |
| 8594 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8595 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8596 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8597 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8598 | if (!hdr) { |
| 8599 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8600 | goto free_msg; |
| 8601 | } |
| 8602 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8603 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8604 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8605 | |
| 8606 | if (err) |
| 8607 | goto free_msg; |
| 8608 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8609 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8610 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8611 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8612 | |
| 8613 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8614 | |
| 8615 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8616 | |
| 8617 | nla_put_failure: |
| 8618 | err = -ENOBUFS; |
| 8619 | free_msg: |
| 8620 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8621 | return err; |
| 8622 | } |
| 8623 | |
| 8624 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8625 | struct genl_info *info) |
| 8626 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8628 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8629 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8630 | |
| 8631 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8632 | return -EINVAL; |
| 8633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8634 | if (!rdev->ops->cancel_remain_on_channel) |
| 8635 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8636 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8637 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8638 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8639 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8640 | } |
| 8641 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8642 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8643 | u8 *rates, u8 rates_len) |
| 8644 | { |
| 8645 | u8 i; |
| 8646 | u32 mask = 0; |
| 8647 | |
| 8648 | for (i = 0; i < rates_len; i++) { |
| 8649 | int rate = (rates[i] & 0x7f) * 5; |
| 8650 | int ridx; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8651 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8652 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8653 | struct ieee80211_rate *srate = |
| 8654 | &sband->bitrates[ridx]; |
| 8655 | if (rate == srate->bitrate) { |
| 8656 | mask |= 1 << ridx; |
| 8657 | break; |
| 8658 | } |
| 8659 | } |
| 8660 | if (ridx == sband->n_bitrates) |
| 8661 | return 0; /* rate not found */ |
| 8662 | } |
| 8663 | |
| 8664 | return mask; |
| 8665 | } |
| 8666 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8667 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8668 | u8 *rates, u8 rates_len, |
| 8669 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8670 | { |
| 8671 | u8 i; |
| 8672 | |
| 8673 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8674 | |
| 8675 | for (i = 0; i < rates_len; i++) { |
| 8676 | int ridx, rbit; |
| 8677 | |
| 8678 | ridx = rates[i] / 8; |
| 8679 | rbit = BIT(rates[i] % 8); |
| 8680 | |
| 8681 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8682 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8683 | return false; |
| 8684 | |
| 8685 | /* check availability */ |
| 8686 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8687 | mcs[ridx] |= rbit; |
| 8688 | else |
| 8689 | return false; |
| 8690 | } |
| 8691 | |
| 8692 | return true; |
| 8693 | } |
| 8694 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8695 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8696 | { |
| 8697 | u16 mcs_mask = 0; |
| 8698 | |
| 8699 | switch (vht_mcs_map) { |
| 8700 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8701 | break; |
| 8702 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8703 | mcs_mask = 0x00FF; |
| 8704 | break; |
| 8705 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8706 | mcs_mask = 0x01FF; |
| 8707 | break; |
| 8708 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8709 | mcs_mask = 0x03FF; |
| 8710 | break; |
| 8711 | default: |
| 8712 | break; |
| 8713 | } |
| 8714 | |
| 8715 | return mcs_mask; |
| 8716 | } |
| 8717 | |
| 8718 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8719 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8720 | { |
| 8721 | u8 nss; |
| 8722 | |
| 8723 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8724 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8725 | vht_mcs_map >>= 2; |
| 8726 | } |
| 8727 | } |
| 8728 | |
| 8729 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8730 | struct nl80211_txrate_vht *txrate, |
| 8731 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8732 | { |
| 8733 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8734 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8735 | u8 i; |
| 8736 | |
| 8737 | if (!sband->vht_cap.vht_supported) |
| 8738 | return false; |
| 8739 | |
| 8740 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8741 | |
| 8742 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8743 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8744 | |
| 8745 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8746 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8747 | mcs[i] = txrate->mcs[i]; |
| 8748 | else |
| 8749 | return false; |
| 8750 | } |
| 8751 | |
| 8752 | return true; |
| 8753 | } |
| 8754 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8755 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8756 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8757 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8758 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8759 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8760 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8761 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8762 | }; |
| 8763 | |
| 8764 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8765 | struct genl_info *info) |
| 8766 | { |
| 8767 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8769 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8770 | int rem, i; |
| 8771 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8772 | struct nlattr *tx_rates; |
| 8773 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8774 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8776 | if (!rdev->ops->set_bitrate_mask) |
| 8777 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8778 | |
| 8779 | memset(&mask, 0, sizeof(mask)); |
| 8780 | /* Default to all rates enabled */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8781 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8782 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8783 | |
| 8784 | if (!sband) |
| 8785 | continue; |
| 8786 | |
| 8787 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8788 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8789 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8790 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8791 | |
| 8792 | if (!sband->vht_cap.vht_supported) |
| 8793 | continue; |
| 8794 | |
| 8795 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8796 | 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] | 8797 | } |
| 8798 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8799 | /* if no rates are given set it back to the defaults */ |
| 8800 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8801 | goto out; |
| 8802 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8803 | /* |
| 8804 | * The nested attribute uses enum nl80211_band as the index. This maps |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8805 | * directly to the enum nl80211_band values used in cfg80211. |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8806 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8807 | 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] | 8808 | 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] | 8809 | enum nl80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8810 | int err; |
| 8811 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8812 | if (band < 0 || band >= NUM_NL80211_BANDS) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8813 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8814 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8815 | if (sband == NULL) |
| 8816 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8817 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8818 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8819 | if (err) |
| 8820 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8821 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8822 | mask.control[band].legacy = rateset_to_mask( |
| 8823 | sband, |
| 8824 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8825 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8826 | if ((mask.control[band].legacy == 0) && |
| 8827 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8828 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8829 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8830 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8831 | if (!ht_rateset_to_mask( |
| 8832 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8833 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8834 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8835 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8836 | return -EINVAL; |
| 8837 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8838 | if (tb[NL80211_TXRATE_VHT]) { |
| 8839 | if (!vht_set_mcs_mask( |
| 8840 | sband, |
| 8841 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8842 | mask.control[band].vht_mcs)) |
| 8843 | return -EINVAL; |
| 8844 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8845 | if (tb[NL80211_TXRATE_GI]) { |
| 8846 | mask.control[band].gi = |
| 8847 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8848 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8849 | return -EINVAL; |
| 8850 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8851 | |
| 8852 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8853 | /* don't allow empty legacy rates if HT or VHT |
| 8854 | * are not even supported. |
| 8855 | */ |
| 8856 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8857 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8858 | return -EINVAL; |
| 8859 | |
| 8860 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8861 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8862 | goto out; |
| 8863 | |
| 8864 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8865 | if (mask.control[band].vht_mcs[i]) |
| 8866 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8867 | |
| 8868 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8869 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8870 | } |
| 8871 | } |
| 8872 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8873 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8874 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8875 | } |
| 8876 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8877 | 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] | 8878 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8880 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8881 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8882 | |
| 8883 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8884 | return -EINVAL; |
| 8885 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8886 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8887 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8888 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8889 | switch (wdev->iftype) { |
| 8890 | case NL80211_IFTYPE_STATION: |
| 8891 | case NL80211_IFTYPE_ADHOC: |
| 8892 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8893 | case NL80211_IFTYPE_AP: |
| 8894 | case NL80211_IFTYPE_AP_VLAN: |
| 8895 | case NL80211_IFTYPE_MESH_POINT: |
| 8896 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8897 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8898 | break; |
| 8899 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8900 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8901 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8902 | |
| 8903 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8904 | if (!rdev->ops->mgmt_tx) |
| 8905 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8906 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8907 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8908 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8909 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8910 | } |
| 8911 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8912 | 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] | 8913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8915 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8916 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8917 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8918 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8919 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8920 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8921 | struct cfg80211_mgmt_tx_params params = { |
| 8922 | .dont_wait_for_ack = |
| 8923 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8924 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8925 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8926 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8927 | return -EINVAL; |
| 8928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8929 | if (!rdev->ops->mgmt_tx) |
| 8930 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8931 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8932 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8933 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8934 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8935 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8936 | case NL80211_IFTYPE_STATION: |
| 8937 | case NL80211_IFTYPE_ADHOC: |
| 8938 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8939 | case NL80211_IFTYPE_AP: |
| 8940 | case NL80211_IFTYPE_AP_VLAN: |
| 8941 | case NL80211_IFTYPE_MESH_POINT: |
| 8942 | case NL80211_IFTYPE_P2P_GO: |
| 8943 | break; |
| 8944 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8945 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8946 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8947 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8948 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8949 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8950 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8951 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8952 | |
| 8953 | /* |
| 8954 | * We should wait on the channel for at least a minimum amount |
| 8955 | * of time (10ms) but no longer than the driver supports. |
| 8956 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8957 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8958 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8959 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8960 | } |
| 8961 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8962 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8963 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8964 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8965 | return -EINVAL; |
| 8966 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8967 | 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] | 8968 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8969 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8970 | * the driver. The latter will use the current one |
| 8971 | */ |
| 8972 | chandef.chan = NULL; |
| 8973 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8974 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8975 | if (err) |
| 8976 | return err; |
| 8977 | } |
| 8978 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8979 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8980 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8981 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8982 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8983 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8984 | |
| 8985 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8986 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8987 | int i; |
| 8988 | |
| 8989 | if (len % sizeof(u16)) |
| 8990 | return -EINVAL; |
| 8991 | |
| 8992 | params.n_csa_offsets = len / sizeof(u16); |
| 8993 | params.csa_offsets = |
| 8994 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8995 | |
| 8996 | /* check that all the offsets fit the frame */ |
| 8997 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8998 | if (params.csa_offsets[i] >= params.len) |
| 8999 | return -EINVAL; |
| 9000 | } |
| 9001 | } |
| 9002 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9003 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9004 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9005 | if (!msg) |
| 9006 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9007 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9008 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9009 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9010 | if (!hdr) { |
| 9011 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9012 | goto free_msg; |
| 9013 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9014 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9015 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9016 | params.chan = chandef.chan; |
| 9017 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9018 | if (err) |
| 9019 | goto free_msg; |
| 9020 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9021 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9022 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9023 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9024 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9025 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9026 | genlmsg_end(msg, hdr); |
| 9027 | return genlmsg_reply(msg, info); |
| 9028 | } |
| 9029 | |
| 9030 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9031 | |
| 9032 | nla_put_failure: |
| 9033 | err = -ENOBUFS; |
| 9034 | free_msg: |
| 9035 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9036 | return err; |
| 9037 | } |
| 9038 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9039 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9040 | { |
| 9041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9042 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9043 | u64 cookie; |
| 9044 | |
| 9045 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9046 | return -EINVAL; |
| 9047 | |
| 9048 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9049 | return -EOPNOTSUPP; |
| 9050 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9051 | switch (wdev->iftype) { |
| 9052 | case NL80211_IFTYPE_STATION: |
| 9053 | case NL80211_IFTYPE_ADHOC: |
| 9054 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9055 | case NL80211_IFTYPE_AP: |
| 9056 | case NL80211_IFTYPE_AP_VLAN: |
| 9057 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9058 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9059 | break; |
| 9060 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9061 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9062 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9063 | |
| 9064 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9065 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9066 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9067 | } |
| 9068 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9069 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9072 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9073 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9074 | u8 ps_state; |
| 9075 | bool state; |
| 9076 | int err; |
| 9077 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9078 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9079 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9080 | |
| 9081 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9082 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9083 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9084 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9085 | |
| 9086 | wdev = dev->ieee80211_ptr; |
| 9087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9088 | if (!rdev->ops->set_power_mgmt) |
| 9089 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9090 | |
| 9091 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9092 | |
| 9093 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9094 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9095 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9096 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9097 | if (!err) |
| 9098 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9099 | return err; |
| 9100 | } |
| 9101 | |
| 9102 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9103 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9105 | enum nl80211_ps_state ps_state; |
| 9106 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9107 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9108 | struct sk_buff *msg; |
| 9109 | void *hdr; |
| 9110 | int err; |
| 9111 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9112 | wdev = dev->ieee80211_ptr; |
| 9113 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9114 | if (!rdev->ops->set_power_mgmt) |
| 9115 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9116 | |
| 9117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9118 | if (!msg) |
| 9119 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9120 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9121 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9122 | NL80211_CMD_GET_POWER_SAVE); |
| 9123 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9124 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9125 | goto free_msg; |
| 9126 | } |
| 9127 | |
| 9128 | if (wdev->ps) |
| 9129 | ps_state = NL80211_PS_ENABLED; |
| 9130 | else |
| 9131 | ps_state = NL80211_PS_DISABLED; |
| 9132 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9133 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9134 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9135 | |
| 9136 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9137 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9138 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9139 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9140 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9141 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9142 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9143 | return err; |
| 9144 | } |
| 9145 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9146 | static const struct nla_policy |
| 9147 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9148 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9149 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9150 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9151 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9152 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9153 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9154 | }; |
| 9155 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9156 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9157 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9158 | { |
| 9159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9160 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9161 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9162 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9163 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9164 | return -EINVAL; |
| 9165 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9166 | if (!rdev->ops->set_cqm_txe_config) |
| 9167 | return -EOPNOTSUPP; |
| 9168 | |
| 9169 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9170 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9171 | return -EOPNOTSUPP; |
| 9172 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9173 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9174 | } |
| 9175 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9176 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9177 | s32 threshold, u32 hysteresis) |
| 9178 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9180 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9181 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9182 | |
| 9183 | if (threshold > 0) |
| 9184 | return -EINVAL; |
| 9185 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9186 | /* disabling - hysteresis should also be zero then */ |
| 9187 | if (threshold == 0) |
| 9188 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9190 | if (!rdev->ops->set_cqm_rssi_config) |
| 9191 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9192 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9193 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9194 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9195 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9196 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9197 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9198 | } |
| 9199 | |
| 9200 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9201 | { |
| 9202 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9203 | struct nlattr *cqm; |
| 9204 | int err; |
| 9205 | |
| 9206 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9207 | if (!cqm) |
| 9208 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9209 | |
| 9210 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9211 | nl80211_attr_cqm_policy); |
| 9212 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9213 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9214 | |
| 9215 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9216 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9217 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9218 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9219 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9220 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9221 | } |
| 9222 | |
| 9223 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9224 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9225 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9226 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9227 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9228 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9229 | |
| 9230 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9231 | } |
| 9232 | |
| 9233 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9234 | } |
| 9235 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9236 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9237 | { |
| 9238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9239 | struct net_device *dev = info->user_ptr[1]; |
| 9240 | struct ocb_setup setup = {}; |
| 9241 | int err; |
| 9242 | |
| 9243 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9244 | if (err) |
| 9245 | return err; |
| 9246 | |
| 9247 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9248 | } |
| 9249 | |
| 9250 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9251 | { |
| 9252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9253 | struct net_device *dev = info->user_ptr[1]; |
| 9254 | |
| 9255 | return cfg80211_leave_ocb(rdev, dev); |
| 9256 | } |
| 9257 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9258 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9259 | { |
| 9260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9261 | struct net_device *dev = info->user_ptr[1]; |
| 9262 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9263 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9264 | int err; |
| 9265 | |
| 9266 | /* start with default */ |
| 9267 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9268 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9269 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9270 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9271 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9272 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9273 | if (err) |
| 9274 | return err; |
| 9275 | } |
| 9276 | |
| 9277 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9278 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9279 | return -EINVAL; |
| 9280 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9281 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9282 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9283 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9284 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9285 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9286 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9287 | return -EINVAL; |
| 9288 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9289 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9290 | setup.beacon_interval = |
| 9291 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9292 | |
| 9293 | err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval); |
| 9294 | if (err) |
| 9295 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9296 | } |
| 9297 | |
| 9298 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9299 | setup.dtim_period = |
| 9300 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9301 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9302 | return -EINVAL; |
| 9303 | } |
| 9304 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9305 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9306 | /* parse additional setup parameters if given */ |
| 9307 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9308 | if (err) |
| 9309 | return err; |
| 9310 | } |
| 9311 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9312 | if (setup.user_mpm) |
| 9313 | cfg.auto_open_plinks = false; |
| 9314 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9315 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9316 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9317 | if (err) |
| 9318 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9319 | } else { |
| 9320 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9321 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9322 | } |
| 9323 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9324 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9325 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9326 | int n_rates = |
| 9327 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9328 | struct ieee80211_supported_band *sband; |
| 9329 | |
| 9330 | if (!setup.chandef.chan) |
| 9331 | return -EINVAL; |
| 9332 | |
| 9333 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9334 | |
| 9335 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9336 | &setup.basic_rates); |
| 9337 | if (err) |
| 9338 | return err; |
| 9339 | } |
| 9340 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9341 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9342 | } |
| 9343 | |
| 9344 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9345 | { |
| 9346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9347 | struct net_device *dev = info->user_ptr[1]; |
| 9348 | |
| 9349 | return cfg80211_leave_mesh(rdev, dev); |
| 9350 | } |
| 9351 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9352 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9353 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9354 | struct cfg80211_registered_device *rdev) |
| 9355 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9356 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9357 | struct nlattr *nl_pats, *nl_pat; |
| 9358 | int i, pat_len; |
| 9359 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9360 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9361 | return 0; |
| 9362 | |
| 9363 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9364 | if (!nl_pats) |
| 9365 | return -ENOBUFS; |
| 9366 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9367 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9368 | nl_pat = nla_nest_start(msg, i + 1); |
| 9369 | if (!nl_pat) |
| 9370 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9371 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9372 | 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] | 9373 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9374 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9375 | wowlan->patterns[i].pattern) || |
| 9376 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9377 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9378 | return -ENOBUFS; |
| 9379 | nla_nest_end(msg, nl_pat); |
| 9380 | } |
| 9381 | nla_nest_end(msg, nl_pats); |
| 9382 | |
| 9383 | return 0; |
| 9384 | } |
| 9385 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9386 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9387 | struct cfg80211_wowlan_tcp *tcp) |
| 9388 | { |
| 9389 | struct nlattr *nl_tcp; |
| 9390 | |
| 9391 | if (!tcp) |
| 9392 | return 0; |
| 9393 | |
| 9394 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9395 | if (!nl_tcp) |
| 9396 | return -ENOBUFS; |
| 9397 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9398 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9399 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9400 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9401 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9402 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9403 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9404 | tcp->payload_len, tcp->payload) || |
| 9405 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9406 | tcp->data_interval) || |
| 9407 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9408 | tcp->wake_len, tcp->wake_data) || |
| 9409 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9410 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9411 | return -ENOBUFS; |
| 9412 | |
| 9413 | if (tcp->payload_seq.len && |
| 9414 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9415 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9416 | return -ENOBUFS; |
| 9417 | |
| 9418 | if (tcp->payload_tok.len && |
| 9419 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9420 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9421 | &tcp->payload_tok)) |
| 9422 | return -ENOBUFS; |
| 9423 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9424 | nla_nest_end(msg, nl_tcp); |
| 9425 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9426 | return 0; |
| 9427 | } |
| 9428 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9429 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9430 | struct cfg80211_sched_scan_request *req) |
| 9431 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9432 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9433 | int i; |
| 9434 | |
| 9435 | if (!req) |
| 9436 | return 0; |
| 9437 | |
| 9438 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9439 | if (!nd) |
| 9440 | return -ENOBUFS; |
| 9441 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9442 | if (req->n_scan_plans == 1 && |
| 9443 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9444 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9445 | return -ENOBUFS; |
| 9446 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9447 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9448 | return -ENOBUFS; |
| 9449 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9450 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9451 | if (!freqs) |
| 9452 | return -ENOBUFS; |
| 9453 | |
| 9454 | for (i = 0; i < req->n_channels; i++) |
| 9455 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 9456 | |
| 9457 | nla_nest_end(msg, freqs); |
| 9458 | |
| 9459 | if (req->n_match_sets) { |
| 9460 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 9461 | for (i = 0; i < req->n_match_sets; i++) { |
| 9462 | match = nla_nest_start(msg, i); |
| 9463 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9464 | req->match_sets[i].ssid.ssid_len, |
| 9465 | req->match_sets[i].ssid.ssid); |
| 9466 | nla_nest_end(msg, match); |
| 9467 | } |
| 9468 | nla_nest_end(msg, matches); |
| 9469 | } |
| 9470 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9471 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9472 | if (!scan_plans) |
| 9473 | return -ENOBUFS; |
| 9474 | |
| 9475 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9476 | scan_plan = nla_nest_start(msg, i + 1); |
| 9477 | if (!scan_plan || |
| 9478 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9479 | req->scan_plans[i].interval) || |
| 9480 | (req->scan_plans[i].iterations && |
| 9481 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9482 | req->scan_plans[i].iterations))) |
| 9483 | return -ENOBUFS; |
| 9484 | nla_nest_end(msg, scan_plan); |
| 9485 | } |
| 9486 | nla_nest_end(msg, scan_plans); |
| 9487 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9488 | nla_nest_end(msg, nd); |
| 9489 | |
| 9490 | return 0; |
| 9491 | } |
| 9492 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9493 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9494 | { |
| 9495 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9496 | struct sk_buff *msg; |
| 9497 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9498 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9499 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9500 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9501 | return -EOPNOTSUPP; |
| 9502 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9503 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9504 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9505 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9506 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9507 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9508 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9509 | } |
| 9510 | |
| 9511 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9512 | if (!msg) |
| 9513 | return -ENOMEM; |
| 9514 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9515 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9516 | NL80211_CMD_GET_WOWLAN); |
| 9517 | if (!hdr) |
| 9518 | goto nla_put_failure; |
| 9519 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9520 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9521 | struct nlattr *nl_wowlan; |
| 9522 | |
| 9523 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9524 | if (!nl_wowlan) |
| 9525 | goto nla_put_failure; |
| 9526 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9527 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9528 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9529 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9530 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9531 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9532 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9533 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9534 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9535 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9536 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9537 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9538 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9539 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9540 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9541 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9542 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9543 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9544 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9545 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9546 | if (nl80211_send_wowlan_tcp(msg, |
| 9547 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9548 | goto nla_put_failure; |
| 9549 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9550 | if (nl80211_send_wowlan_nd( |
| 9551 | msg, |
| 9552 | rdev->wiphy.wowlan_config->nd_config)) |
| 9553 | goto nla_put_failure; |
| 9554 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9555 | nla_nest_end(msg, nl_wowlan); |
| 9556 | } |
| 9557 | |
| 9558 | genlmsg_end(msg, hdr); |
| 9559 | return genlmsg_reply(msg, info); |
| 9560 | |
| 9561 | nla_put_failure: |
| 9562 | nlmsg_free(msg); |
| 9563 | return -ENOBUFS; |
| 9564 | } |
| 9565 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9566 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9567 | struct nlattr *attr, |
| 9568 | struct cfg80211_wowlan *trig) |
| 9569 | { |
| 9570 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9571 | struct cfg80211_wowlan_tcp *cfg; |
| 9572 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9573 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9574 | u32 size; |
| 9575 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9576 | int err, port; |
| 9577 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9578 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9579 | return -EINVAL; |
| 9580 | |
| 9581 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9582 | nla_data(attr), nla_len(attr), |
| 9583 | nl80211_wowlan_tcp_policy); |
| 9584 | if (err) |
| 9585 | return err; |
| 9586 | |
| 9587 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9588 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9589 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9590 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9591 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9592 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9593 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9594 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9595 | return -EINVAL; |
| 9596 | |
| 9597 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9598 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9599 | return -EINVAL; |
| 9600 | |
| 9601 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9602 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9603 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9604 | return -EINVAL; |
| 9605 | |
| 9606 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9607 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9608 | return -EINVAL; |
| 9609 | |
| 9610 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9611 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9612 | return -EINVAL; |
| 9613 | |
| 9614 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9615 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9616 | |
| 9617 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9618 | tokens_size = tokln - sizeof(*tok); |
| 9619 | |
| 9620 | if (!tok->len || tokens_size % tok->len) |
| 9621 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9622 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9623 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9624 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9625 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9626 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9627 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9628 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9629 | return -EINVAL; |
| 9630 | if (tok->offset + tok->len > data_size) |
| 9631 | return -EINVAL; |
| 9632 | } |
| 9633 | |
| 9634 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9635 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9636 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9637 | return -EINVAL; |
| 9638 | if (seq->len == 0 || seq->len > 4) |
| 9639 | return -EINVAL; |
| 9640 | if (seq->len + seq->offset > data_size) |
| 9641 | return -EINVAL; |
| 9642 | } |
| 9643 | |
| 9644 | size = sizeof(*cfg); |
| 9645 | size += data_size; |
| 9646 | size += wake_size + wake_mask_size; |
| 9647 | size += tokens_size; |
| 9648 | |
| 9649 | cfg = kzalloc(size, GFP_KERNEL); |
| 9650 | if (!cfg) |
| 9651 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9652 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9653 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9654 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9655 | ETH_ALEN); |
| 9656 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9657 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9658 | else |
| 9659 | port = 0; |
| 9660 | #ifdef CONFIG_INET |
| 9661 | /* allocate a socket and port for it and use it */ |
| 9662 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9663 | IPPROTO_TCP, &cfg->sock, 1); |
| 9664 | if (err) { |
| 9665 | kfree(cfg); |
| 9666 | return err; |
| 9667 | } |
| 9668 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9669 | sock_release(cfg->sock); |
| 9670 | kfree(cfg); |
| 9671 | return -EADDRINUSE; |
| 9672 | } |
| 9673 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9674 | #else |
| 9675 | if (!port) { |
| 9676 | kfree(cfg); |
| 9677 | return -EINVAL; |
| 9678 | } |
| 9679 | cfg->src_port = port; |
| 9680 | #endif |
| 9681 | |
| 9682 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9683 | cfg->payload_len = data_size; |
| 9684 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9685 | memcpy((void *)cfg->payload, |
| 9686 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9687 | data_size); |
| 9688 | if (seq) |
| 9689 | cfg->payload_seq = *seq; |
| 9690 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9691 | cfg->wake_len = wake_size; |
| 9692 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9693 | memcpy((void *)cfg->wake_data, |
| 9694 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9695 | wake_size); |
| 9696 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9697 | data_size + wake_size; |
| 9698 | memcpy((void *)cfg->wake_mask, |
| 9699 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9700 | wake_mask_size); |
| 9701 | if (tok) { |
| 9702 | cfg->tokens_size = tokens_size; |
| 9703 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9704 | } |
| 9705 | |
| 9706 | trig->tcp = cfg; |
| 9707 | |
| 9708 | return 0; |
| 9709 | } |
| 9710 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9711 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9712 | const struct wiphy_wowlan_support *wowlan, |
| 9713 | struct nlattr *attr, |
| 9714 | struct cfg80211_wowlan *trig) |
| 9715 | { |
| 9716 | struct nlattr **tb; |
| 9717 | int err; |
| 9718 | |
| 9719 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9720 | if (!tb) |
| 9721 | return -ENOMEM; |
| 9722 | |
| 9723 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9724 | err = -EOPNOTSUPP; |
| 9725 | goto out; |
| 9726 | } |
| 9727 | |
| 9728 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9729 | nla_data(attr), nla_len(attr), |
| 9730 | nl80211_policy); |
| 9731 | if (err) |
| 9732 | goto out; |
| 9733 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9734 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9735 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9736 | if (err) |
| 9737 | trig->nd_config = NULL; |
| 9738 | |
| 9739 | out: |
| 9740 | kfree(tb); |
| 9741 | return err; |
| 9742 | } |
| 9743 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9744 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9745 | { |
| 9746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9747 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9748 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9749 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9750 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9751 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9752 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9753 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9754 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9755 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9756 | return -EOPNOTSUPP; |
| 9757 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9758 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9759 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9760 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9761 | goto set_wakeup; |
| 9762 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9763 | |
| 9764 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9765 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9766 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9767 | nl80211_wowlan_policy); |
| 9768 | if (err) |
| 9769 | return err; |
| 9770 | |
| 9771 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9772 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9773 | return -EINVAL; |
| 9774 | new_triggers.any = true; |
| 9775 | } |
| 9776 | |
| 9777 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9778 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9779 | return -EINVAL; |
| 9780 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9781 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9782 | } |
| 9783 | |
| 9784 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9785 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9786 | return -EINVAL; |
| 9787 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9788 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9789 | } |
| 9790 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9791 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9792 | return -EINVAL; |
| 9793 | |
| 9794 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9795 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9796 | return -EINVAL; |
| 9797 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9798 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9799 | } |
| 9800 | |
| 9801 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9802 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9803 | return -EINVAL; |
| 9804 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9805 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9806 | } |
| 9807 | |
| 9808 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9809 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9810 | return -EINVAL; |
| 9811 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9812 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9813 | } |
| 9814 | |
| 9815 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9816 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9817 | return -EINVAL; |
| 9818 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9819 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9820 | } |
| 9821 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9822 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9823 | struct nlattr *pat; |
| 9824 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9825 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9826 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9827 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9828 | regular = true; |
| 9829 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9830 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9831 | rem) |
| 9832 | n_patterns++; |
| 9833 | if (n_patterns > wowlan->n_patterns) |
| 9834 | return -EINVAL; |
| 9835 | |
| 9836 | new_triggers.patterns = kcalloc(n_patterns, |
| 9837 | sizeof(new_triggers.patterns[0]), |
| 9838 | GFP_KERNEL); |
| 9839 | if (!new_triggers.patterns) |
| 9840 | return -ENOMEM; |
| 9841 | |
| 9842 | new_triggers.n_patterns = n_patterns; |
| 9843 | i = 0; |
| 9844 | |
| 9845 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9846 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9847 | u8 *mask_pat; |
| 9848 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9849 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9850 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9851 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9852 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9853 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9854 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9855 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9856 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9857 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9858 | goto error; |
| 9859 | if (pat_len > wowlan->pattern_max_len || |
| 9860 | pat_len < wowlan->pattern_min_len) |
| 9861 | goto error; |
| 9862 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9863 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9864 | pkt_offset = 0; |
| 9865 | else |
| 9866 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9867 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9868 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9869 | goto error; |
| 9870 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9871 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9872 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9873 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9874 | err = -ENOMEM; |
| 9875 | goto error; |
| 9876 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9877 | new_triggers.patterns[i].mask = mask_pat; |
| 9878 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9879 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9880 | mask_pat += mask_len; |
| 9881 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9882 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9883 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9884 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9885 | pat_len); |
| 9886 | i++; |
| 9887 | } |
| 9888 | } |
| 9889 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9890 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9891 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9892 | err = nl80211_parse_wowlan_tcp( |
| 9893 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9894 | &new_triggers); |
| 9895 | if (err) |
| 9896 | goto error; |
| 9897 | } |
| 9898 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9899 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9900 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9901 | err = nl80211_parse_wowlan_nd( |
| 9902 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9903 | &new_triggers); |
| 9904 | if (err) |
| 9905 | goto error; |
| 9906 | } |
| 9907 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9908 | /* The 'any' trigger means the device continues operating more or less |
| 9909 | * as in its normal operation mode and wakes up the host on most of the |
| 9910 | * normal interrupts (like packet RX, ...) |
| 9911 | * It therefore makes little sense to combine with the more constrained |
| 9912 | * wakeup trigger modes. |
| 9913 | */ |
| 9914 | if (new_triggers.any && regular) { |
| 9915 | err = -EINVAL; |
| 9916 | goto error; |
| 9917 | } |
| 9918 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9919 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9920 | if (!ntrig) { |
| 9921 | err = -ENOMEM; |
| 9922 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9923 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9924 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9925 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9926 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9927 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9928 | if (rdev->ops->set_wakeup && |
| 9929 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9930 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9931 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9932 | return 0; |
| 9933 | error: |
| 9934 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9935 | kfree(new_triggers.patterns[i].mask); |
| 9936 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9937 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9938 | sock_release(new_triggers.tcp->sock); |
| 9939 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 9940 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9941 | return err; |
| 9942 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9943 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9944 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9945 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9946 | struct cfg80211_registered_device *rdev) |
| 9947 | { |
| 9948 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9949 | int i, j, pat_len; |
| 9950 | struct cfg80211_coalesce_rules *rule; |
| 9951 | |
| 9952 | if (!rdev->coalesce->n_rules) |
| 9953 | return 0; |
| 9954 | |
| 9955 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9956 | if (!nl_rules) |
| 9957 | return -ENOBUFS; |
| 9958 | |
| 9959 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9960 | nl_rule = nla_nest_start(msg, i + 1); |
| 9961 | if (!nl_rule) |
| 9962 | return -ENOBUFS; |
| 9963 | |
| 9964 | rule = &rdev->coalesce->rules[i]; |
| 9965 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9966 | rule->delay)) |
| 9967 | return -ENOBUFS; |
| 9968 | |
| 9969 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9970 | rule->condition)) |
| 9971 | return -ENOBUFS; |
| 9972 | |
| 9973 | nl_pats = nla_nest_start(msg, |
| 9974 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9975 | if (!nl_pats) |
| 9976 | return -ENOBUFS; |
| 9977 | |
| 9978 | for (j = 0; j < rule->n_patterns; j++) { |
| 9979 | nl_pat = nla_nest_start(msg, j + 1); |
| 9980 | if (!nl_pat) |
| 9981 | return -ENOBUFS; |
| 9982 | pat_len = rule->patterns[j].pattern_len; |
| 9983 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9984 | DIV_ROUND_UP(pat_len, 8), |
| 9985 | rule->patterns[j].mask) || |
| 9986 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9987 | rule->patterns[j].pattern) || |
| 9988 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9989 | rule->patterns[j].pkt_offset)) |
| 9990 | return -ENOBUFS; |
| 9991 | nla_nest_end(msg, nl_pat); |
| 9992 | } |
| 9993 | nla_nest_end(msg, nl_pats); |
| 9994 | nla_nest_end(msg, nl_rule); |
| 9995 | } |
| 9996 | nla_nest_end(msg, nl_rules); |
| 9997 | |
| 9998 | return 0; |
| 9999 | } |
| 10000 | |
| 10001 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10002 | { |
| 10003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10004 | struct sk_buff *msg; |
| 10005 | void *hdr; |
| 10006 | |
| 10007 | if (!rdev->wiphy.coalesce) |
| 10008 | return -EOPNOTSUPP; |
| 10009 | |
| 10010 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10011 | if (!msg) |
| 10012 | return -ENOMEM; |
| 10013 | |
| 10014 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10015 | NL80211_CMD_GET_COALESCE); |
| 10016 | if (!hdr) |
| 10017 | goto nla_put_failure; |
| 10018 | |
| 10019 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10020 | goto nla_put_failure; |
| 10021 | |
| 10022 | genlmsg_end(msg, hdr); |
| 10023 | return genlmsg_reply(msg, info); |
| 10024 | |
| 10025 | nla_put_failure: |
| 10026 | nlmsg_free(msg); |
| 10027 | return -ENOBUFS; |
| 10028 | } |
| 10029 | |
| 10030 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10031 | { |
| 10032 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10033 | int i, j; |
| 10034 | struct cfg80211_coalesce_rules *rule; |
| 10035 | |
| 10036 | if (!coalesce) |
| 10037 | return; |
| 10038 | |
| 10039 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10040 | rule = &coalesce->rules[i]; |
| 10041 | for (j = 0; j < rule->n_patterns; j++) |
| 10042 | kfree(rule->patterns[j].mask); |
| 10043 | kfree(rule->patterns); |
| 10044 | } |
| 10045 | kfree(coalesce->rules); |
| 10046 | kfree(coalesce); |
| 10047 | rdev->coalesce = NULL; |
| 10048 | } |
| 10049 | |
| 10050 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10051 | struct nlattr *rule, |
| 10052 | struct cfg80211_coalesce_rules *new_rule) |
| 10053 | { |
| 10054 | int err, i; |
| 10055 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10056 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10057 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10058 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10059 | |
| 10060 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 10061 | nla_len(rule), nl80211_coalesce_policy); |
| 10062 | if (err) |
| 10063 | return err; |
| 10064 | |
| 10065 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10066 | new_rule->delay = |
| 10067 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10068 | if (new_rule->delay > coalesce->max_delay) |
| 10069 | return -EINVAL; |
| 10070 | |
| 10071 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10072 | new_rule->condition = |
| 10073 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10074 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10075 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10076 | return -EINVAL; |
| 10077 | |
| 10078 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10079 | return -EINVAL; |
| 10080 | |
| 10081 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10082 | rem) |
| 10083 | n_patterns++; |
| 10084 | if (n_patterns > coalesce->n_patterns) |
| 10085 | return -EINVAL; |
| 10086 | |
| 10087 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10088 | GFP_KERNEL); |
| 10089 | if (!new_rule->patterns) |
| 10090 | return -ENOMEM; |
| 10091 | |
| 10092 | new_rule->n_patterns = n_patterns; |
| 10093 | i = 0; |
| 10094 | |
| 10095 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10096 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10097 | u8 *mask_pat; |
| 10098 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10099 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 10100 | nla_len(pat), NULL); |
| 10101 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10102 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10103 | return -EINVAL; |
| 10104 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10105 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10106 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10107 | return -EINVAL; |
| 10108 | if (pat_len > coalesce->pattern_max_len || |
| 10109 | pat_len < coalesce->pattern_min_len) |
| 10110 | return -EINVAL; |
| 10111 | |
| 10112 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10113 | pkt_offset = 0; |
| 10114 | else |
| 10115 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10116 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10117 | return -EINVAL; |
| 10118 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10119 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10120 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10121 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10122 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10123 | |
| 10124 | new_rule->patterns[i].mask = mask_pat; |
| 10125 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10126 | mask_len); |
| 10127 | |
| 10128 | mask_pat += mask_len; |
| 10129 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10130 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10131 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10132 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10133 | i++; |
| 10134 | } |
| 10135 | |
| 10136 | return 0; |
| 10137 | } |
| 10138 | |
| 10139 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10140 | { |
| 10141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10142 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10143 | struct cfg80211_coalesce new_coalesce = {}; |
| 10144 | struct cfg80211_coalesce *n_coalesce; |
| 10145 | int err, rem_rule, n_rules = 0, i, j; |
| 10146 | struct nlattr *rule; |
| 10147 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10148 | |
| 10149 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10150 | return -EOPNOTSUPP; |
| 10151 | |
| 10152 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10153 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10154 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10155 | return 0; |
| 10156 | } |
| 10157 | |
| 10158 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10159 | rem_rule) |
| 10160 | n_rules++; |
| 10161 | if (n_rules > coalesce->n_rules) |
| 10162 | return -EINVAL; |
| 10163 | |
| 10164 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10165 | GFP_KERNEL); |
| 10166 | if (!new_coalesce.rules) |
| 10167 | return -ENOMEM; |
| 10168 | |
| 10169 | new_coalesce.n_rules = n_rules; |
| 10170 | i = 0; |
| 10171 | |
| 10172 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10173 | rem_rule) { |
| 10174 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10175 | &new_coalesce.rules[i]); |
| 10176 | if (err) |
| 10177 | goto error; |
| 10178 | |
| 10179 | i++; |
| 10180 | } |
| 10181 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10182 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10183 | if (err) |
| 10184 | goto error; |
| 10185 | |
| 10186 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10187 | if (!n_coalesce) { |
| 10188 | err = -ENOMEM; |
| 10189 | goto error; |
| 10190 | } |
| 10191 | cfg80211_rdev_free_coalesce(rdev); |
| 10192 | rdev->coalesce = n_coalesce; |
| 10193 | |
| 10194 | return 0; |
| 10195 | error: |
| 10196 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10197 | tmp_rule = &new_coalesce.rules[i]; |
| 10198 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10199 | kfree(tmp_rule->patterns[j].mask); |
| 10200 | kfree(tmp_rule->patterns); |
| 10201 | } |
| 10202 | kfree(new_coalesce.rules); |
| 10203 | |
| 10204 | return err; |
| 10205 | } |
| 10206 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10207 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10208 | { |
| 10209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10210 | struct net_device *dev = info->user_ptr[1]; |
| 10211 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10212 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10213 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10214 | int err; |
| 10215 | |
| 10216 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10217 | return -EINVAL; |
| 10218 | |
| 10219 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 10220 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10221 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10222 | nl80211_rekey_policy); |
| 10223 | if (err) |
| 10224 | return err; |
| 10225 | |
| 10226 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10227 | return -ERANGE; |
| 10228 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10229 | return -ERANGE; |
| 10230 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10231 | return -ERANGE; |
| 10232 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10233 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10234 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10235 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10236 | |
| 10237 | wdev_lock(wdev); |
| 10238 | if (!wdev->current_bss) { |
| 10239 | err = -ENOTCONN; |
| 10240 | goto out; |
| 10241 | } |
| 10242 | |
| 10243 | if (!rdev->ops->set_rekey_data) { |
| 10244 | err = -EOPNOTSUPP; |
| 10245 | goto out; |
| 10246 | } |
| 10247 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10248 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10249 | out: |
| 10250 | wdev_unlock(wdev); |
| 10251 | return err; |
| 10252 | } |
| 10253 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10254 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10255 | struct genl_info *info) |
| 10256 | { |
| 10257 | struct net_device *dev = info->user_ptr[1]; |
| 10258 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10259 | |
| 10260 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10261 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10262 | return -EINVAL; |
| 10263 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10264 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10265 | return -EBUSY; |
| 10266 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10267 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10268 | return 0; |
| 10269 | } |
| 10270 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10271 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10272 | struct genl_info *info) |
| 10273 | { |
| 10274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10275 | struct net_device *dev = info->user_ptr[1]; |
| 10276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10277 | struct sk_buff *msg; |
| 10278 | void *hdr; |
| 10279 | const u8 *addr; |
| 10280 | u64 cookie; |
| 10281 | int err; |
| 10282 | |
| 10283 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10284 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10285 | return -EOPNOTSUPP; |
| 10286 | |
| 10287 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10288 | return -EINVAL; |
| 10289 | |
| 10290 | if (!rdev->ops->probe_client) |
| 10291 | return -EOPNOTSUPP; |
| 10292 | |
| 10293 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10294 | if (!msg) |
| 10295 | return -ENOMEM; |
| 10296 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10297 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10298 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10299 | if (!hdr) { |
| 10300 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10301 | goto free_msg; |
| 10302 | } |
| 10303 | |
| 10304 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10305 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10306 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10307 | if (err) |
| 10308 | goto free_msg; |
| 10309 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10310 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10311 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10312 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10313 | |
| 10314 | genlmsg_end(msg, hdr); |
| 10315 | |
| 10316 | return genlmsg_reply(msg, info); |
| 10317 | |
| 10318 | nla_put_failure: |
| 10319 | err = -ENOBUFS; |
| 10320 | free_msg: |
| 10321 | nlmsg_free(msg); |
| 10322 | return err; |
| 10323 | } |
| 10324 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10325 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10326 | { |
| 10327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10328 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10329 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10330 | |
| 10331 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10332 | return -EOPNOTSUPP; |
| 10333 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10334 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10335 | if (!nreg) |
| 10336 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10337 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10338 | /* First, check if already registered. */ |
| 10339 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10340 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10341 | if (reg->nlportid == info->snd_portid) { |
| 10342 | rv = -EALREADY; |
| 10343 | goto out_err; |
| 10344 | } |
| 10345 | } |
| 10346 | /* Add it to the list */ |
| 10347 | nreg->nlportid = info->snd_portid; |
| 10348 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10349 | |
| 10350 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10351 | |
| 10352 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10353 | out_err: |
| 10354 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10355 | kfree(nreg); |
| 10356 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10357 | } |
| 10358 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10359 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10360 | { |
| 10361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10362 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10363 | int err; |
| 10364 | |
| 10365 | if (!rdev->ops->start_p2p_device) |
| 10366 | return -EOPNOTSUPP; |
| 10367 | |
| 10368 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10369 | return -EOPNOTSUPP; |
| 10370 | |
| 10371 | if (wdev->p2p_started) |
| 10372 | return 0; |
| 10373 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10374 | if (rfkill_blocked(rdev->rfkill)) |
| 10375 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10376 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10377 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10378 | if (err) |
| 10379 | return err; |
| 10380 | |
| 10381 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10382 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10383 | |
| 10384 | return 0; |
| 10385 | } |
| 10386 | |
| 10387 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10388 | { |
| 10389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10390 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10391 | |
| 10392 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10393 | return -EOPNOTSUPP; |
| 10394 | |
| 10395 | if (!rdev->ops->stop_p2p_device) |
| 10396 | return -EOPNOTSUPP; |
| 10397 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10398 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10399 | |
| 10400 | return 0; |
| 10401 | } |
| 10402 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10403 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 10404 | struct genl_info *info) |
| 10405 | { |
| 10406 | void *hdr; |
| 10407 | struct sk_buff *msg; |
| 10408 | |
| 10409 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10410 | if (!msg) |
| 10411 | return -ENOMEM; |
| 10412 | |
| 10413 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10414 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 10415 | if (!hdr) |
| 10416 | goto nla_put_failure; |
| 10417 | |
| 10418 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 10419 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 10420 | goto nla_put_failure; |
| 10421 | |
| 10422 | genlmsg_end(msg, hdr); |
| 10423 | return genlmsg_reply(msg, info); |
| 10424 | |
| 10425 | nla_put_failure: |
| 10426 | kfree_skb(msg); |
| 10427 | return -ENOBUFS; |
| 10428 | } |
| 10429 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10430 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 10431 | { |
| 10432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10433 | struct cfg80211_update_ft_ies_params ft_params; |
| 10434 | struct net_device *dev = info->user_ptr[1]; |
| 10435 | |
| 10436 | if (!rdev->ops->update_ft_ies) |
| 10437 | return -EOPNOTSUPP; |
| 10438 | |
| 10439 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 10440 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 10441 | return -EINVAL; |
| 10442 | |
| 10443 | memset(&ft_params, 0, sizeof(ft_params)); |
| 10444 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 10445 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10446 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10447 | |
| 10448 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 10449 | } |
| 10450 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10451 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 10452 | struct genl_info *info) |
| 10453 | { |
| 10454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10455 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10456 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 10457 | u16 duration; |
| 10458 | int ret; |
| 10459 | |
| 10460 | if (!rdev->ops->crit_proto_start) |
| 10461 | return -EOPNOTSUPP; |
| 10462 | |
| 10463 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 10464 | return -EINVAL; |
| 10465 | |
| 10466 | if (rdev->crit_proto_nlportid) |
| 10467 | return -EBUSY; |
| 10468 | |
| 10469 | /* determine protocol if provided */ |
| 10470 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 10471 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 10472 | |
| 10473 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 10474 | return -EINVAL; |
| 10475 | |
| 10476 | /* timeout must be provided */ |
| 10477 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 10478 | return -EINVAL; |
| 10479 | |
| 10480 | duration = |
| 10481 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 10482 | |
| 10483 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 10484 | return -ERANGE; |
| 10485 | |
| 10486 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 10487 | if (!ret) |
| 10488 | rdev->crit_proto_nlportid = info->snd_portid; |
| 10489 | |
| 10490 | return ret; |
| 10491 | } |
| 10492 | |
| 10493 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 10494 | struct genl_info *info) |
| 10495 | { |
| 10496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10497 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10498 | |
| 10499 | if (!rdev->ops->crit_proto_stop) |
| 10500 | return -EOPNOTSUPP; |
| 10501 | |
| 10502 | if (rdev->crit_proto_nlportid) { |
| 10503 | rdev->crit_proto_nlportid = 0; |
| 10504 | rdev_crit_proto_stop(rdev, wdev); |
| 10505 | } |
| 10506 | return 0; |
| 10507 | } |
| 10508 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10509 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 10510 | { |
| 10511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10512 | struct wireless_dev *wdev = |
| 10513 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10514 | int i, err; |
| 10515 | u32 vid, subcmd; |
| 10516 | |
| 10517 | if (!rdev->wiphy.vendor_commands) |
| 10518 | return -EOPNOTSUPP; |
| 10519 | |
| 10520 | if (IS_ERR(wdev)) { |
| 10521 | err = PTR_ERR(wdev); |
| 10522 | if (err != -EINVAL) |
| 10523 | return err; |
| 10524 | wdev = NULL; |
| 10525 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10526 | return -EINVAL; |
| 10527 | } |
| 10528 | |
| 10529 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 10530 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 10531 | return -EINVAL; |
| 10532 | |
| 10533 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 10534 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10535 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 10536 | const struct wiphy_vendor_command *vcmd; |
| 10537 | void *data = NULL; |
| 10538 | int len = 0; |
| 10539 | |
| 10540 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 10541 | |
| 10542 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10543 | continue; |
| 10544 | |
| 10545 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10546 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10547 | if (!wdev) |
| 10548 | return -EINVAL; |
| 10549 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10550 | !wdev->netdev) |
| 10551 | return -EINVAL; |
| 10552 | |
| 10553 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10554 | if (wdev->netdev && |
| 10555 | !netif_running(wdev->netdev)) |
| 10556 | return -ENETDOWN; |
| 10557 | if (!wdev->netdev && !wdev->p2p_started) |
| 10558 | return -ENETDOWN; |
| 10559 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10560 | |
| 10561 | if (!vcmd->doit) |
| 10562 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10563 | } else { |
| 10564 | wdev = NULL; |
| 10565 | } |
| 10566 | |
| 10567 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 10568 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10569 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10570 | } |
| 10571 | |
| 10572 | rdev->cur_cmd_info = info; |
| 10573 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 10574 | data, len); |
| 10575 | rdev->cur_cmd_info = NULL; |
| 10576 | return err; |
| 10577 | } |
| 10578 | |
| 10579 | return -EOPNOTSUPP; |
| 10580 | } |
| 10581 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10582 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 10583 | struct netlink_callback *cb, |
| 10584 | struct cfg80211_registered_device **rdev, |
| 10585 | struct wireless_dev **wdev) |
| 10586 | { |
| 10587 | u32 vid, subcmd; |
| 10588 | unsigned int i; |
| 10589 | int vcmd_idx = -1; |
| 10590 | int err; |
| 10591 | void *data = NULL; |
| 10592 | unsigned int data_len = 0; |
| 10593 | |
| 10594 | rtnl_lock(); |
| 10595 | |
| 10596 | if (cb->args[0]) { |
| 10597 | /* subtract the 1 again here */ |
| 10598 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 10599 | struct wireless_dev *tmp; |
| 10600 | |
| 10601 | if (!wiphy) { |
| 10602 | err = -ENODEV; |
| 10603 | goto out_unlock; |
| 10604 | } |
| 10605 | *rdev = wiphy_to_rdev(wiphy); |
| 10606 | *wdev = NULL; |
| 10607 | |
| 10608 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 10609 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10610 | if (tmp->identifier == cb->args[1] - 1) { |
| 10611 | *wdev = tmp; |
| 10612 | break; |
| 10613 | } |
| 10614 | } |
| 10615 | } |
| 10616 | |
| 10617 | /* keep rtnl locked in successful case */ |
| 10618 | return 0; |
| 10619 | } |
| 10620 | |
| 10621 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10622 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 10623 | nl80211_policy); |
| 10624 | if (err) |
| 10625 | goto out_unlock; |
| 10626 | |
| 10627 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 10628 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 10629 | err = -EINVAL; |
| 10630 | goto out_unlock; |
| 10631 | } |
| 10632 | |
| 10633 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 10634 | nl80211_fam.attrbuf); |
| 10635 | if (IS_ERR(*wdev)) |
| 10636 | *wdev = NULL; |
| 10637 | |
| 10638 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 10639 | nl80211_fam.attrbuf); |
| 10640 | if (IS_ERR(*rdev)) { |
| 10641 | err = PTR_ERR(*rdev); |
| 10642 | goto out_unlock; |
| 10643 | } |
| 10644 | |
| 10645 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 10646 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10647 | |
| 10648 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 10649 | const struct wiphy_vendor_command *vcmd; |
| 10650 | |
| 10651 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 10652 | |
| 10653 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10654 | continue; |
| 10655 | |
| 10656 | if (!vcmd->dumpit) { |
| 10657 | err = -EOPNOTSUPP; |
| 10658 | goto out_unlock; |
| 10659 | } |
| 10660 | |
| 10661 | vcmd_idx = i; |
| 10662 | break; |
| 10663 | } |
| 10664 | |
| 10665 | if (vcmd_idx < 0) { |
| 10666 | err = -EOPNOTSUPP; |
| 10667 | goto out_unlock; |
| 10668 | } |
| 10669 | |
| 10670 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 10671 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10672 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10673 | } |
| 10674 | |
| 10675 | /* 0 is the first index - add 1 to parse only once */ |
| 10676 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 10677 | /* add 1 to know if it was NULL */ |
| 10678 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 10679 | cb->args[2] = vcmd_idx; |
| 10680 | cb->args[3] = (unsigned long)data; |
| 10681 | cb->args[4] = data_len; |
| 10682 | |
| 10683 | /* keep rtnl locked in successful case */ |
| 10684 | return 0; |
| 10685 | out_unlock: |
| 10686 | rtnl_unlock(); |
| 10687 | return err; |
| 10688 | } |
| 10689 | |
| 10690 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 10691 | struct netlink_callback *cb) |
| 10692 | { |
| 10693 | struct cfg80211_registered_device *rdev; |
| 10694 | struct wireless_dev *wdev; |
| 10695 | unsigned int vcmd_idx; |
| 10696 | const struct wiphy_vendor_command *vcmd; |
| 10697 | void *data; |
| 10698 | int data_len; |
| 10699 | int err; |
| 10700 | struct nlattr *vendor_data; |
| 10701 | |
| 10702 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 10703 | if (err) |
| 10704 | return err; |
| 10705 | |
| 10706 | vcmd_idx = cb->args[2]; |
| 10707 | data = (void *)cb->args[3]; |
| 10708 | data_len = cb->args[4]; |
| 10709 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 10710 | |
| 10711 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10712 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10713 | if (!wdev) |
| 10714 | return -EINVAL; |
| 10715 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10716 | !wdev->netdev) |
| 10717 | return -EINVAL; |
| 10718 | |
| 10719 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10720 | if (wdev->netdev && |
| 10721 | !netif_running(wdev->netdev)) |
| 10722 | return -ENETDOWN; |
| 10723 | if (!wdev->netdev && !wdev->p2p_started) |
| 10724 | return -ENETDOWN; |
| 10725 | } |
| 10726 | } |
| 10727 | |
| 10728 | while (1) { |
| 10729 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10730 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10731 | NL80211_CMD_VENDOR); |
| 10732 | if (!hdr) |
| 10733 | break; |
| 10734 | |
| 10735 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10736 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10737 | wdev_id(wdev), |
| 10738 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10739 | genlmsg_cancel(skb, hdr); |
| 10740 | break; |
| 10741 | } |
| 10742 | |
| 10743 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 10744 | if (!vendor_data) { |
| 10745 | genlmsg_cancel(skb, hdr); |
| 10746 | break; |
| 10747 | } |
| 10748 | |
| 10749 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 10750 | (unsigned long *)&cb->args[5]); |
| 10751 | nla_nest_end(skb, vendor_data); |
| 10752 | |
| 10753 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10754 | genlmsg_cancel(skb, hdr); |
| 10755 | break; |
| 10756 | } else if (err) { |
| 10757 | genlmsg_cancel(skb, hdr); |
| 10758 | goto out; |
| 10759 | } |
| 10760 | |
| 10761 | genlmsg_end(skb, hdr); |
| 10762 | } |
| 10763 | |
| 10764 | err = skb->len; |
| 10765 | out: |
| 10766 | rtnl_unlock(); |
| 10767 | return err; |
| 10768 | } |
| 10769 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10770 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 10771 | enum nl80211_commands cmd, |
| 10772 | enum nl80211_attrs attr, |
| 10773 | int approxlen) |
| 10774 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10775 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10776 | |
| 10777 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 10778 | return NULL; |
| 10779 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10780 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10781 | rdev->cur_cmd_info->snd_portid, |
| 10782 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10783 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10784 | } |
| 10785 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 10786 | |
| 10787 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 10788 | { |
| 10789 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10790 | void *hdr = ((void **)skb->cb)[1]; |
| 10791 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10792 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10793 | /* clear CB data for netlink core to own from now on */ |
| 10794 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10795 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10796 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 10797 | kfree_skb(skb); |
| 10798 | return -EINVAL; |
| 10799 | } |
| 10800 | |
| 10801 | nla_nest_end(skb, data); |
| 10802 | genlmsg_end(skb, hdr); |
| 10803 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 10804 | } |
| 10805 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 10806 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10807 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 10808 | struct genl_info *info) |
| 10809 | { |
| 10810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10811 | struct cfg80211_qos_map *qos_map = NULL; |
| 10812 | struct net_device *dev = info->user_ptr[1]; |
| 10813 | u8 *pos, len, num_des, des_len, des; |
| 10814 | int ret; |
| 10815 | |
| 10816 | if (!rdev->ops->set_qos_map) |
| 10817 | return -EOPNOTSUPP; |
| 10818 | |
| 10819 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10820 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10821 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10822 | |
| 10823 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10824 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10825 | return -EINVAL; |
| 10826 | |
| 10827 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10828 | if (!qos_map) |
| 10829 | return -ENOMEM; |
| 10830 | |
| 10831 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10832 | if (num_des) { |
| 10833 | des_len = num_des * |
| 10834 | sizeof(struct cfg80211_dscp_exception); |
| 10835 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10836 | qos_map->num_des = num_des; |
| 10837 | for (des = 0; des < num_des; des++) { |
| 10838 | if (qos_map->dscp_exception[des].up > 7) { |
| 10839 | kfree(qos_map); |
| 10840 | return -EINVAL; |
| 10841 | } |
| 10842 | } |
| 10843 | pos += des_len; |
| 10844 | } |
| 10845 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10846 | } |
| 10847 | |
| 10848 | wdev_lock(dev->ieee80211_ptr); |
| 10849 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10850 | if (!ret) |
| 10851 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10852 | wdev_unlock(dev->ieee80211_ptr); |
| 10853 | |
| 10854 | kfree(qos_map); |
| 10855 | return ret; |
| 10856 | } |
| 10857 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10858 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10859 | { |
| 10860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10861 | struct net_device *dev = info->user_ptr[1]; |
| 10862 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10863 | const u8 *peer; |
| 10864 | u8 tsid, up; |
| 10865 | u16 admitted_time = 0; |
| 10866 | int err; |
| 10867 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10868 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10869 | return -EOPNOTSUPP; |
| 10870 | |
| 10871 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10872 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10873 | return -EINVAL; |
| 10874 | |
| 10875 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10876 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10877 | return -EINVAL; |
| 10878 | |
| 10879 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10880 | if (up >= IEEE80211_NUM_UPS) |
| 10881 | return -EINVAL; |
| 10882 | |
| 10883 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10884 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10885 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10886 | * need more attributes for that (e.g. BA session requirement); |
| 10887 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10888 | */ |
| 10889 | return -EINVAL; |
| 10890 | } |
| 10891 | |
| 10892 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10893 | |
| 10894 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10895 | admitted_time = |
| 10896 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10897 | if (!admitted_time) |
| 10898 | return -EINVAL; |
| 10899 | } |
| 10900 | |
| 10901 | wdev_lock(wdev); |
| 10902 | switch (wdev->iftype) { |
| 10903 | case NL80211_IFTYPE_STATION: |
| 10904 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10905 | if (wdev->current_bss) |
| 10906 | break; |
| 10907 | err = -ENOTCONN; |
| 10908 | goto out; |
| 10909 | default: |
| 10910 | err = -EOPNOTSUPP; |
| 10911 | goto out; |
| 10912 | } |
| 10913 | |
| 10914 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10915 | |
| 10916 | out: |
| 10917 | wdev_unlock(wdev); |
| 10918 | return err; |
| 10919 | } |
| 10920 | |
| 10921 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10922 | { |
| 10923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10924 | struct net_device *dev = info->user_ptr[1]; |
| 10925 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10926 | const u8 *peer; |
| 10927 | u8 tsid; |
| 10928 | int err; |
| 10929 | |
| 10930 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10931 | return -EINVAL; |
| 10932 | |
| 10933 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10934 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10935 | |
| 10936 | wdev_lock(wdev); |
| 10937 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10938 | wdev_unlock(wdev); |
| 10939 | |
| 10940 | return err; |
| 10941 | } |
| 10942 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10943 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10944 | struct genl_info *info) |
| 10945 | { |
| 10946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10947 | struct net_device *dev = info->user_ptr[1]; |
| 10948 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10949 | struct cfg80211_chan_def chandef = {}; |
| 10950 | const u8 *addr; |
| 10951 | u8 oper_class; |
| 10952 | int err; |
| 10953 | |
| 10954 | if (!rdev->ops->tdls_channel_switch || |
| 10955 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10956 | return -EOPNOTSUPP; |
| 10957 | |
| 10958 | switch (dev->ieee80211_ptr->iftype) { |
| 10959 | case NL80211_IFTYPE_STATION: |
| 10960 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10961 | break; |
| 10962 | default: |
| 10963 | return -EOPNOTSUPP; |
| 10964 | } |
| 10965 | |
| 10966 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10967 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10968 | return -EINVAL; |
| 10969 | |
| 10970 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10971 | if (err) |
| 10972 | return err; |
| 10973 | |
| 10974 | /* |
| 10975 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10976 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10977 | * specification is not defined for them. |
| 10978 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10979 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10980 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10981 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10982 | return -EINVAL; |
| 10983 | |
| 10984 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10985 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10986 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10987 | return -EINVAL; |
| 10988 | |
| 10989 | /* don't allow switching to DFS channels */ |
| 10990 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10991 | return -EINVAL; |
| 10992 | |
| 10993 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10994 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10995 | |
| 10996 | wdev_lock(wdev); |
| 10997 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10998 | wdev_unlock(wdev); |
| 10999 | |
| 11000 | return err; |
| 11001 | } |
| 11002 | |
| 11003 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 11004 | struct genl_info *info) |
| 11005 | { |
| 11006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11007 | struct net_device *dev = info->user_ptr[1]; |
| 11008 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11009 | const u8 *addr; |
| 11010 | |
| 11011 | if (!rdev->ops->tdls_channel_switch || |
| 11012 | !rdev->ops->tdls_cancel_channel_switch || |
| 11013 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11014 | return -EOPNOTSUPP; |
| 11015 | |
| 11016 | switch (dev->ieee80211_ptr->iftype) { |
| 11017 | case NL80211_IFTYPE_STATION: |
| 11018 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11019 | break; |
| 11020 | default: |
| 11021 | return -EOPNOTSUPP; |
| 11022 | } |
| 11023 | |
| 11024 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11025 | return -EINVAL; |
| 11026 | |
| 11027 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11028 | |
| 11029 | wdev_lock(wdev); |
| 11030 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 11031 | wdev_unlock(wdev); |
| 11032 | |
| 11033 | return 0; |
| 11034 | } |
| 11035 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11036 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 11037 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 11038 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11039 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 11040 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 11041 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11042 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11043 | /* 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] | 11044 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 11045 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11046 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11047 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11048 | 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] | 11049 | struct genl_info *info) |
| 11050 | { |
| 11051 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11052 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11053 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11054 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 11055 | |
| 11056 | if (rtnl) |
| 11057 | rtnl_lock(); |
| 11058 | |
| 11059 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 11060 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11061 | if (IS_ERR(rdev)) { |
| 11062 | if (rtnl) |
| 11063 | rtnl_unlock(); |
| 11064 | return PTR_ERR(rdev); |
| 11065 | } |
| 11066 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11067 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 11068 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11069 | ASSERT_RTNL(); |
| 11070 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11071 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 11072 | info->attrs); |
| 11073 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11074 | if (rtnl) |
| 11075 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11076 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11077 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11078 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11079 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11080 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11081 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11082 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 11083 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11084 | if (rtnl) |
| 11085 | rtnl_unlock(); |
| 11086 | return -EINVAL; |
| 11087 | } |
| 11088 | |
| 11089 | info->user_ptr[1] = dev; |
| 11090 | } else { |
| 11091 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11092 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11093 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11094 | if (dev) { |
| 11095 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 11096 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11097 | if (rtnl) |
| 11098 | rtnl_unlock(); |
| 11099 | return -ENETDOWN; |
| 11100 | } |
| 11101 | |
| 11102 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11103 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 11104 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11105 | if (rtnl) |
| 11106 | rtnl_unlock(); |
| 11107 | return -ENETDOWN; |
| 11108 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11109 | } |
| 11110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11111 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11112 | } |
| 11113 | |
| 11114 | return 0; |
| 11115 | } |
| 11116 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11117 | 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] | 11118 | struct genl_info *info) |
| 11119 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11120 | if (info->user_ptr[1]) { |
| 11121 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 11122 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11123 | |
| 11124 | if (wdev->netdev) |
| 11125 | dev_put(wdev->netdev); |
| 11126 | } else { |
| 11127 | dev_put(info->user_ptr[1]); |
| 11128 | } |
| 11129 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11131 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 11132 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11133 | |
| 11134 | /* If needed, clear the netlink message payload from the SKB |
| 11135 | * as it might contain key data that shouldn't stick around on |
| 11136 | * the heap after the SKB is freed. The netlink message header |
| 11137 | * is still needed for further processing, so leave it intact. |
| 11138 | */ |
| 11139 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 11140 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 11141 | |
| 11142 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 11143 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11144 | } |
| 11145 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 11146 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11147 | { |
| 11148 | .cmd = NL80211_CMD_GET_WIPHY, |
| 11149 | .doit = nl80211_get_wiphy, |
| 11150 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11151 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11152 | .policy = nl80211_policy, |
| 11153 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11154 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11155 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11156 | }, |
| 11157 | { |
| 11158 | .cmd = NL80211_CMD_SET_WIPHY, |
| 11159 | .doit = nl80211_set_wiphy, |
| 11160 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11161 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11162 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11163 | }, |
| 11164 | { |
| 11165 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 11166 | .doit = nl80211_get_interface, |
| 11167 | .dumpit = nl80211_dump_interface, |
| 11168 | .policy = nl80211_policy, |
| 11169 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11170 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11171 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11172 | }, |
| 11173 | { |
| 11174 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 11175 | .doit = nl80211_set_interface, |
| 11176 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11177 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11178 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11179 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11180 | }, |
| 11181 | { |
| 11182 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 11183 | .doit = nl80211_new_interface, |
| 11184 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11185 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11186 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11187 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11188 | }, |
| 11189 | { |
| 11190 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 11191 | .doit = nl80211_del_interface, |
| 11192 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11193 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 11194 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11195 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11196 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11197 | { |
| 11198 | .cmd = NL80211_CMD_GET_KEY, |
| 11199 | .doit = nl80211_get_key, |
| 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 | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11204 | }, |
| 11205 | { |
| 11206 | .cmd = NL80211_CMD_SET_KEY, |
| 11207 | .doit = nl80211_set_key, |
| 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 | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11211 | NL80211_FLAG_NEED_RTNL | |
| 11212 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11213 | }, |
| 11214 | { |
| 11215 | .cmd = NL80211_CMD_NEW_KEY, |
| 11216 | .doit = nl80211_new_key, |
| 11217 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11218 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11220 | NL80211_FLAG_NEED_RTNL | |
| 11221 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11222 | }, |
| 11223 | { |
| 11224 | .cmd = NL80211_CMD_DEL_KEY, |
| 11225 | .doit = nl80211_del_key, |
| 11226 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11227 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11228 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11229 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11230 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11231 | { |
| 11232 | .cmd = NL80211_CMD_SET_BEACON, |
| 11233 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11234 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11235 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11237 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11238 | }, |
| 11239 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11240 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11241 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11242 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11243 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11246 | }, |
| 11247 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11248 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11249 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11250 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11251 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11254 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11255 | { |
| 11256 | .cmd = NL80211_CMD_GET_STATION, |
| 11257 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11258 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11259 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11260 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11261 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11262 | }, |
| 11263 | { |
| 11264 | .cmd = NL80211_CMD_SET_STATION, |
| 11265 | .doit = nl80211_set_station, |
| 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, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11270 | }, |
| 11271 | { |
| 11272 | .cmd = NL80211_CMD_NEW_STATION, |
| 11273 | .doit = nl80211_new_station, |
| 11274 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11275 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11276 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11277 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11278 | }, |
| 11279 | { |
| 11280 | .cmd = NL80211_CMD_DEL_STATION, |
| 11281 | .doit = nl80211_del_station, |
| 11282 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11283 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11284 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11285 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11286 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11287 | { |
| 11288 | .cmd = NL80211_CMD_GET_MPATH, |
| 11289 | .doit = nl80211_get_mpath, |
| 11290 | .dumpit = nl80211_dump_mpath, |
| 11291 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11292 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11293 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11294 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11295 | }, |
| 11296 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11297 | .cmd = NL80211_CMD_GET_MPP, |
| 11298 | .doit = nl80211_get_mpp, |
| 11299 | .dumpit = nl80211_dump_mpp, |
| 11300 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11301 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11302 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11303 | NL80211_FLAG_NEED_RTNL, |
| 11304 | }, |
| 11305 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11306 | .cmd = NL80211_CMD_SET_MPATH, |
| 11307 | .doit = nl80211_set_mpath, |
| 11308 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11309 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11310 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11311 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11312 | }, |
| 11313 | { |
| 11314 | .cmd = NL80211_CMD_NEW_MPATH, |
| 11315 | .doit = nl80211_new_mpath, |
| 11316 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11317 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11318 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11319 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11320 | }, |
| 11321 | { |
| 11322 | .cmd = NL80211_CMD_DEL_MPATH, |
| 11323 | .doit = nl80211_del_mpath, |
| 11324 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11325 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11326 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11327 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11328 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11329 | { |
| 11330 | .cmd = NL80211_CMD_SET_BSS, |
| 11331 | .doit = nl80211_set_bss, |
| 11332 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11333 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11334 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11335 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11336 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11337 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11338 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11339 | .doit = nl80211_get_reg_do, |
| 11340 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11341 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11342 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11343 | /* can be retrieved by unprivileged users */ |
| 11344 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11345 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11346 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11347 | .cmd = NL80211_CMD_SET_REG, |
| 11348 | .doit = nl80211_set_reg, |
| 11349 | .policy = nl80211_policy, |
| 11350 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11351 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11352 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11353 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11354 | { |
| 11355 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 11356 | .doit = nl80211_req_set_reg, |
| 11357 | .policy = nl80211_policy, |
| 11358 | .flags = GENL_ADMIN_PERM, |
| 11359 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11360 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11361 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 11362 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11363 | .policy = nl80211_policy, |
| 11364 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11366 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11367 | }, |
| 11368 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11369 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 11370 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11371 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11372 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11374 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11375 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 11376 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11377 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 11378 | .doit = nl80211_trigger_scan, |
| 11379 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11380 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11381 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11382 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11383 | }, |
| 11384 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11385 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 11386 | .doit = nl80211_abort_scan, |
| 11387 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11388 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11389 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11390 | NL80211_FLAG_NEED_RTNL, |
| 11391 | }, |
| 11392 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11393 | .cmd = NL80211_CMD_GET_SCAN, |
| 11394 | .policy = nl80211_policy, |
| 11395 | .dumpit = nl80211_dump_scan, |
| 11396 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11397 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11398 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 11399 | .doit = nl80211_start_sched_scan, |
| 11400 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11401 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11403 | NL80211_FLAG_NEED_RTNL, |
| 11404 | }, |
| 11405 | { |
| 11406 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 11407 | .doit = nl80211_stop_sched_scan, |
| 11408 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11409 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11411 | NL80211_FLAG_NEED_RTNL, |
| 11412 | }, |
| 11413 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11414 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 11415 | .doit = nl80211_authenticate, |
| 11416 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11417 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11419 | NL80211_FLAG_NEED_RTNL | |
| 11420 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11421 | }, |
| 11422 | { |
| 11423 | .cmd = NL80211_CMD_ASSOCIATE, |
| 11424 | .doit = nl80211_associate, |
| 11425 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11426 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11428 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11429 | }, |
| 11430 | { |
| 11431 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 11432 | .doit = nl80211_deauthenticate, |
| 11433 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11434 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11436 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11437 | }, |
| 11438 | { |
| 11439 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 11440 | .doit = nl80211_disassociate, |
| 11441 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11442 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11444 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11445 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11446 | { |
| 11447 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 11448 | .doit = nl80211_join_ibss, |
| 11449 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11450 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11453 | }, |
| 11454 | { |
| 11455 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 11456 | .doit = nl80211_leave_ibss, |
| 11457 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11458 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11460 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11461 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11462 | #ifdef CONFIG_NL80211_TESTMODE |
| 11463 | { |
| 11464 | .cmd = NL80211_CMD_TESTMODE, |
| 11465 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 11466 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11467 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11468 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11469 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11470 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11471 | }, |
| 11472 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11473 | { |
| 11474 | .cmd = NL80211_CMD_CONNECT, |
| 11475 | .doit = nl80211_connect, |
| 11476 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11477 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11479 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11480 | }, |
| 11481 | { |
| 11482 | .cmd = NL80211_CMD_DISCONNECT, |
| 11483 | .doit = nl80211_disconnect, |
| 11484 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11485 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11486 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11487 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11488 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11489 | { |
| 11490 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 11491 | .doit = nl80211_wiphy_netns, |
| 11492 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11493 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11494 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11495 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11496 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 11497 | { |
| 11498 | .cmd = NL80211_CMD_GET_SURVEY, |
| 11499 | .policy = nl80211_policy, |
| 11500 | .dumpit = nl80211_dump_survey, |
| 11501 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11502 | { |
| 11503 | .cmd = NL80211_CMD_SET_PMKSA, |
| 11504 | .doit = nl80211_setdel_pmksa, |
| 11505 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11506 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11508 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11509 | }, |
| 11510 | { |
| 11511 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 11512 | .doit = nl80211_setdel_pmksa, |
| 11513 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11514 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11516 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11517 | }, |
| 11518 | { |
| 11519 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 11520 | .doit = nl80211_flush_pmksa, |
| 11521 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11522 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11524 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11525 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11526 | { |
| 11527 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 11528 | .doit = nl80211_remain_on_channel, |
| 11529 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11530 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11531 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11533 | }, |
| 11534 | { |
| 11535 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 11536 | .doit = nl80211_cancel_remain_on_channel, |
| 11537 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11538 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11539 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11540 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11541 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11542 | { |
| 11543 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 11544 | .doit = nl80211_set_tx_bitrate_mask, |
| 11545 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11546 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11547 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11548 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11549 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11550 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11551 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 11552 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11553 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11554 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11555 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11556 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11557 | }, |
| 11558 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11559 | .cmd = NL80211_CMD_FRAME, |
| 11560 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11561 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11562 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11563 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11564 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11565 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11566 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11567 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 11568 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 11569 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11570 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11571 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11572 | NL80211_FLAG_NEED_RTNL, |
| 11573 | }, |
| 11574 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11575 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 11576 | .doit = nl80211_set_power_save, |
| 11577 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11578 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11579 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11580 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11581 | }, |
| 11582 | { |
| 11583 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 11584 | .doit = nl80211_get_power_save, |
| 11585 | .policy = nl80211_policy, |
| 11586 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11587 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11588 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11589 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11590 | { |
| 11591 | .cmd = NL80211_CMD_SET_CQM, |
| 11592 | .doit = nl80211_set_cqm, |
| 11593 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11594 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11595 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11596 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11597 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11598 | { |
| 11599 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 11600 | .doit = nl80211_set_channel, |
| 11601 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11602 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11603 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11604 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11605 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11606 | { |
| 11607 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 11608 | .doit = nl80211_set_wds_peer, |
| 11609 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11610 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 11611 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11612 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11613 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11614 | { |
| 11615 | .cmd = NL80211_CMD_JOIN_MESH, |
| 11616 | .doit = nl80211_join_mesh, |
| 11617 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11618 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11620 | NL80211_FLAG_NEED_RTNL, |
| 11621 | }, |
| 11622 | { |
| 11623 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 11624 | .doit = nl80211_leave_mesh, |
| 11625 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11626 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11627 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11628 | NL80211_FLAG_NEED_RTNL, |
| 11629 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11630 | { |
| 11631 | .cmd = NL80211_CMD_JOIN_OCB, |
| 11632 | .doit = nl80211_join_ocb, |
| 11633 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11634 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11635 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11636 | NL80211_FLAG_NEED_RTNL, |
| 11637 | }, |
| 11638 | { |
| 11639 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 11640 | .doit = nl80211_leave_ocb, |
| 11641 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11642 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11643 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11644 | NL80211_FLAG_NEED_RTNL, |
| 11645 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11646 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11647 | { |
| 11648 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 11649 | .doit = nl80211_get_wowlan, |
| 11650 | .policy = nl80211_policy, |
| 11651 | /* can be retrieved by unprivileged users */ |
| 11652 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11653 | NL80211_FLAG_NEED_RTNL, |
| 11654 | }, |
| 11655 | { |
| 11656 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 11657 | .doit = nl80211_set_wowlan, |
| 11658 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11659 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11660 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11661 | NL80211_FLAG_NEED_RTNL, |
| 11662 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11663 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11664 | { |
| 11665 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 11666 | .doit = nl80211_set_rekey_data, |
| 11667 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11668 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11670 | NL80211_FLAG_NEED_RTNL | |
| 11671 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11672 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11673 | { |
| 11674 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 11675 | .doit = nl80211_tdls_mgmt, |
| 11676 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11677 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11679 | NL80211_FLAG_NEED_RTNL, |
| 11680 | }, |
| 11681 | { |
| 11682 | .cmd = NL80211_CMD_TDLS_OPER, |
| 11683 | .doit = nl80211_tdls_oper, |
| 11684 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11685 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11687 | NL80211_FLAG_NEED_RTNL, |
| 11688 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11689 | { |
| 11690 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 11691 | .doit = nl80211_register_unexpected_frame, |
| 11692 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11693 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11694 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11695 | NL80211_FLAG_NEED_RTNL, |
| 11696 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11697 | { |
| 11698 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 11699 | .doit = nl80211_probe_client, |
| 11700 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11701 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11703 | NL80211_FLAG_NEED_RTNL, |
| 11704 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11705 | { |
| 11706 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 11707 | .doit = nl80211_register_beacons, |
| 11708 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11709 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11710 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11711 | NL80211_FLAG_NEED_RTNL, |
| 11712 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11713 | { |
| 11714 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 11715 | .doit = nl80211_set_noack_map, |
| 11716 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11717 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11718 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11719 | NL80211_FLAG_NEED_RTNL, |
| 11720 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11721 | { |
| 11722 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 11723 | .doit = nl80211_start_p2p_device, |
| 11724 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11725 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11726 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11727 | NL80211_FLAG_NEED_RTNL, |
| 11728 | }, |
| 11729 | { |
| 11730 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 11731 | .doit = nl80211_stop_p2p_device, |
| 11732 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11733 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11734 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11735 | NL80211_FLAG_NEED_RTNL, |
| 11736 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11737 | { |
| 11738 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 11739 | .doit = nl80211_set_mcast_rate, |
| 11740 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11741 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11743 | NL80211_FLAG_NEED_RTNL, |
| 11744 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11745 | { |
| 11746 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 11747 | .doit = nl80211_set_mac_acl, |
| 11748 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11749 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11751 | NL80211_FLAG_NEED_RTNL, |
| 11752 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11753 | { |
| 11754 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 11755 | .doit = nl80211_start_radar_detection, |
| 11756 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11757 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11759 | NL80211_FLAG_NEED_RTNL, |
| 11760 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11761 | { |
| 11762 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 11763 | .doit = nl80211_get_protocol_features, |
| 11764 | .policy = nl80211_policy, |
| 11765 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11766 | { |
| 11767 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 11768 | .doit = nl80211_update_ft_ies, |
| 11769 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11770 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11771 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11772 | NL80211_FLAG_NEED_RTNL, |
| 11773 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11774 | { |
| 11775 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 11776 | .doit = nl80211_crit_protocol_start, |
| 11777 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11778 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11779 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11780 | NL80211_FLAG_NEED_RTNL, |
| 11781 | }, |
| 11782 | { |
| 11783 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 11784 | .doit = nl80211_crit_protocol_stop, |
| 11785 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11786 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11788 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11789 | }, |
| 11790 | { |
| 11791 | .cmd = NL80211_CMD_GET_COALESCE, |
| 11792 | .doit = nl80211_get_coalesce, |
| 11793 | .policy = nl80211_policy, |
| 11794 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11795 | NL80211_FLAG_NEED_RTNL, |
| 11796 | }, |
| 11797 | { |
| 11798 | .cmd = NL80211_CMD_SET_COALESCE, |
| 11799 | .doit = nl80211_set_coalesce, |
| 11800 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11801 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11802 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11803 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11804 | }, |
| 11805 | { |
| 11806 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 11807 | .doit = nl80211_channel_switch, |
| 11808 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11809 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11811 | NL80211_FLAG_NEED_RTNL, |
| 11812 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11813 | { |
| 11814 | .cmd = NL80211_CMD_VENDOR, |
| 11815 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11816 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11817 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11818 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11819 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11820 | NL80211_FLAG_NEED_RTNL, |
| 11821 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11822 | { |
| 11823 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11824 | .doit = nl80211_set_qos_map, |
| 11825 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11826 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11827 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11828 | NL80211_FLAG_NEED_RTNL, |
| 11829 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11830 | { |
| 11831 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11832 | .doit = nl80211_add_tx_ts, |
| 11833 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11834 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11836 | NL80211_FLAG_NEED_RTNL, |
| 11837 | }, |
| 11838 | { |
| 11839 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11840 | .doit = nl80211_del_tx_ts, |
| 11841 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11842 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11843 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11844 | NL80211_FLAG_NEED_RTNL, |
| 11845 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11846 | { |
| 11847 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11848 | .doit = nl80211_tdls_channel_switch, |
| 11849 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11850 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11852 | NL80211_FLAG_NEED_RTNL, |
| 11853 | }, |
| 11854 | { |
| 11855 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11856 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11857 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11858 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11859 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11860 | NL80211_FLAG_NEED_RTNL, |
| 11861 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11862 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11863 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11864 | /* notification functions */ |
| 11865 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11866 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11867 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11868 | { |
| 11869 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11870 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11871 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11872 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11873 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11874 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11876 | if (!msg) |
| 11877 | return; |
| 11878 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11879 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11880 | nlmsg_free(msg); |
| 11881 | return; |
| 11882 | } |
| 11883 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11884 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11885 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11886 | } |
| 11887 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 11888 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 11889 | struct wireless_dev *wdev, |
| 11890 | enum nl80211_commands cmd) |
| 11891 | { |
| 11892 | struct sk_buff *msg; |
| 11893 | |
| 11894 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 11895 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 11896 | |
| 11897 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11898 | if (!msg) |
| 11899 | return; |
| 11900 | |
| 11901 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 11902 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 11903 | nlmsg_free(msg); |
| 11904 | return; |
| 11905 | } |
| 11906 | |
| 11907 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 11908 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 11909 | } |
| 11910 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11911 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11912 | struct cfg80211_registered_device *rdev) |
| 11913 | { |
| 11914 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11915 | struct nlattr *nest; |
| 11916 | int i; |
| 11917 | |
| 11918 | if (WARN_ON(!req)) |
| 11919 | return 0; |
| 11920 | |
| 11921 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11922 | if (!nest) |
| 11923 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11924 | for (i = 0; i < req->n_ssids; i++) { |
| 11925 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11926 | goto nla_put_failure; |
| 11927 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11928 | nla_nest_end(msg, nest); |
| 11929 | |
| 11930 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11931 | if (!nest) |
| 11932 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11933 | for (i = 0; i < req->n_channels; i++) { |
| 11934 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11935 | goto nla_put_failure; |
| 11936 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11937 | nla_nest_end(msg, nest); |
| 11938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11939 | if (req->ie && |
| 11940 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11941 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11942 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11943 | if (req->flags && |
| 11944 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11945 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11946 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 11947 | if (req->info.scan_start_tsf && |
| 11948 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 11949 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 11950 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 11951 | req->info.tsf_bssid))) |
| 11952 | goto nla_put_failure; |
| 11953 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11954 | return 0; |
| 11955 | nla_put_failure: |
| 11956 | return -ENOBUFS; |
| 11957 | } |
| 11958 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11959 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11960 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11961 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11962 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11963 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11964 | { |
| 11965 | void *hdr; |
| 11966 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11967 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11968 | if (!hdr) |
| 11969 | return -1; |
| 11970 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11971 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11972 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11973 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11974 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11975 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11976 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11977 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11978 | /* ignore errors and send incomplete event anyway */ |
| 11979 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11980 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11981 | genlmsg_end(msg, hdr); |
| 11982 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11983 | |
| 11984 | nla_put_failure: |
| 11985 | genlmsg_cancel(msg, hdr); |
| 11986 | return -EMSGSIZE; |
| 11987 | } |
| 11988 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11989 | static int |
| 11990 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11991 | struct cfg80211_registered_device *rdev, |
| 11992 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11993 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11994 | { |
| 11995 | void *hdr; |
| 11996 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11997 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11998 | if (!hdr) |
| 11999 | return -1; |
| 12000 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12001 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12002 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12003 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12004 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 12005 | genlmsg_end(msg, hdr); |
| 12006 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12007 | |
| 12008 | nla_put_failure: |
| 12009 | genlmsg_cancel(msg, hdr); |
| 12010 | return -EMSGSIZE; |
| 12011 | } |
| 12012 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12013 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12014 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12015 | { |
| 12016 | struct sk_buff *msg; |
| 12017 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12018 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12019 | if (!msg) |
| 12020 | return; |
| 12021 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12022 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12023 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 12024 | nlmsg_free(msg); |
| 12025 | return; |
| 12026 | } |
| 12027 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12028 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12029 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12030 | } |
| 12031 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12032 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 12033 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12034 | { |
| 12035 | struct sk_buff *msg; |
| 12036 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12038 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12039 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12040 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12041 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12042 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 12043 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12044 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12045 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12046 | } |
| 12047 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12048 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12049 | } |
| 12050 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12051 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 12052 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12053 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12054 | if (!msg) |
| 12055 | return; |
| 12056 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12057 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12058 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12059 | } |
| 12060 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12061 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 12062 | struct net_device *netdev) |
| 12063 | { |
| 12064 | struct sk_buff *msg; |
| 12065 | |
| 12066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12067 | if (!msg) |
| 12068 | return; |
| 12069 | |
| 12070 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 12071 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 12072 | nlmsg_free(msg); |
| 12073 | return; |
| 12074 | } |
| 12075 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12076 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12077 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12078 | } |
| 12079 | |
| 12080 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 12081 | struct net_device *netdev, u32 cmd) |
| 12082 | { |
| 12083 | struct sk_buff *msg; |
| 12084 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12085 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12086 | if (!msg) |
| 12087 | return; |
| 12088 | |
| 12089 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 12090 | nlmsg_free(msg); |
| 12091 | return; |
| 12092 | } |
| 12093 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12094 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12095 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12096 | } |
| 12097 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12098 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 12099 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12100 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12101 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12102 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 12103 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12104 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12105 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 12106 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12107 | NL80211_REGDOM_TYPE_WORLD)) |
| 12108 | goto nla_put_failure; |
| 12109 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 12110 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12111 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 12112 | goto nla_put_failure; |
| 12113 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 12114 | request->intersect) { |
| 12115 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12116 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 12117 | goto nla_put_failure; |
| 12118 | } else { |
| 12119 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12120 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 12121 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 12122 | request->alpha2)) |
| 12123 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12124 | } |
| 12125 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12126 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 12127 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 12128 | |
| 12129 | if (wiphy && |
| 12130 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 12131 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 12132 | |
| 12133 | if (wiphy && |
| 12134 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 12135 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 12136 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12137 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12138 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12139 | return true; |
| 12140 | |
| 12141 | nla_put_failure: |
| 12142 | return false; |
| 12143 | } |
| 12144 | |
| 12145 | /* |
| 12146 | * This can happen on global regulatory changes or device specific settings |
| 12147 | * based on custom regulatory domains. |
| 12148 | */ |
| 12149 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 12150 | struct regulatory_request *request) |
| 12151 | { |
| 12152 | struct sk_buff *msg; |
| 12153 | void *hdr; |
| 12154 | |
| 12155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12156 | if (!msg) |
| 12157 | return; |
| 12158 | |
| 12159 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 12160 | if (!hdr) { |
| 12161 | nlmsg_free(msg); |
| 12162 | return; |
| 12163 | } |
| 12164 | |
| 12165 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 12166 | goto nla_put_failure; |
| 12167 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12168 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12169 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12170 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12171 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12172 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12173 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12174 | |
| 12175 | return; |
| 12176 | |
| 12177 | nla_put_failure: |
| 12178 | genlmsg_cancel(msg, hdr); |
| 12179 | nlmsg_free(msg); |
| 12180 | } |
| 12181 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12182 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 12183 | struct net_device *netdev, |
| 12184 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12185 | enum nl80211_commands cmd, gfp_t gfp, |
| 12186 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12187 | { |
| 12188 | struct sk_buff *msg; |
| 12189 | void *hdr; |
| 12190 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12191 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12192 | if (!msg) |
| 12193 | return; |
| 12194 | |
| 12195 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12196 | if (!hdr) { |
| 12197 | nlmsg_free(msg); |
| 12198 | return; |
| 12199 | } |
| 12200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12201 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12202 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12203 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 12204 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12205 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12206 | if (uapsd_queues >= 0) { |
| 12207 | struct nlattr *nla_wmm = |
| 12208 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 12209 | if (!nla_wmm) |
| 12210 | goto nla_put_failure; |
| 12211 | |
| 12212 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 12213 | uapsd_queues)) |
| 12214 | goto nla_put_failure; |
| 12215 | |
| 12216 | nla_nest_end(msg, nla_wmm); |
| 12217 | } |
| 12218 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12219 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12220 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12221 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12222 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12223 | return; |
| 12224 | |
| 12225 | nla_put_failure: |
| 12226 | genlmsg_cancel(msg, hdr); |
| 12227 | nlmsg_free(msg); |
| 12228 | } |
| 12229 | |
| 12230 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12231 | struct net_device *netdev, const u8 *buf, |
| 12232 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12233 | { |
| 12234 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12235 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12236 | } |
| 12237 | |
| 12238 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 12239 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12240 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12241 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12242 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12243 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12244 | } |
| 12245 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12246 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12247 | struct net_device *netdev, const u8 *buf, |
| 12248 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12249 | { |
| 12250 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12251 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12252 | } |
| 12253 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12254 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 12255 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12256 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12257 | { |
| 12258 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12259 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12260 | } |
| 12261 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12262 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 12263 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12264 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12265 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12266 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12267 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12268 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 12269 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12270 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12271 | if (WARN_ON(len < 2)) |
| 12272 | return; |
| 12273 | |
| 12274 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 12275 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 12276 | else |
| 12277 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 12278 | |
| 12279 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12280 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12281 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12282 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12283 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 12284 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 12285 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12286 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12287 | { |
| 12288 | struct sk_buff *msg; |
| 12289 | void *hdr; |
| 12290 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12292 | if (!msg) |
| 12293 | return; |
| 12294 | |
| 12295 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12296 | if (!hdr) { |
| 12297 | nlmsg_free(msg); |
| 12298 | return; |
| 12299 | } |
| 12300 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12301 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12302 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12303 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 12304 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12305 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12306 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12307 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12308 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12309 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12310 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12311 | return; |
| 12312 | |
| 12313 | nla_put_failure: |
| 12314 | genlmsg_cancel(msg, hdr); |
| 12315 | nlmsg_free(msg); |
| 12316 | } |
| 12317 | |
| 12318 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12319 | struct net_device *netdev, const u8 *addr, |
| 12320 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12321 | { |
| 12322 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12323 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12324 | } |
| 12325 | |
| 12326 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12327 | struct net_device *netdev, const u8 *addr, |
| 12328 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12329 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12330 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 12331 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12332 | } |
| 12333 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12334 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 12335 | struct net_device *netdev, const u8 *bssid, |
| 12336 | const u8 *req_ie, size_t req_ie_len, |
| 12337 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12338 | int status, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12339 | { |
| 12340 | struct sk_buff *msg; |
| 12341 | void *hdr; |
| 12342 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12344 | if (!msg) |
| 12345 | return; |
| 12346 | |
| 12347 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 12348 | if (!hdr) { |
| 12349 | nlmsg_free(msg); |
| 12350 | return; |
| 12351 | } |
| 12352 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12354 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12355 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12356 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 12357 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 12358 | status) || |
| 12359 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12360 | (req_ie && |
| 12361 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12362 | (resp_ie && |
| 12363 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12364 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12365 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12366 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12367 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12368 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12369 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12370 | return; |
| 12371 | |
| 12372 | nla_put_failure: |
| 12373 | genlmsg_cancel(msg, hdr); |
| 12374 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12375 | } |
| 12376 | |
| 12377 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 12378 | struct net_device *netdev, const u8 *bssid, |
| 12379 | const u8 *req_ie, size_t req_ie_len, |
| 12380 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 12381 | { |
| 12382 | struct sk_buff *msg; |
| 12383 | void *hdr; |
| 12384 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12386 | if (!msg) |
| 12387 | return; |
| 12388 | |
| 12389 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 12390 | if (!hdr) { |
| 12391 | nlmsg_free(msg); |
| 12392 | return; |
| 12393 | } |
| 12394 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12396 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12397 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 12398 | (req_ie && |
| 12399 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12400 | (resp_ie && |
| 12401 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12402 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12403 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12404 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12405 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12406 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12407 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12408 | return; |
| 12409 | |
| 12410 | nla_put_failure: |
| 12411 | genlmsg_cancel(msg, hdr); |
| 12412 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12413 | } |
| 12414 | |
| 12415 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 12416 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 12417 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12418 | { |
| 12419 | struct sk_buff *msg; |
| 12420 | void *hdr; |
| 12421 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12422 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12423 | if (!msg) |
| 12424 | return; |
| 12425 | |
| 12426 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 12427 | if (!hdr) { |
| 12428 | nlmsg_free(msg); |
| 12429 | return; |
| 12430 | } |
| 12431 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12432 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12433 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12434 | (from_ap && reason && |
| 12435 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 12436 | (from_ap && |
| 12437 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 12438 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 12439 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12440 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12441 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12442 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12443 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12444 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12445 | return; |
| 12446 | |
| 12447 | nla_put_failure: |
| 12448 | genlmsg_cancel(msg, hdr); |
| 12449 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12450 | } |
| 12451 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12452 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 12453 | struct net_device *netdev, const u8 *bssid, |
| 12454 | gfp_t gfp) |
| 12455 | { |
| 12456 | struct sk_buff *msg; |
| 12457 | void *hdr; |
| 12458 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12459 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12460 | if (!msg) |
| 12461 | return; |
| 12462 | |
| 12463 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 12464 | if (!hdr) { |
| 12465 | nlmsg_free(msg); |
| 12466 | return; |
| 12467 | } |
| 12468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12470 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12471 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12472 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12473 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12474 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12475 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12476 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12477 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12478 | return; |
| 12479 | |
| 12480 | nla_put_failure: |
| 12481 | genlmsg_cancel(msg, hdr); |
| 12482 | nlmsg_free(msg); |
| 12483 | } |
| 12484 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12485 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 12486 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12487 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12488 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12489 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12490 | struct sk_buff *msg; |
| 12491 | void *hdr; |
| 12492 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12493 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 12494 | return; |
| 12495 | |
| 12496 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 12497 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12498 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12499 | if (!msg) |
| 12500 | return; |
| 12501 | |
| 12502 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 12503 | if (!hdr) { |
| 12504 | nlmsg_free(msg); |
| 12505 | return; |
| 12506 | } |
| 12507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12508 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12509 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12510 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12511 | (ie_len && ie && |
| 12512 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 12513 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12514 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12515 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12516 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12518 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12519 | return; |
| 12520 | |
| 12521 | nla_put_failure: |
| 12522 | genlmsg_cancel(msg, hdr); |
| 12523 | nlmsg_free(msg); |
| 12524 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12525 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12526 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12527 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 12528 | struct net_device *netdev, const u8 *addr, |
| 12529 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12530 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12531 | { |
| 12532 | struct sk_buff *msg; |
| 12533 | void *hdr; |
| 12534 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12536 | if (!msg) |
| 12537 | return; |
| 12538 | |
| 12539 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 12540 | if (!hdr) { |
| 12541 | nlmsg_free(msg); |
| 12542 | return; |
| 12543 | } |
| 12544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12545 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12546 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12547 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 12548 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 12549 | (key_id != -1 && |
| 12550 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 12551 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 12552 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12553 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12554 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12555 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12556 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12557 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12558 | return; |
| 12559 | |
| 12560 | nla_put_failure: |
| 12561 | genlmsg_cancel(msg, hdr); |
| 12562 | nlmsg_free(msg); |
| 12563 | } |
| 12564 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12565 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 12566 | struct ieee80211_channel *channel_before, |
| 12567 | struct ieee80211_channel *channel_after) |
| 12568 | { |
| 12569 | struct sk_buff *msg; |
| 12570 | void *hdr; |
| 12571 | struct nlattr *nl_freq; |
| 12572 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12573 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12574 | if (!msg) |
| 12575 | return; |
| 12576 | |
| 12577 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 12578 | if (!hdr) { |
| 12579 | nlmsg_free(msg); |
| 12580 | return; |
| 12581 | } |
| 12582 | |
| 12583 | /* |
| 12584 | * Since we are applying the beacon hint to a wiphy we know its |
| 12585 | * wiphy_idx is valid |
| 12586 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12587 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 12588 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12589 | |
| 12590 | /* Before */ |
| 12591 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 12592 | if (!nl_freq) |
| 12593 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12594 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12595 | goto nla_put_failure; |
| 12596 | nla_nest_end(msg, nl_freq); |
| 12597 | |
| 12598 | /* After */ |
| 12599 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 12600 | if (!nl_freq) |
| 12601 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12602 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12603 | goto nla_put_failure; |
| 12604 | nla_nest_end(msg, nl_freq); |
| 12605 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12606 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12607 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12608 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12609 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12610 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12611 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12612 | |
| 12613 | return; |
| 12614 | |
| 12615 | nla_put_failure: |
| 12616 | genlmsg_cancel(msg, hdr); |
| 12617 | nlmsg_free(msg); |
| 12618 | } |
| 12619 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12620 | static void nl80211_send_remain_on_chan_event( |
| 12621 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12622 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12623 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12624 | unsigned int duration, gfp_t gfp) |
| 12625 | { |
| 12626 | struct sk_buff *msg; |
| 12627 | void *hdr; |
| 12628 | |
| 12629 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12630 | if (!msg) |
| 12631 | return; |
| 12632 | |
| 12633 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12634 | if (!hdr) { |
| 12635 | nlmsg_free(msg); |
| 12636 | return; |
| 12637 | } |
| 12638 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12640 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12641 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12642 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12643 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12644 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12645 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 12646 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12647 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12648 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12649 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12650 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12651 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 12652 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 12653 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12654 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12655 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12656 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12657 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12658 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12659 | return; |
| 12660 | |
| 12661 | nla_put_failure: |
| 12662 | genlmsg_cancel(msg, hdr); |
| 12663 | nlmsg_free(msg); |
| 12664 | } |
| 12665 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12666 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 12667 | struct ieee80211_channel *chan, |
| 12668 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12669 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12670 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12671 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12672 | |
| 12673 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12674 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12675 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12676 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12677 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12678 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12679 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12680 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 12681 | struct ieee80211_channel *chan, |
| 12682 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12683 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12684 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12685 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12686 | |
| 12687 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12688 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12689 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12690 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12691 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12692 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12693 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 12694 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12695 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12696 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12697 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12698 | struct sk_buff *msg; |
| 12699 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12700 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 12701 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12703 | if (!msg) |
| 12704 | return; |
| 12705 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12706 | 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] | 12707 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12708 | nlmsg_free(msg); |
| 12709 | return; |
| 12710 | } |
| 12711 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12712 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12713 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12714 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12715 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12716 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12717 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 12718 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12719 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12720 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12721 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12722 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12723 | struct station_info empty_sinfo = {}; |
| 12724 | |
| 12725 | if (!sinfo) |
| 12726 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12727 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12728 | trace_cfg80211_del_sta(dev, mac_addr); |
| 12729 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12731 | if (!msg) |
| 12732 | return; |
| 12733 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12734 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 12735 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12736 | nlmsg_free(msg); |
| 12737 | return; |
| 12738 | } |
| 12739 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12740 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12741 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12742 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12743 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12744 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12745 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 12746 | enum nl80211_connect_failed_reason reason, |
| 12747 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12748 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12749 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12750 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12751 | struct sk_buff *msg; |
| 12752 | void *hdr; |
| 12753 | |
| 12754 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 12755 | if (!msg) |
| 12756 | return; |
| 12757 | |
| 12758 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 12759 | if (!hdr) { |
| 12760 | nlmsg_free(msg); |
| 12761 | return; |
| 12762 | } |
| 12763 | |
| 12764 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12765 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 12766 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 12767 | goto nla_put_failure; |
| 12768 | |
| 12769 | genlmsg_end(msg, hdr); |
| 12770 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12771 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12772 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12773 | return; |
| 12774 | |
| 12775 | nla_put_failure: |
| 12776 | genlmsg_cancel(msg, hdr); |
| 12777 | nlmsg_free(msg); |
| 12778 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12779 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12780 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12781 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 12782 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12783 | { |
| 12784 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12785 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12786 | struct sk_buff *msg; |
| 12787 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12788 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12789 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12790 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12791 | return false; |
| 12792 | |
| 12793 | msg = nlmsg_new(100, gfp); |
| 12794 | if (!msg) |
| 12795 | return true; |
| 12796 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12797 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12798 | if (!hdr) { |
| 12799 | nlmsg_free(msg); |
| 12800 | return true; |
| 12801 | } |
| 12802 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12803 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12804 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12805 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12806 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12807 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12808 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12809 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12810 | return true; |
| 12811 | |
| 12812 | nla_put_failure: |
| 12813 | genlmsg_cancel(msg, hdr); |
| 12814 | nlmsg_free(msg); |
| 12815 | return true; |
| 12816 | } |
| 12817 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12818 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 12819 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12820 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12821 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12822 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12823 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12824 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 12825 | |
| 12826 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12827 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 12828 | trace_cfg80211_return_bool(false); |
| 12829 | return false; |
| 12830 | } |
| 12831 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 12832 | addr, gfp); |
| 12833 | trace_cfg80211_return_bool(ret); |
| 12834 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12835 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12836 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 12837 | |
| 12838 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 12839 | const u8 *addr, gfp_t gfp) |
| 12840 | { |
| 12841 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12842 | bool ret; |
| 12843 | |
| 12844 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 12845 | |
| 12846 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12847 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 12848 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 12849 | trace_cfg80211_return_bool(false); |
| 12850 | return false; |
| 12851 | } |
| 12852 | ret = __nl80211_unexpected_frame(dev, |
| 12853 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12854 | addr, gfp); |
| 12855 | trace_cfg80211_return_bool(ret); |
| 12856 | return ret; |
| 12857 | } |
| 12858 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12859 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12860 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12861 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12862 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12863 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12864 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12865 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12866 | struct sk_buff *msg; |
| 12867 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12868 | |
| 12869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12870 | if (!msg) |
| 12871 | return -ENOMEM; |
| 12872 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12873 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12874 | if (!hdr) { |
| 12875 | nlmsg_free(msg); |
| 12876 | return -ENOMEM; |
| 12877 | } |
| 12878 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12879 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12880 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12881 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12882 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12883 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12884 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12885 | (sig_dbm && |
| 12886 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12887 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12888 | (flags && |
| 12889 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12890 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12891 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12892 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12893 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12894 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12895 | |
| 12896 | nla_put_failure: |
| 12897 | genlmsg_cancel(msg, hdr); |
| 12898 | nlmsg_free(msg); |
| 12899 | return -ENOBUFS; |
| 12900 | } |
| 12901 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12902 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12903 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12904 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12905 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12906 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12907 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12908 | struct sk_buff *msg; |
| 12909 | void *hdr; |
| 12910 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12911 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12912 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12914 | if (!msg) |
| 12915 | return; |
| 12916 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12917 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12918 | if (!hdr) { |
| 12919 | nlmsg_free(msg); |
| 12920 | return; |
| 12921 | } |
| 12922 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12923 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12924 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12925 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12926 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12927 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12928 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12929 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12930 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12931 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12932 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12933 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12934 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12935 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12936 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12937 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12938 | return; |
| 12939 | |
| 12940 | nla_put_failure: |
| 12941 | genlmsg_cancel(msg, hdr); |
| 12942 | nlmsg_free(msg); |
| 12943 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12944 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12945 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12946 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12947 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12948 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12949 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12950 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12951 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12952 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12953 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12954 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12955 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12956 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12957 | cb = (void **)msg->cb; |
| 12958 | |
| 12959 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12960 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12961 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12962 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12963 | } |
| 12964 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12966 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12967 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12968 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12969 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12970 | goto nla_put_failure; |
| 12971 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12972 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12973 | if (!cb[1]) |
| 12974 | goto nla_put_failure; |
| 12975 | |
| 12976 | cb[2] = rdev; |
| 12977 | |
| 12978 | return msg; |
| 12979 | nla_put_failure: |
| 12980 | nlmsg_free(msg); |
| 12981 | return NULL; |
| 12982 | } |
| 12983 | |
| 12984 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12985 | { |
| 12986 | void **cb = (void **)msg->cb; |
| 12987 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12988 | |
| 12989 | nla_nest_end(msg, cb[1]); |
| 12990 | genlmsg_end(msg, cb[0]); |
| 12991 | |
| 12992 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12993 | |
| 12994 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12995 | NL80211_MCGRP_MLME, gfp); |
| 12996 | } |
| 12997 | |
| 12998 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12999 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 13000 | gfp_t gfp) |
| 13001 | { |
| 13002 | struct sk_buff *msg; |
| 13003 | |
| 13004 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 13005 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13006 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 13007 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 13008 | return; |
| 13009 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13010 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13011 | if (!msg) |
| 13012 | return; |
| 13013 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13014 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 13015 | rssi_event)) |
| 13016 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13017 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13018 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13019 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13020 | return; |
| 13021 | |
| 13022 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13023 | nlmsg_free(msg); |
| 13024 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13025 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13026 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13027 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 13028 | const u8 *peer, u32 num_packets, |
| 13029 | u32 rate, u32 intvl, gfp_t gfp) |
| 13030 | { |
| 13031 | struct sk_buff *msg; |
| 13032 | |
| 13033 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13034 | if (!msg) |
| 13035 | return; |
| 13036 | |
| 13037 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 13038 | goto nla_put_failure; |
| 13039 | |
| 13040 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 13041 | goto nla_put_failure; |
| 13042 | |
| 13043 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 13044 | goto nla_put_failure; |
| 13045 | |
| 13046 | cfg80211_send_cqm(msg, gfp); |
| 13047 | return; |
| 13048 | |
| 13049 | nla_put_failure: |
| 13050 | nlmsg_free(msg); |
| 13051 | } |
| 13052 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 13053 | |
| 13054 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 13055 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 13056 | { |
| 13057 | struct sk_buff *msg; |
| 13058 | |
| 13059 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 13060 | |
| 13061 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13062 | if (!msg) |
| 13063 | return; |
| 13064 | |
| 13065 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 13066 | goto nla_put_failure; |
| 13067 | |
| 13068 | cfg80211_send_cqm(msg, gfp); |
| 13069 | return; |
| 13070 | |
| 13071 | nla_put_failure: |
| 13072 | nlmsg_free(msg); |
| 13073 | } |
| 13074 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 13075 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13076 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 13077 | { |
| 13078 | struct sk_buff *msg; |
| 13079 | |
| 13080 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13081 | if (!msg) |
| 13082 | return; |
| 13083 | |
| 13084 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 13085 | goto nla_put_failure; |
| 13086 | |
| 13087 | cfg80211_send_cqm(msg, gfp); |
| 13088 | return; |
| 13089 | |
| 13090 | nla_put_failure: |
| 13091 | nlmsg_free(msg); |
| 13092 | } |
| 13093 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 13094 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13095 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 13096 | struct net_device *netdev, const u8 *bssid, |
| 13097 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13098 | { |
| 13099 | struct sk_buff *msg; |
| 13100 | struct nlattr *rekey_attr; |
| 13101 | void *hdr; |
| 13102 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13104 | if (!msg) |
| 13105 | return; |
| 13106 | |
| 13107 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 13108 | if (!hdr) { |
| 13109 | nlmsg_free(msg); |
| 13110 | return; |
| 13111 | } |
| 13112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13113 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13114 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13115 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13116 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13117 | |
| 13118 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 13119 | if (!rekey_attr) |
| 13120 | goto nla_put_failure; |
| 13121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13122 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 13123 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 13124 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13125 | |
| 13126 | nla_nest_end(msg, rekey_attr); |
| 13127 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13128 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13129 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13130 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13131 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13132 | return; |
| 13133 | |
| 13134 | nla_put_failure: |
| 13135 | genlmsg_cancel(msg, hdr); |
| 13136 | nlmsg_free(msg); |
| 13137 | } |
| 13138 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13139 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 13140 | const u8 *replay_ctr, gfp_t gfp) |
| 13141 | { |
| 13142 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13143 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13144 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13145 | |
| 13146 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 13147 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 13148 | } |
| 13149 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 13150 | |
| 13151 | static void |
| 13152 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 13153 | struct net_device *netdev, int index, |
| 13154 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13155 | { |
| 13156 | struct sk_buff *msg; |
| 13157 | struct nlattr *attr; |
| 13158 | void *hdr; |
| 13159 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13161 | if (!msg) |
| 13162 | return; |
| 13163 | |
| 13164 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 13165 | if (!hdr) { |
| 13166 | nlmsg_free(msg); |
| 13167 | return; |
| 13168 | } |
| 13169 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13171 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13172 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13173 | |
| 13174 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 13175 | if (!attr) |
| 13176 | goto nla_put_failure; |
| 13177 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13178 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 13179 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 13180 | (preauth && |
| 13181 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 13182 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13183 | |
| 13184 | nla_nest_end(msg, attr); |
| 13185 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13186 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13187 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13188 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13189 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13190 | return; |
| 13191 | |
| 13192 | nla_put_failure: |
| 13193 | genlmsg_cancel(msg, hdr); |
| 13194 | nlmsg_free(msg); |
| 13195 | } |
| 13196 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13197 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 13198 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 13199 | { |
| 13200 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13201 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13202 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13203 | |
| 13204 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 13205 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 13206 | } |
| 13207 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 13208 | |
| 13209 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 13210 | struct net_device *netdev, |
| 13211 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13212 | gfp_t gfp, |
| 13213 | enum nl80211_commands notif, |
| 13214 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13215 | { |
| 13216 | struct sk_buff *msg; |
| 13217 | void *hdr; |
| 13218 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13220 | if (!msg) |
| 13221 | return; |
| 13222 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13223 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13224 | if (!hdr) { |
| 13225 | nlmsg_free(msg); |
| 13226 | return; |
| 13227 | } |
| 13228 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 13229 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13230 | goto nla_put_failure; |
| 13231 | |
| 13232 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 13233 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13234 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13235 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 13236 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 13237 | goto nla_put_failure; |
| 13238 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13239 | genlmsg_end(msg, hdr); |
| 13240 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13241 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13242 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13243 | return; |
| 13244 | |
| 13245 | nla_put_failure: |
| 13246 | genlmsg_cancel(msg, hdr); |
| 13247 | nlmsg_free(msg); |
| 13248 | } |
| 13249 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13250 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 13251 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13252 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13253 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13254 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13255 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13256 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13257 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13258 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13259 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13260 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 13261 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 13262 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13263 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13264 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13265 | } |
| 13266 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 13267 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13268 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 13269 | struct cfg80211_chan_def *chandef, |
| 13270 | u8 count) |
| 13271 | { |
| 13272 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13273 | struct wiphy *wiphy = wdev->wiphy; |
| 13274 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13275 | |
| 13276 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 13277 | |
| 13278 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13279 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 13280 | } |
| 13281 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 13282 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13283 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13284 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 13285 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13286 | enum nl80211_radar_event event, |
| 13287 | struct net_device *netdev, gfp_t gfp) |
| 13288 | { |
| 13289 | struct sk_buff *msg; |
| 13290 | void *hdr; |
| 13291 | |
| 13292 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13293 | if (!msg) |
| 13294 | return; |
| 13295 | |
| 13296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 13297 | if (!hdr) { |
| 13298 | nlmsg_free(msg); |
| 13299 | return; |
| 13300 | } |
| 13301 | |
| 13302 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 13303 | goto nla_put_failure; |
| 13304 | |
| 13305 | /* NOP and radar events don't need a netdev parameter */ |
| 13306 | if (netdev) { |
| 13307 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 13308 | |
| 13309 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13310 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13311 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13312 | goto nla_put_failure; |
| 13313 | } |
| 13314 | |
| 13315 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 13316 | goto nla_put_failure; |
| 13317 | |
| 13318 | if (nl80211_send_chandef(msg, chandef)) |
| 13319 | goto nla_put_failure; |
| 13320 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13321 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13322 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13323 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13324 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13325 | return; |
| 13326 | |
| 13327 | nla_put_failure: |
| 13328 | genlmsg_cancel(msg, hdr); |
| 13329 | nlmsg_free(msg); |
| 13330 | } |
| 13331 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13332 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 13333 | u64 cookie, bool acked, gfp_t gfp) |
| 13334 | { |
| 13335 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13336 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13337 | struct sk_buff *msg; |
| 13338 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13339 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13340 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 13341 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13342 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13343 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13344 | if (!msg) |
| 13345 | return; |
| 13346 | |
| 13347 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 13348 | if (!hdr) { |
| 13349 | nlmsg_free(msg); |
| 13350 | return; |
| 13351 | } |
| 13352 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13354 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13355 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13356 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13357 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13358 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 13359 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13360 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13361 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13362 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13363 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13364 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13365 | return; |
| 13366 | |
| 13367 | nla_put_failure: |
| 13368 | genlmsg_cancel(msg, hdr); |
| 13369 | nlmsg_free(msg); |
| 13370 | } |
| 13371 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 13372 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13373 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 13374 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13375 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13376 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13377 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13378 | struct sk_buff *msg; |
| 13379 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13380 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13381 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13382 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 13383 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13384 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13385 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 13386 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 13387 | if (!msg) { |
| 13388 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13389 | return; |
| 13390 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13391 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13392 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 13393 | if (!hdr) |
| 13394 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13395 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13397 | (freq && |
| 13398 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 13399 | (sig_dbm && |
| 13400 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 13401 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 13402 | goto nla_put_failure; |
| 13403 | |
| 13404 | genlmsg_end(msg, hdr); |
| 13405 | |
| 13406 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13407 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13408 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13409 | return; |
| 13410 | |
| 13411 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13412 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13413 | if (hdr) |
| 13414 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13415 | nlmsg_free(msg); |
| 13416 | } |
| 13417 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 13418 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13419 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13420 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 13421 | struct cfg80211_wowlan_wakeup *wakeup) |
| 13422 | { |
| 13423 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 13424 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 13425 | int i, j; |
| 13426 | |
| 13427 | nl_results = nla_nest_start( |
| 13428 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 13429 | if (!nl_results) |
| 13430 | return -EMSGSIZE; |
| 13431 | |
| 13432 | for (i = 0; i < nd->n_matches; i++) { |
| 13433 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 13434 | |
| 13435 | nl_match = nla_nest_start(msg, i); |
| 13436 | if (!nl_match) |
| 13437 | break; |
| 13438 | |
| 13439 | /* The SSID attribute is optional in nl80211, but for |
| 13440 | * simplicity reasons it's always present in the |
| 13441 | * cfg80211 structure. If a driver can't pass the |
| 13442 | * SSID, that needs to be changed. A zero length SSID |
| 13443 | * is still a valid SSID (wildcard), so it cannot be |
| 13444 | * used for this purpose. |
| 13445 | */ |
| 13446 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 13447 | match->ssid.ssid)) { |
| 13448 | nla_nest_cancel(msg, nl_match); |
| 13449 | goto out; |
| 13450 | } |
| 13451 | |
| 13452 | if (match->n_channels) { |
| 13453 | nl_freqs = nla_nest_start( |
| 13454 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13455 | if (!nl_freqs) { |
| 13456 | nla_nest_cancel(msg, nl_match); |
| 13457 | goto out; |
| 13458 | } |
| 13459 | |
| 13460 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 13461 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13462 | nla_nest_cancel(msg, nl_freqs); |
| 13463 | nla_nest_cancel(msg, nl_match); |
| 13464 | goto out; |
| 13465 | } |
| 13466 | } |
| 13467 | |
| 13468 | nla_nest_end(msg, nl_freqs); |
| 13469 | } |
| 13470 | |
| 13471 | nla_nest_end(msg, nl_match); |
| 13472 | } |
| 13473 | |
| 13474 | out: |
| 13475 | nla_nest_end(msg, nl_results); |
| 13476 | return 0; |
| 13477 | } |
| 13478 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13479 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 13480 | struct cfg80211_wowlan_wakeup *wakeup, |
| 13481 | gfp_t gfp) |
| 13482 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13483 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13484 | struct sk_buff *msg; |
| 13485 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13486 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13487 | |
| 13488 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 13489 | |
| 13490 | if (wakeup) |
| 13491 | size += wakeup->packet_present_len; |
| 13492 | |
| 13493 | msg = nlmsg_new(size, gfp); |
| 13494 | if (!msg) |
| 13495 | return; |
| 13496 | |
| 13497 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 13498 | if (!hdr) |
| 13499 | goto free_msg; |
| 13500 | |
| 13501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13502 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13503 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13504 | goto free_msg; |
| 13505 | |
| 13506 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13507 | wdev->netdev->ifindex)) |
| 13508 | goto free_msg; |
| 13509 | |
| 13510 | if (wakeup) { |
| 13511 | struct nlattr *reasons; |
| 13512 | |
| 13513 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 13514 | if (!reasons) |
| 13515 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13516 | |
| 13517 | if (wakeup->disconnect && |
| 13518 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 13519 | goto free_msg; |
| 13520 | if (wakeup->magic_pkt && |
| 13521 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 13522 | goto free_msg; |
| 13523 | if (wakeup->gtk_rekey_failure && |
| 13524 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 13525 | goto free_msg; |
| 13526 | if (wakeup->eap_identity_req && |
| 13527 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 13528 | goto free_msg; |
| 13529 | if (wakeup->four_way_handshake && |
| 13530 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 13531 | goto free_msg; |
| 13532 | if (wakeup->rfkill_release && |
| 13533 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 13534 | goto free_msg; |
| 13535 | |
| 13536 | if (wakeup->pattern_idx >= 0 && |
| 13537 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 13538 | wakeup->pattern_idx)) |
| 13539 | goto free_msg; |
| 13540 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13541 | if (wakeup->tcp_match && |
| 13542 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 13543 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13544 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13545 | if (wakeup->tcp_connlost && |
| 13546 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 13547 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13548 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13549 | if (wakeup->tcp_nomoretokens && |
| 13550 | nla_put_flag(msg, |
| 13551 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 13552 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13553 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13554 | if (wakeup->packet) { |
| 13555 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 13556 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 13557 | |
| 13558 | if (!wakeup->packet_80211) { |
| 13559 | pkt_attr = |
| 13560 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 13561 | len_attr = |
| 13562 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 13563 | } |
| 13564 | |
| 13565 | if (wakeup->packet_len && |
| 13566 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 13567 | goto free_msg; |
| 13568 | |
| 13569 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 13570 | wakeup->packet)) |
| 13571 | goto free_msg; |
| 13572 | } |
| 13573 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13574 | if (wakeup->net_detect && |
| 13575 | cfg80211_net_detect_results(msg, wakeup)) |
| 13576 | goto free_msg; |
| 13577 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13578 | nla_nest_end(msg, reasons); |
| 13579 | } |
| 13580 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13581 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13582 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13583 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13584 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13585 | return; |
| 13586 | |
| 13587 | free_msg: |
| 13588 | nlmsg_free(msg); |
| 13589 | } |
| 13590 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 13591 | #endif |
| 13592 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13593 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 13594 | enum nl80211_tdls_operation oper, |
| 13595 | u16 reason_code, gfp_t gfp) |
| 13596 | { |
| 13597 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13598 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13599 | struct sk_buff *msg; |
| 13600 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13601 | |
| 13602 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 13603 | reason_code); |
| 13604 | |
| 13605 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13606 | if (!msg) |
| 13607 | return; |
| 13608 | |
| 13609 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 13610 | if (!hdr) { |
| 13611 | nlmsg_free(msg); |
| 13612 | return; |
| 13613 | } |
| 13614 | |
| 13615 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13616 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13617 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 13618 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 13619 | (reason_code > 0 && |
| 13620 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 13621 | goto nla_put_failure; |
| 13622 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13623 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13624 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13625 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13626 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13627 | return; |
| 13628 | |
| 13629 | nla_put_failure: |
| 13630 | genlmsg_cancel(msg, hdr); |
| 13631 | nlmsg_free(msg); |
| 13632 | } |
| 13633 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 13634 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13635 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 13636 | unsigned long state, |
| 13637 | void *_notify) |
| 13638 | { |
| 13639 | struct netlink_notify *notify = _notify; |
| 13640 | struct cfg80211_registered_device *rdev; |
| 13641 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13642 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13643 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 13644 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13645 | return NOTIFY_DONE; |
| 13646 | |
| 13647 | rcu_read_lock(); |
| 13648 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13649 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13650 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13651 | bool schedule_scan_stop = false; |
| 13652 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 13653 | rcu_dereference(rdev->sched_scan_req); |
| 13654 | |
| 13655 | if (sched_scan_req && notify->portid && |
| 13656 | sched_scan_req->owner_nlportid == notify->portid) |
| 13657 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13658 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13659 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13660 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13661 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13662 | if (wdev->owner_nlportid == notify->portid) |
| 13663 | schedule_destroy_work = true; |
| 13664 | } |
| 13665 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13666 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13667 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 13668 | list) { |
| 13669 | if (reg->nlportid == notify->portid) { |
| 13670 | list_del(®->list); |
| 13671 | kfree(reg); |
| 13672 | break; |
| 13673 | } |
| 13674 | } |
| 13675 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13676 | |
| 13677 | if (schedule_destroy_work) { |
| 13678 | struct cfg80211_iface_destroy *destroy; |
| 13679 | |
| 13680 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 13681 | if (destroy) { |
| 13682 | destroy->nlportid = notify->portid; |
| 13683 | spin_lock(&rdev->destroy_list_lock); |
| 13684 | list_add(&destroy->list, &rdev->destroy_list); |
| 13685 | spin_unlock(&rdev->destroy_list_lock); |
| 13686 | schedule_work(&rdev->destroy_work); |
| 13687 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13688 | } else if (schedule_scan_stop) { |
| 13689 | sched_scan_req->owner_nlportid = 0; |
| 13690 | |
| 13691 | if (rdev->ops->sched_scan_stop && |
| 13692 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 13693 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13694 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13695 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13696 | |
| 13697 | rcu_read_unlock(); |
| 13698 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 13699 | /* |
| 13700 | * It is possible that the user space process that is controlling the |
| 13701 | * indoor setting disappeared, so notify the regulatory core. |
| 13702 | */ |
| 13703 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 13704 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13705 | } |
| 13706 | |
| 13707 | static struct notifier_block nl80211_netlink_notifier = { |
| 13708 | .notifier_call = nl80211_netlink_notify, |
| 13709 | }; |
| 13710 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13711 | void cfg80211_ft_event(struct net_device *netdev, |
| 13712 | struct cfg80211_ft_event_params *ft_event) |
| 13713 | { |
| 13714 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13715 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13716 | struct sk_buff *msg; |
| 13717 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13718 | |
| 13719 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 13720 | |
| 13721 | if (!ft_event->target_ap) |
| 13722 | return; |
| 13723 | |
| 13724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13725 | if (!msg) |
| 13726 | return; |
| 13727 | |
| 13728 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13729 | if (!hdr) |
| 13730 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13731 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13733 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13734 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 13735 | goto out; |
| 13736 | |
| 13737 | if (ft_event->ies && |
| 13738 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 13739 | goto out; |
| 13740 | if (ft_event->ric_ies && |
| 13741 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 13742 | ft_event->ric_ies)) |
| 13743 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13744 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13745 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13746 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13747 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13748 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13749 | return; |
| 13750 | out: |
| 13751 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13752 | } |
| 13753 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 13754 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13755 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 13756 | { |
| 13757 | struct cfg80211_registered_device *rdev; |
| 13758 | struct sk_buff *msg; |
| 13759 | void *hdr; |
| 13760 | u32 nlportid; |
| 13761 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13762 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13763 | if (!rdev->crit_proto_nlportid) |
| 13764 | return; |
| 13765 | |
| 13766 | nlportid = rdev->crit_proto_nlportid; |
| 13767 | rdev->crit_proto_nlportid = 0; |
| 13768 | |
| 13769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13770 | if (!msg) |
| 13771 | return; |
| 13772 | |
| 13773 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 13774 | if (!hdr) |
| 13775 | goto nla_put_failure; |
| 13776 | |
| 13777 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13778 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13779 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13780 | goto nla_put_failure; |
| 13781 | |
| 13782 | genlmsg_end(msg, hdr); |
| 13783 | |
| 13784 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 13785 | return; |
| 13786 | |
| 13787 | nla_put_failure: |
| 13788 | if (hdr) |
| 13789 | genlmsg_cancel(msg, hdr); |
| 13790 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13791 | } |
| 13792 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 13793 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13794 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 13795 | { |
| 13796 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13797 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13798 | struct sk_buff *msg; |
| 13799 | void *hdr; |
| 13800 | |
| 13801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13802 | if (!msg) |
| 13803 | return; |
| 13804 | |
| 13805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 13806 | if (!hdr) |
| 13807 | goto out; |
| 13808 | |
| 13809 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13810 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13811 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13812 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13813 | goto out; |
| 13814 | |
| 13815 | genlmsg_end(msg, hdr); |
| 13816 | |
| 13817 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 13818 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13819 | return; |
| 13820 | out: |
| 13821 | nlmsg_free(msg); |
| 13822 | } |
| 13823 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13824 | /* initialisation/exit functions */ |
| 13825 | |
| 13826 | int nl80211_init(void) |
| 13827 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 13828 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13829 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13830 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 13831 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13832 | if (err) |
| 13833 | return err; |
| 13834 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13835 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 13836 | if (err) |
| 13837 | goto err_out; |
| 13838 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13839 | return 0; |
| 13840 | err_out: |
| 13841 | genl_unregister_family(&nl80211_fam); |
| 13842 | return err; |
| 13843 | } |
| 13844 | |
| 13845 | void nl80211_exit(void) |
| 13846 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13847 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13848 | genl_unregister_family(&nl80211_fam); |
| 13849 | } |