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 | 36aedc90 | 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 | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 294 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_STA_FLAGS2] = { |
| 296 | .len = sizeof(struct nl80211_sta_flag_update), |
| 297 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 298 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 299 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 300 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 301 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 302 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 303 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 304 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 305 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 307 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 308 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 309 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 310 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 311 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
| 313 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 314 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 319 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 320 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 321 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 322 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 324 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 326 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 327 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 328 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 329 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 330 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 331 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
| 334 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 338 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 341 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 343 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 344 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 345 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 346 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 347 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 348 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 349 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 350 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 351 | .len = NL80211_HT_CAPABILITY_LEN |
| 352 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 353 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 354 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 355 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 356 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 357 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 358 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 359 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 360 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 361 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 362 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 363 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 364 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 365 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 366 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 367 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 368 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 369 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 370 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 371 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 372 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 373 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 374 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 375 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 376 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 377 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 378 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 379 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 381 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 382 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 383 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 384 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 385 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 386 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 387 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 388 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 389 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 390 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 391 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 392 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 395 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 396 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 397 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 398 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 399 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 400 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 403 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 404 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 405 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 406 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 407 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 408 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 409 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 410 | }, |
| 411 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 412 | }; |
| 413 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 415 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 416 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 417 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 418 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 419 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 420 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 421 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 422 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 423 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 424 | }; |
| 425 | |
| 426 | /* policy for the key default flags */ |
| 427 | static const struct nla_policy |
| 428 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 429 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 430 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 431 | }; |
| 432 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 433 | /* policy for WoWLAN attributes */ |
| 434 | static const struct nla_policy |
| 435 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 436 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 437 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 438 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 439 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 440 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 441 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 442 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 443 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 444 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 445 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | static const struct nla_policy |
| 449 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 450 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 451 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 452 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 453 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 454 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 455 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 456 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 457 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 458 | }, |
| 459 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 460 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 461 | }, |
| 462 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 463 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 464 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 465 | }; |
| 466 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 467 | /* policy for coalesce rule attributes */ |
| 468 | static const struct nla_policy |
| 469 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 470 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 471 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 472 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 473 | }; |
| 474 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 475 | /* policy for GTK rekey offload attributes */ |
| 476 | static const struct nla_policy |
| 477 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 478 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 479 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 480 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 481 | }; |
| 482 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 483 | static const struct nla_policy |
| 484 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 485 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 486 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 487 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 488 | }; |
| 489 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 490 | static const struct nla_policy |
| 491 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 492 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 493 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 494 | }; |
| 495 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 496 | static const struct nla_policy |
| 497 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 498 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 499 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 500 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 501 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 502 | }, |
| 503 | }; |
| 504 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 505 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 506 | struct netlink_callback *cb, |
| 507 | struct cfg80211_registered_device **rdev, |
| 508 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 509 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 510 | int err; |
| 511 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 512 | rtnl_lock(); |
| 513 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | if (!cb->args[0]) { |
| 515 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 516 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 517 | nl80211_policy); |
| 518 | if (err) |
| 519 | goto out_unlock; |
| 520 | |
| 521 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 522 | nl80211_fam.attrbuf); |
| 523 | if (IS_ERR(*wdev)) { |
| 524 | err = PTR_ERR(*wdev); |
| 525 | goto out_unlock; |
| 526 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 527 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 528 | /* 0 is the first index - add 1 to parse only once */ |
| 529 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 530 | cb->args[1] = (*wdev)->identifier; |
| 531 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 532 | /* subtract the 1 again here */ |
| 533 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 534 | struct wireless_dev *tmp; |
| 535 | |
| 536 | if (!wiphy) { |
| 537 | err = -ENODEV; |
| 538 | goto out_unlock; |
| 539 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 540 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 541 | *wdev = NULL; |
| 542 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 543 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 544 | if (tmp->identifier == cb->args[1]) { |
| 545 | *wdev = tmp; |
| 546 | break; |
| 547 | } |
| 548 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 549 | |
| 550 | if (!*wdev) { |
| 551 | err = -ENODEV; |
| 552 | goto out_unlock; |
| 553 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 556 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 557 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 558 | rtnl_unlock(); |
| 559 | return err; |
| 560 | } |
| 561 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 562 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 563 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 564 | rtnl_unlock(); |
| 565 | } |
| 566 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 567 | /* IE validation */ |
| 568 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 569 | { |
| 570 | const u8 *pos; |
| 571 | int len; |
| 572 | |
| 573 | if (!attr) |
| 574 | return true; |
| 575 | |
| 576 | pos = nla_data(attr); |
| 577 | len = nla_len(attr); |
| 578 | |
| 579 | while (len) { |
| 580 | u8 elemlen; |
| 581 | |
| 582 | if (len < 2) |
| 583 | return false; |
| 584 | len -= 2; |
| 585 | |
| 586 | elemlen = pos[1]; |
| 587 | if (elemlen > len) |
| 588 | return false; |
| 589 | |
| 590 | len -= elemlen; |
| 591 | pos += 2 + elemlen; |
| 592 | } |
| 593 | |
| 594 | return true; |
| 595 | } |
| 596 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 597 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 598 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 599 | int flags, u8 cmd) |
| 600 | { |
| 601 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 602 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 605 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 606 | struct ieee80211_channel *chan, |
| 607 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 608 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 609 | /* Some channels must be completely excluded from the |
| 610 | * list to protect old user-space tools from breaking |
| 611 | */ |
| 612 | if (!large && chan->flags & |
| 613 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 614 | return 0; |
| 615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 617 | chan->center_freq)) |
| 618 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 619 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 620 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 622 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 623 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 624 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 625 | goto nla_put_failure; |
| 626 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 627 | goto nla_put_failure; |
| 628 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 629 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 630 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 631 | goto nla_put_failure; |
| 632 | if (large) { |
| 633 | u32 time; |
| 634 | |
| 635 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 636 | |
| 637 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 638 | chan->dfs_state)) |
| 639 | goto nla_put_failure; |
| 640 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 641 | time)) |
| 642 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 643 | if (nla_put_u32(msg, |
| 644 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 645 | chan->dfs_cac_ms)) |
| 646 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 647 | } |
| 648 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 649 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 650 | if (large) { |
| 651 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 652 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 653 | goto nla_put_failure; |
| 654 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 655 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 656 | goto nla_put_failure; |
| 657 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 658 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 659 | goto nla_put_failure; |
| 660 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 661 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 662 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 663 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 664 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 665 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 666 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 667 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 668 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 669 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 670 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 671 | goto nla_put_failure; |
| 672 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 673 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 674 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 675 | } |
| 676 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 677 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 678 | DBM_TO_MBM(chan->max_power))) |
| 679 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 680 | |
| 681 | return 0; |
| 682 | |
| 683 | nla_put_failure: |
| 684 | return -ENOBUFS; |
| 685 | } |
| 686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 687 | /* netlink command implementations */ |
| 688 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 689 | struct key_parse { |
| 690 | struct key_params p; |
| 691 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 692 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 693 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 694 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 695 | }; |
| 696 | |
| 697 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 698 | { |
| 699 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 700 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 701 | nl80211_key_policy); |
| 702 | if (err) |
| 703 | return err; |
| 704 | |
| 705 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 706 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 707 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 708 | if (k->def) { |
| 709 | k->def_uni = true; |
| 710 | k->def_multi = true; |
| 711 | } |
| 712 | if (k->defmgmt) |
| 713 | k->def_multi = true; |
| 714 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 715 | if (tb[NL80211_KEY_IDX]) |
| 716 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 717 | |
| 718 | if (tb[NL80211_KEY_DATA]) { |
| 719 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 720 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 721 | } |
| 722 | |
| 723 | if (tb[NL80211_KEY_SEQ]) { |
| 724 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 725 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 726 | } |
| 727 | |
| 728 | if (tb[NL80211_KEY_CIPHER]) |
| 729 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 730 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 731 | if (tb[NL80211_KEY_TYPE]) { |
| 732 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 733 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 734 | return -EINVAL; |
| 735 | } |
| 736 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 737 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 738 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 739 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 740 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 741 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 742 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 743 | if (err) |
| 744 | return err; |
| 745 | |
| 746 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 747 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 748 | } |
| 749 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 754 | { |
| 755 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 756 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 757 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 758 | } |
| 759 | |
| 760 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 761 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 762 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 763 | } |
| 764 | |
| 765 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 766 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 767 | |
| 768 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 769 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 770 | |
| 771 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 772 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 773 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 774 | if (k->def) { |
| 775 | k->def_uni = true; |
| 776 | k->def_multi = true; |
| 777 | } |
| 778 | if (k->defmgmt) |
| 779 | k->def_multi = true; |
| 780 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 782 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 783 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 787 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 788 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 789 | int err = nla_parse_nested( |
| 790 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 791 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 792 | nl80211_key_default_policy); |
| 793 | if (err) |
| 794 | return err; |
| 795 | |
| 796 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 797 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 798 | } |
| 799 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 804 | { |
| 805 | int err; |
| 806 | |
| 807 | memset(k, 0, sizeof(*k)); |
| 808 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 809 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 810 | |
| 811 | if (info->attrs[NL80211_ATTR_KEY]) |
| 812 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 813 | else |
| 814 | err = nl80211_parse_key_old(info, k); |
| 815 | |
| 816 | if (err) |
| 817 | return err; |
| 818 | |
| 819 | if (k->def && k->defmgmt) |
| 820 | return -EINVAL; |
| 821 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 822 | if (k->defmgmt) { |
| 823 | if (k->def_uni || !k->def_multi) |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 827 | if (k->idx != -1) { |
| 828 | if (k->defmgmt) { |
| 829 | if (k->idx < 4 || k->idx > 5) |
| 830 | return -EINVAL; |
| 831 | } else if (k->def) { |
| 832 | if (k->idx < 0 || k->idx > 3) |
| 833 | return -EINVAL; |
| 834 | } else { |
| 835 | if (k->idx < 0 || k->idx > 5) |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 843 | static struct cfg80211_cached_keys * |
| 844 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 845 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | { |
| 847 | struct key_parse parse; |
| 848 | struct nlattr *key; |
| 849 | struct cfg80211_cached_keys *result; |
| 850 | int rem, err, def = 0; |
| 851 | |
| 852 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 853 | if (!result) |
| 854 | return ERR_PTR(-ENOMEM); |
| 855 | |
| 856 | result->def = -1; |
| 857 | result->defmgmt = -1; |
| 858 | |
| 859 | nla_for_each_nested(key, keys, rem) { |
| 860 | memset(&parse, 0, sizeof(parse)); |
| 861 | parse.idx = -1; |
| 862 | |
| 863 | err = nl80211_parse_key_new(key, &parse); |
| 864 | if (err) |
| 865 | goto error; |
| 866 | err = -EINVAL; |
| 867 | if (!parse.p.key) |
| 868 | goto error; |
| 869 | if (parse.idx < 0 || parse.idx > 4) |
| 870 | goto error; |
| 871 | if (parse.def) { |
| 872 | if (def) |
| 873 | goto error; |
| 874 | def = 1; |
| 875 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 876 | if (!parse.def_uni || !parse.def_multi) |
| 877 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | } else if (parse.defmgmt) |
| 879 | goto error; |
| 880 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 881 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 882 | if (err) |
| 883 | goto error; |
| 884 | result->params[parse.idx].cipher = parse.p.cipher; |
| 885 | result->params[parse.idx].key_len = parse.p.key_len; |
| 886 | result->params[parse.idx].key = result->data[parse.idx]; |
| 887 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 888 | |
| 889 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 890 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 891 | if (no_ht) |
| 892 | *no_ht = true; |
| 893 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | return result; |
| 897 | error: |
| 898 | kfree(result); |
| 899 | return ERR_PTR(err); |
| 900 | } |
| 901 | |
| 902 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 903 | { |
| 904 | ASSERT_WDEV_LOCK(wdev); |
| 905 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 906 | switch (wdev->iftype) { |
| 907 | case NL80211_IFTYPE_AP: |
| 908 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 909 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 910 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 911 | break; |
| 912 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 913 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 914 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 915 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 916 | return -ENOLINK; |
| 917 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 918 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 919 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 920 | case NL80211_IFTYPE_MONITOR: |
| 921 | case NL80211_IFTYPE_P2P_DEVICE: |
| 922 | case NL80211_IFTYPE_WDS: |
| 923 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 924 | return -EINVAL; |
| 925 | } |
| 926 | |
| 927 | return 0; |
| 928 | } |
| 929 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 930 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 931 | struct nlattr *tb) |
| 932 | { |
| 933 | struct ieee80211_channel *chan; |
| 934 | |
| 935 | if (tb == NULL) |
| 936 | return NULL; |
| 937 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 938 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 939 | return NULL; |
| 940 | return chan; |
| 941 | } |
| 942 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 943 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 944 | { |
| 945 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 946 | int i; |
| 947 | |
| 948 | if (!nl_modes) |
| 949 | goto nla_put_failure; |
| 950 | |
| 951 | i = 0; |
| 952 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 953 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 954 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 955 | ifmodes >>= 1; |
| 956 | i++; |
| 957 | } |
| 958 | |
| 959 | nla_nest_end(msg, nl_modes); |
| 960 | return 0; |
| 961 | |
| 962 | nla_put_failure: |
| 963 | return -ENOBUFS; |
| 964 | } |
| 965 | |
| 966 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 967 | struct sk_buff *msg, |
| 968 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 969 | { |
| 970 | struct nlattr *nl_combis; |
| 971 | int i, j; |
| 972 | |
| 973 | nl_combis = nla_nest_start(msg, |
| 974 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 975 | if (!nl_combis) |
| 976 | goto nla_put_failure; |
| 977 | |
| 978 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 979 | const struct ieee80211_iface_combination *c; |
| 980 | struct nlattr *nl_combi, *nl_limits; |
| 981 | |
| 982 | c = &wiphy->iface_combinations[i]; |
| 983 | |
| 984 | nl_combi = nla_nest_start(msg, i + 1); |
| 985 | if (!nl_combi) |
| 986 | goto nla_put_failure; |
| 987 | |
| 988 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 989 | if (!nl_limits) |
| 990 | goto nla_put_failure; |
| 991 | |
| 992 | for (j = 0; j < c->n_limits; j++) { |
| 993 | struct nlattr *nl_limit; |
| 994 | |
| 995 | nl_limit = nla_nest_start(msg, j + 1); |
| 996 | if (!nl_limit) |
| 997 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 998 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 999 | c->limits[j].max)) |
| 1000 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1001 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1002 | c->limits[j].types)) |
| 1003 | goto nla_put_failure; |
| 1004 | nla_nest_end(msg, nl_limit); |
| 1005 | } |
| 1006 | |
| 1007 | nla_nest_end(msg, nl_limits); |
| 1008 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1009 | if (c->beacon_int_infra_match && |
| 1010 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1011 | goto nla_put_failure; |
| 1012 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1013 | c->num_different_channels) || |
| 1014 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1015 | c->max_interfaces)) |
| 1016 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1017 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1018 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1019 | c->radar_detect_widths) || |
| 1020 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1021 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1022 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1023 | |
| 1024 | nla_nest_end(msg, nl_combi); |
| 1025 | } |
| 1026 | |
| 1027 | nla_nest_end(msg, nl_combis); |
| 1028 | |
| 1029 | return 0; |
| 1030 | nla_put_failure: |
| 1031 | return -ENOBUFS; |
| 1032 | } |
| 1033 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1034 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1035 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1036 | struct sk_buff *msg) |
| 1037 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1038 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1039 | struct nlattr *nl_tcp; |
| 1040 | |
| 1041 | if (!tcp) |
| 1042 | return 0; |
| 1043 | |
| 1044 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1045 | if (!nl_tcp) |
| 1046 | return -ENOBUFS; |
| 1047 | |
| 1048 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1049 | tcp->data_payload_max)) |
| 1050 | return -ENOBUFS; |
| 1051 | |
| 1052 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1053 | tcp->data_payload_max)) |
| 1054 | return -ENOBUFS; |
| 1055 | |
| 1056 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1057 | return -ENOBUFS; |
| 1058 | |
| 1059 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1060 | sizeof(*tcp->tok), tcp->tok)) |
| 1061 | return -ENOBUFS; |
| 1062 | |
| 1063 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1064 | tcp->data_interval_max)) |
| 1065 | return -ENOBUFS; |
| 1066 | |
| 1067 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1068 | tcp->wake_payload_max)) |
| 1069 | return -ENOBUFS; |
| 1070 | |
| 1071 | nla_nest_end(msg, nl_tcp); |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1076 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1077 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | { |
| 1079 | struct nlattr *nl_wowlan; |
| 1080 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1081 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1082 | return 0; |
| 1083 | |
| 1084 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1085 | if (!nl_wowlan) |
| 1086 | return -ENOBUFS; |
| 1087 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1088 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1089 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1090 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1091 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1092 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1093 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1094 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1095 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1096 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1097 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1098 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1099 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1100 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1101 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1102 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1103 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1104 | return -ENOBUFS; |
| 1105 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1106 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1107 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1108 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1109 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1110 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1111 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1112 | }; |
| 1113 | |
| 1114 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1115 | sizeof(pat), &pat)) |
| 1116 | return -ENOBUFS; |
| 1117 | } |
| 1118 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1119 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1120 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1121 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1122 | return -ENOBUFS; |
| 1123 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1124 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1125 | return -ENOBUFS; |
| 1126 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1127 | nla_nest_end(msg, nl_wowlan); |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | #endif |
| 1132 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1133 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1134 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1135 | { |
| 1136 | struct nl80211_coalesce_rule_support rule; |
| 1137 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1138 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1139 | return 0; |
| 1140 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1141 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1142 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1143 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1144 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1145 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1146 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1147 | |
| 1148 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1149 | return -ENOBUFS; |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1154 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1155 | struct ieee80211_supported_band *sband) |
| 1156 | { |
| 1157 | struct nlattr *nl_rates, *nl_rate; |
| 1158 | struct ieee80211_rate *rate; |
| 1159 | int i; |
| 1160 | |
| 1161 | /* add HT info */ |
| 1162 | if (sband->ht_cap.ht_supported && |
| 1163 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1164 | sizeof(sband->ht_cap.mcs), |
| 1165 | &sband->ht_cap.mcs) || |
| 1166 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1167 | sband->ht_cap.cap) || |
| 1168 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1169 | sband->ht_cap.ampdu_factor) || |
| 1170 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1171 | sband->ht_cap.ampdu_density))) |
| 1172 | return -ENOBUFS; |
| 1173 | |
| 1174 | /* add VHT info */ |
| 1175 | if (sband->vht_cap.vht_supported && |
| 1176 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1177 | sizeof(sband->vht_cap.vht_mcs), |
| 1178 | &sband->vht_cap.vht_mcs) || |
| 1179 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1180 | sband->vht_cap.cap))) |
| 1181 | return -ENOBUFS; |
| 1182 | |
| 1183 | /* add bitrates */ |
| 1184 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1185 | if (!nl_rates) |
| 1186 | return -ENOBUFS; |
| 1187 | |
| 1188 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1189 | nl_rate = nla_nest_start(msg, i); |
| 1190 | if (!nl_rate) |
| 1191 | return -ENOBUFS; |
| 1192 | |
| 1193 | rate = &sband->bitrates[i]; |
| 1194 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1195 | rate->bitrate)) |
| 1196 | return -ENOBUFS; |
| 1197 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1198 | nla_put_flag(msg, |
| 1199 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1200 | return -ENOBUFS; |
| 1201 | |
| 1202 | nla_nest_end(msg, nl_rate); |
| 1203 | } |
| 1204 | |
| 1205 | nla_nest_end(msg, nl_rates); |
| 1206 | |
| 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | static int |
| 1211 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1212 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1213 | { |
| 1214 | u16 stypes; |
| 1215 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1216 | enum nl80211_iftype ift; |
| 1217 | int i; |
| 1218 | |
| 1219 | if (!mgmt_stypes) |
| 1220 | return 0; |
| 1221 | |
| 1222 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1223 | if (!nl_ifs) |
| 1224 | return -ENOBUFS; |
| 1225 | |
| 1226 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1227 | nl_ftypes = nla_nest_start(msg, ift); |
| 1228 | if (!nl_ftypes) |
| 1229 | return -ENOBUFS; |
| 1230 | i = 0; |
| 1231 | stypes = mgmt_stypes[ift].tx; |
| 1232 | while (stypes) { |
| 1233 | if ((stypes & 1) && |
| 1234 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1235 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1236 | return -ENOBUFS; |
| 1237 | stypes >>= 1; |
| 1238 | i++; |
| 1239 | } |
| 1240 | nla_nest_end(msg, nl_ftypes); |
| 1241 | } |
| 1242 | |
| 1243 | nla_nest_end(msg, nl_ifs); |
| 1244 | |
| 1245 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1246 | if (!nl_ifs) |
| 1247 | return -ENOBUFS; |
| 1248 | |
| 1249 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1250 | nl_ftypes = nla_nest_start(msg, ift); |
| 1251 | if (!nl_ftypes) |
| 1252 | return -ENOBUFS; |
| 1253 | i = 0; |
| 1254 | stypes = mgmt_stypes[ift].rx; |
| 1255 | while (stypes) { |
| 1256 | if ((stypes & 1) && |
| 1257 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1258 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1259 | return -ENOBUFS; |
| 1260 | stypes >>= 1; |
| 1261 | i++; |
| 1262 | } |
| 1263 | nla_nest_end(msg, nl_ftypes); |
| 1264 | } |
| 1265 | nla_nest_end(msg, nl_ifs); |
| 1266 | |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1270 | struct nl80211_dump_wiphy_state { |
| 1271 | s64 filter_wiphy; |
| 1272 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1273 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1274 | bool split; |
| 1275 | }; |
| 1276 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1278 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1280 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1281 | { |
| 1282 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1283 | struct nlattr *nl_bands, *nl_band; |
| 1284 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1285 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1286 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1287 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1288 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1289 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1291 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1292 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1293 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | return -ENOBUFS; |
| 1296 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1297 | if (WARN_ON(!state)) |
| 1298 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1299 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1301 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1303 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1305 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1306 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1307 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1308 | goto finish; |
| 1309 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1310 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | case 0: |
| 1312 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1317 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1319 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1320 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1323 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1325 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1326 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1327 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1328 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1331 | rdev->wiphy.max_match_sets) || |
| 1332 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1333 | rdev->wiphy.max_sched_scan_plans) || |
| 1334 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1335 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1336 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1337 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1338 | goto nla_put_failure; |
| 1339 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1340 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1342 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1343 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1345 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1348 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1349 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1351 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1352 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1354 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1355 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1356 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1357 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1358 | state->split_start++; |
| 1359 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | break; |
| 1361 | case 1: |
| 1362 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1363 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1364 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1365 | goto nla_put_failure; |
| 1366 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1368 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1369 | goto nla_put_failure; |
| 1370 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1373 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1374 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1376 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1377 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1378 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1379 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1380 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1381 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1383 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1385 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1386 | if ((rdev->wiphy.available_antennas_tx || |
| 1387 | rdev->wiphy.available_antennas_rx) && |
| 1388 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1389 | u32 tx_ant = 0, rx_ant = 0; |
| 1390 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1391 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1392 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | if (!res) { |
| 1394 | if (nla_put_u32(msg, |
| 1395 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1396 | tx_ant) || |
| 1397 | nla_put_u32(msg, |
| 1398 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1399 | rx_ant)) |
| 1400 | goto nla_put_failure; |
| 1401 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1404 | state->split_start++; |
| 1405 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1406 | break; |
| 1407 | case 2: |
| 1408 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1409 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1411 | state->split_start++; |
| 1412 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | break; |
| 1414 | case 3: |
| 1415 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1416 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1417 | goto nla_put_failure; |
| 1418 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1419 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1420 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | struct ieee80211_supported_band *sband; |
| 1422 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1423 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | |
| 1425 | if (!sband) |
| 1426 | continue; |
| 1427 | |
| 1428 | nl_band = nla_nest_start(msg, band); |
| 1429 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | goto nla_put_failure; |
| 1431 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1432 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | case 0: |
| 1434 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1435 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | state->chan_start++; |
| 1437 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | break; |
| 1439 | default: |
| 1440 | /* add frequencies */ |
| 1441 | nl_freqs = nla_nest_start( |
| 1442 | msg, NL80211_BAND_ATTR_FREQS); |
| 1443 | if (!nl_freqs) |
| 1444 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1445 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1446 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | i < sband->n_channels; |
| 1448 | i++) { |
| 1449 | nl_freq = nla_nest_start(msg, i); |
| 1450 | if (!nl_freq) |
| 1451 | goto nla_put_failure; |
| 1452 | |
| 1453 | chan = &sband->channels[i]; |
| 1454 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | if (nl80211_msg_put_channel( |
| 1456 | msg, chan, |
| 1457 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | goto nla_put_failure; |
| 1459 | |
| 1460 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1461 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1465 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1467 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | nla_nest_end(msg, nl_freqs); |
| 1469 | } |
| 1470 | |
| 1471 | nla_nest_end(msg, nl_band); |
| 1472 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1473 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1475 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | band--; |
| 1477 | break; |
| 1478 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1479 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1481 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1482 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1483 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1485 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1486 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1488 | if (state->band_start == 0 && state->chan_start == 0) |
| 1489 | state->split_start++; |
| 1490 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | break; |
| 1492 | case 4: |
| 1493 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1494 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1495 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1496 | |
| 1497 | i = 0; |
| 1498 | #define CMD(op, n) \ |
| 1499 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1500 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | i++; \ |
| 1502 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1503 | goto nla_put_failure; \ |
| 1504 | } \ |
| 1505 | } while (0) |
| 1506 | |
| 1507 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1508 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1509 | CMD(add_key, NEW_KEY); |
| 1510 | CMD(start_ap, START_AP); |
| 1511 | CMD(add_station, NEW_STATION); |
| 1512 | CMD(add_mpath, NEW_MPATH); |
| 1513 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1514 | CMD(change_bss, SET_BSS); |
| 1515 | CMD(auth, AUTHENTICATE); |
| 1516 | CMD(assoc, ASSOCIATE); |
| 1517 | CMD(deauth, DEAUTHENTICATE); |
| 1518 | CMD(disassoc, DISASSOCIATE); |
| 1519 | CMD(join_ibss, JOIN_IBSS); |
| 1520 | CMD(join_mesh, JOIN_MESH); |
| 1521 | CMD(set_pmksa, SET_PMKSA); |
| 1522 | CMD(del_pmksa, DEL_PMKSA); |
| 1523 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1526 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1527 | CMD(mgmt_tx, FRAME); |
| 1528 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | i++; |
| 1531 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1532 | goto nla_put_failure; |
| 1533 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1535 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | i++; |
| 1537 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1538 | goto nla_put_failure; |
| 1539 | } |
| 1540 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1541 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1543 | CMD(tdls_oper, TDLS_OPER); |
| 1544 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1545 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1547 | CMD(probe_client, PROBE_CLIENT); |
| 1548 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1549 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | i++; |
| 1551 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1552 | goto nla_put_failure; |
| 1553 | } |
| 1554 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1555 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1556 | #ifdef CONFIG_NL80211_TESTMODE |
| 1557 | CMD(testmode_cmd, TESTMODE); |
| 1558 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1560 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1561 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1562 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1563 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1564 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1565 | if (rdev->wiphy.features & |
| 1566 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1567 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1568 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1569 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1570 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1571 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1572 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | i++; |
| 1574 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1575 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1576 | } |
| 1577 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1579 | i++; |
| 1580 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1581 | goto nla_put_failure; |
| 1582 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1583 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1585 | state->split_start++; |
| 1586 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | break; |
| 1588 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | if (rdev->ops->remain_on_channel && |
| 1590 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | nla_put_u32(msg, |
| 1592 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1594 | goto nla_put_failure; |
| 1595 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1596 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1598 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1599 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1601 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1602 | state->split_start++; |
| 1603 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | break; |
| 1605 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1606 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1609 | state->split_start++; |
| 1610 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1611 | break; |
| 1612 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1613 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | #endif |
| 1615 | case 7: |
| 1616 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1617 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1618 | goto nla_put_failure; |
| 1619 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1620 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1623 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1624 | state->split_start++; |
| 1625 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1626 | break; |
| 1627 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1628 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1630 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1631 | goto nla_put_failure; |
| 1632 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1634 | /* |
| 1635 | * We can only add the per-channel limit information if the |
| 1636 | * dump is split, otherwise it makes it too big. Therefore |
| 1637 | * only advertise it in that case. |
| 1638 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1640 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1641 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1642 | goto nla_put_failure; |
| 1643 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1644 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1645 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1647 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | goto nla_put_failure; |
| 1649 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1650 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1651 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1653 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1654 | goto nla_put_failure; |
| 1655 | |
| 1656 | /* |
| 1657 | * Any information below this point is only available to |
| 1658 | * applications that can deal with it being split. This |
| 1659 | * helps ensure that newly added capabilities don't break |
| 1660 | * older tools by overrunning their buffers. |
| 1661 | * |
| 1662 | * We still increment split_start so that in the split |
| 1663 | * case we'll continue with more data in the next round, |
| 1664 | * but break unconditionally so unsplit data stops here. |
| 1665 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1666 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1667 | break; |
| 1668 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1669 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1670 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1671 | rdev->wiphy.extended_capabilities_len, |
| 1672 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1673 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1674 | rdev->wiphy.extended_capabilities_len, |
| 1675 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1676 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1677 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1678 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1679 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1680 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1681 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1682 | goto nla_put_failure; |
| 1683 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1684 | state->split_start++; |
| 1685 | break; |
| 1686 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1687 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1688 | goto nla_put_failure; |
| 1689 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1691 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1692 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1693 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1694 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1695 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1696 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1697 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1698 | goto nla_put_failure; |
| 1699 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1700 | state->split_start++; |
| 1701 | break; |
| 1702 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1704 | const struct nl80211_vendor_cmd_info *info; |
| 1705 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1706 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1707 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1708 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1709 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1710 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1711 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1712 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1713 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1714 | goto nla_put_failure; |
| 1715 | } |
| 1716 | nla_nest_end(msg, nested); |
| 1717 | } |
| 1718 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1720 | const struct nl80211_vendor_cmd_info *info; |
| 1721 | struct nlattr *nested; |
| 1722 | |
| 1723 | nested = nla_nest_start(msg, |
| 1724 | NL80211_ATTR_VENDOR_EVENTS); |
| 1725 | if (!nested) |
| 1726 | goto nla_put_failure; |
| 1727 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1728 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1729 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1730 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1731 | goto nla_put_failure; |
| 1732 | } |
| 1733 | nla_nest_end(msg, nested); |
| 1734 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1735 | state->split_start++; |
| 1736 | break; |
| 1737 | case 12: |
| 1738 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1739 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1740 | rdev->wiphy.max_num_csa_counters)) |
| 1741 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1742 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1743 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1744 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1745 | goto nla_put_failure; |
| 1746 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1747 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1748 | sizeof(rdev->wiphy.ext_features), |
| 1749 | rdev->wiphy.ext_features)) |
| 1750 | goto nla_put_failure; |
| 1751 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1752 | if (rdev->wiphy.bss_select_support) { |
| 1753 | struct nlattr *nested; |
| 1754 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1755 | |
| 1756 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1757 | if (!nested) |
| 1758 | goto nla_put_failure; |
| 1759 | |
| 1760 | i = 0; |
| 1761 | while (bss_select_support) { |
| 1762 | if ((bss_select_support & 1) && |
| 1763 | nla_put_flag(msg, i)) |
| 1764 | goto nla_put_failure; |
| 1765 | i++; |
| 1766 | bss_select_support >>= 1; |
| 1767 | } |
| 1768 | nla_nest_end(msg, nested); |
| 1769 | } |
| 1770 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1771 | state->split_start++; |
| 1772 | break; |
| 1773 | case 13: |
| 1774 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1775 | rdev->wiphy.iftype_ext_capab) { |
| 1776 | struct nlattr *nested_ext_capab, *nested; |
| 1777 | |
| 1778 | nested = nla_nest_start(msg, |
| 1779 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1780 | if (!nested) |
| 1781 | goto nla_put_failure; |
| 1782 | |
| 1783 | for (i = state->capa_start; |
| 1784 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1785 | const struct wiphy_iftype_ext_capab *capab; |
| 1786 | |
| 1787 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1788 | |
| 1789 | nested_ext_capab = nla_nest_start(msg, i); |
| 1790 | if (!nested_ext_capab || |
| 1791 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1792 | capab->iftype) || |
| 1793 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1794 | capab->extended_capabilities_len, |
| 1795 | capab->extended_capabilities) || |
| 1796 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1797 | capab->extended_capabilities_len, |
| 1798 | capab->extended_capabilities_mask)) |
| 1799 | goto nla_put_failure; |
| 1800 | |
| 1801 | nla_nest_end(msg, nested_ext_capab); |
| 1802 | if (state->split) |
| 1803 | break; |
| 1804 | } |
| 1805 | nla_nest_end(msg, nested); |
| 1806 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1807 | state->capa_start = i + 1; |
| 1808 | break; |
| 1809 | } |
| 1810 | } |
| 1811 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1812 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1813 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1815 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1816 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1817 | genlmsg_end(msg, hdr); |
| 1818 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | |
| 1820 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1821 | genlmsg_cancel(msg, hdr); |
| 1822 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1823 | } |
| 1824 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1825 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1826 | struct netlink_callback *cb, |
| 1827 | struct nl80211_dump_wiphy_state *state) |
| 1828 | { |
| 1829 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1830 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1831 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1832 | /* ignore parse errors for backward compatibility */ |
| 1833 | if (ret) |
| 1834 | return 0; |
| 1835 | |
| 1836 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1837 | if (tb[NL80211_ATTR_WIPHY]) |
| 1838 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1839 | if (tb[NL80211_ATTR_WDEV]) |
| 1840 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1841 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1842 | struct net_device *netdev; |
| 1843 | struct cfg80211_registered_device *rdev; |
| 1844 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1845 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1846 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1847 | if (!netdev) |
| 1848 | return -ENODEV; |
| 1849 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1850 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1851 | netdev->ieee80211_ptr->wiphy); |
| 1852 | state->filter_wiphy = rdev->wiphy_idx; |
| 1853 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1859 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1860 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1861 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1862 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1863 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1864 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1865 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1866 | if (!state) { |
| 1867 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1868 | if (!state) { |
| 1869 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1870 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1871 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1872 | state->filter_wiphy = -1; |
| 1873 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1874 | if (ret) { |
| 1875 | kfree(state); |
| 1876 | rtnl_unlock(); |
| 1877 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1878 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1879 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1882 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1883 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1884 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1885 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1886 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1887 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1888 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1889 | continue; |
| 1890 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1891 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1892 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1893 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1894 | NETLINK_CB(cb->skb).portid, |
| 1895 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1896 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1897 | if (ret < 0) { |
| 1898 | /* |
| 1899 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1900 | * or EMSGSIZE returned), this SKB is still |
| 1901 | * empty (so it's not too big because another |
| 1902 | * wiphy dataset is already in the skb) and |
| 1903 | * we've not tried to adjust the dump allocation |
| 1904 | * yet ... then adjust the alloc size to be |
| 1905 | * bigger, and return 1 but with the empty skb. |
| 1906 | * This results in an empty message being RX'ed |
| 1907 | * in userspace, but that is ignored. |
| 1908 | * |
| 1909 | * We can then retry with the larger buffer. |
| 1910 | */ |
| 1911 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1912 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1913 | cb->min_dump_alloc < 4096) { |
| 1914 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1915 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1916 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1917 | return 1; |
| 1918 | } |
| 1919 | idx--; |
| 1920 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1921 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1922 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1923 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1924 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1925 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1926 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1927 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1928 | |
| 1929 | return skb->len; |
| 1930 | } |
| 1931 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1932 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1933 | { |
| 1934 | kfree((void *)cb->args[0]); |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1938 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1939 | { |
| 1940 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1942 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1943 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1944 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1945 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1946 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1947 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1948 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1949 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1950 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1951 | nlmsg_free(msg); |
| 1952 | return -ENOBUFS; |
| 1953 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1955 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1956 | } |
| 1957 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1958 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1959 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1960 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1961 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1962 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1963 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1964 | }; |
| 1965 | |
| 1966 | static int parse_txq_params(struct nlattr *tb[], |
| 1967 | struct ieee80211_txq_params *txq_params) |
| 1968 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1969 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1970 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1971 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1972 | return -EINVAL; |
| 1973 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1974 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1975 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1976 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1977 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1978 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1979 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1980 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1981 | return -EINVAL; |
| 1982 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1983 | return 0; |
| 1984 | } |
| 1985 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1986 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1987 | { |
| 1988 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1989 | * You can only set the channel explicitly for WDS interfaces, |
| 1990 | * all others have their channel managed via their respective |
| 1991 | * "establish a connection" command (connect, join, ...) |
| 1992 | * |
| 1993 | * For AP/GO and mesh mode, the channel can be set with the |
| 1994 | * channel userspace API, but is only stored and passed to the |
| 1995 | * low-level driver when the AP starts or the mesh is joined. |
| 1996 | * This is for backward compatibility, userspace can also give |
| 1997 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1998 | * |
| 1999 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2000 | * whatever else is going on, so they have their own special |
| 2001 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2002 | */ |
| 2003 | return !wdev || |
| 2004 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2005 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2006 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2007 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2008 | } |
| 2009 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2010 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2011 | struct genl_info *info, |
| 2012 | struct cfg80211_chan_def *chandef) |
| 2013 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2014 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2015 | |
| 2016 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2017 | return -EINVAL; |
| 2018 | |
| 2019 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2020 | |
| 2021 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2022 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2023 | chandef->center_freq1 = control_freq; |
| 2024 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2025 | |
| 2026 | /* Primary channel not allowed */ |
| 2027 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2028 | return -EINVAL; |
| 2029 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2030 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2031 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2032 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2033 | chantype = nla_get_u32( |
| 2034 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2035 | |
| 2036 | switch (chantype) { |
| 2037 | case NL80211_CHAN_NO_HT: |
| 2038 | case NL80211_CHAN_HT20: |
| 2039 | case NL80211_CHAN_HT40PLUS: |
| 2040 | case NL80211_CHAN_HT40MINUS: |
| 2041 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2042 | chantype); |
| 2043 | break; |
| 2044 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2045 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2046 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2047 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2048 | chandef->width = |
| 2049 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2050 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2051 | chandef->center_freq1 = |
| 2052 | nla_get_u32( |
| 2053 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2054 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2055 | chandef->center_freq2 = |
| 2056 | nla_get_u32( |
| 2057 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2058 | } |
| 2059 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2060 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2061 | return -EINVAL; |
| 2062 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2063 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2064 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2065 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2066 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2067 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2068 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2069 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2070 | return -EINVAL; |
| 2071 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2072 | return 0; |
| 2073 | } |
| 2074 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2075 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2076 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2077 | struct genl_info *info) |
| 2078 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2079 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2080 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2081 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2082 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2083 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2084 | if (dev) |
| 2085 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2086 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2087 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2088 | if (wdev) |
| 2089 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2090 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2091 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2092 | if (result) |
| 2093 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2094 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2095 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2096 | case NL80211_IFTYPE_AP: |
| 2097 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2098 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2099 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2100 | result = -EINVAL; |
| 2101 | break; |
| 2102 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2103 | if (wdev->beacon_interval) { |
| 2104 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2105 | !(rdev->wiphy.features & |
| 2106 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2107 | result = -EBUSY; |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | /* Only allow dynamic channel width changes */ |
| 2112 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2113 | result = -EBUSY; |
| 2114 | break; |
| 2115 | } |
| 2116 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2117 | if (result) |
| 2118 | break; |
| 2119 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2120 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2121 | result = 0; |
| 2122 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2123 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2124 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2125 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2126 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2127 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2128 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2129 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2130 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2131 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2132 | |
| 2133 | return result; |
| 2134 | } |
| 2135 | |
| 2136 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2139 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2140 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2141 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2142 | } |
| 2143 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2144 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2145 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2147 | struct net_device *dev = info->user_ptr[1]; |
| 2148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2149 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2150 | |
| 2151 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2152 | return -EINVAL; |
| 2153 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2154 | if (netif_running(dev)) |
| 2155 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2156 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2157 | if (!rdev->ops->set_wds_peer) |
| 2158 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2159 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2160 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2161 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2162 | |
| 2163 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2164 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2167 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2168 | { |
| 2169 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2170 | struct net_device *netdev = NULL; |
| 2171 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2172 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2173 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2174 | u32 changed; |
| 2175 | u8 retry_short = 0, retry_long = 0; |
| 2176 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2177 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2178 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2179 | ASSERT_RTNL(); |
| 2180 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2181 | /* |
| 2182 | * Try to find the wiphy and netdev. Normally this |
| 2183 | * function shouldn't need the netdev, but this is |
| 2184 | * done for backward compatibility -- previously |
| 2185 | * setting the channel was done per wiphy, but now |
| 2186 | * it is per netdev. Previous userland like hostapd |
| 2187 | * also passed a netdev to set_wiphy, so that it is |
| 2188 | * possible to let that go to the right netdev! |
| 2189 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2190 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2191 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2192 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2193 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2194 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2195 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2196 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2197 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2198 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2201 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2202 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2203 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2204 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2205 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2206 | wdev = NULL; |
| 2207 | netdev = NULL; |
| 2208 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2209 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2210 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2211 | |
| 2212 | /* |
| 2213 | * end workaround code, by now the rdev is available |
| 2214 | * and locked, and wdev may or may not be NULL. |
| 2215 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2216 | |
| 2217 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2218 | result = cfg80211_dev_rename( |
| 2219 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2220 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2221 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2222 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2223 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2224 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2225 | struct ieee80211_txq_params txq_params; |
| 2226 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2227 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2228 | if (!rdev->ops->set_txq_params) |
| 2229 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2230 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2231 | if (!netdev) |
| 2232 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2233 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2234 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2235 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2236 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2237 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2238 | if (!netif_running(netdev)) |
| 2239 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2240 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2241 | nla_for_each_nested(nl_txq_params, |
| 2242 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2243 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2244 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2245 | nla_data(nl_txq_params), |
| 2246 | nla_len(nl_txq_params), |
| 2247 | txq_params_policy); |
| 2248 | if (result) |
| 2249 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2250 | result = parse_txq_params(tb, &txq_params); |
| 2251 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2252 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2253 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2254 | result = rdev_set_txq_params(rdev, netdev, |
| 2255 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2256 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2257 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2261 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2262 | result = __nl80211_set_channel( |
| 2263 | rdev, |
| 2264 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2265 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2266 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2267 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2268 | } |
| 2269 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2270 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2271 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2272 | enum nl80211_tx_power_setting type; |
| 2273 | int idx, mbm = 0; |
| 2274 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2275 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2276 | txp_wdev = NULL; |
| 2277 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2278 | if (!rdev->ops->set_tx_power) |
| 2279 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2280 | |
| 2281 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2282 | type = nla_get_u32(info->attrs[idx]); |
| 2283 | |
| 2284 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2285 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2286 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2287 | |
| 2288 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2289 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2290 | mbm = nla_get_u32(info->attrs[idx]); |
| 2291 | } |
| 2292 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2293 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2294 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2295 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2296 | } |
| 2297 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2298 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2299 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2300 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2301 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2302 | if ((!rdev->wiphy.available_antennas_tx && |
| 2303 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2304 | !rdev->ops->set_antenna) |
| 2305 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2306 | |
| 2307 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2308 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2309 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2310 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2311 | * available antenna masks, except for the "all" mask */ |
| 2312 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2313 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2314 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2315 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2316 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2317 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2318 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2319 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2320 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2321 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2322 | } |
| 2323 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2324 | changed = 0; |
| 2325 | |
| 2326 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2327 | retry_short = nla_get_u8( |
| 2328 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | if (retry_short == 0) |
| 2330 | return -EINVAL; |
| 2331 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2332 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2333 | } |
| 2334 | |
| 2335 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2336 | retry_long = nla_get_u8( |
| 2337 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2338 | if (retry_long == 0) |
| 2339 | return -EINVAL; |
| 2340 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2341 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2342 | } |
| 2343 | |
| 2344 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2345 | frag_threshold = nla_get_u32( |
| 2346 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2347 | if (frag_threshold < 256) |
| 2348 | return -EINVAL; |
| 2349 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2350 | if (frag_threshold != (u32) -1) { |
| 2351 | /* |
| 2352 | * Fragments (apart from the last one) are required to |
| 2353 | * have even length. Make the fragmentation code |
| 2354 | * simpler by stripping LSB should someone try to use |
| 2355 | * odd threshold value. |
| 2356 | */ |
| 2357 | frag_threshold &= ~0x1; |
| 2358 | } |
| 2359 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2360 | } |
| 2361 | |
| 2362 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2363 | rts_threshold = nla_get_u32( |
| 2364 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2365 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2366 | } |
| 2367 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2368 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2369 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2370 | return -EINVAL; |
| 2371 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2372 | coverage_class = nla_get_u8( |
| 2373 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2374 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2375 | } |
| 2376 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2377 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2378 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2379 | return -EOPNOTSUPP; |
| 2380 | |
| 2381 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2382 | } |
| 2383 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2384 | if (changed) { |
| 2385 | u8 old_retry_short, old_retry_long; |
| 2386 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2387 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2388 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2389 | if (!rdev->ops->set_wiphy_params) |
| 2390 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2391 | |
| 2392 | old_retry_short = rdev->wiphy.retry_short; |
| 2393 | old_retry_long = rdev->wiphy.retry_long; |
| 2394 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2395 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2396 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2397 | |
| 2398 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2399 | rdev->wiphy.retry_short = retry_short; |
| 2400 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2401 | rdev->wiphy.retry_long = retry_long; |
| 2402 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2403 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2404 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2405 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2406 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2407 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2408 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2409 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2410 | if (result) { |
| 2411 | rdev->wiphy.retry_short = old_retry_short; |
| 2412 | rdev->wiphy.retry_long = old_retry_long; |
| 2413 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2414 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2415 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2416 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2417 | } |
| 2418 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2419 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2422 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2423 | { |
| 2424 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2425 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2426 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2427 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2428 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2429 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2430 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2431 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2432 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2433 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2434 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2435 | chandef->chan->center_freq)) |
| 2436 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2437 | switch (chandef->width) { |
| 2438 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2439 | case NL80211_CHAN_WIDTH_20: |
| 2440 | case NL80211_CHAN_WIDTH_40: |
| 2441 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2442 | cfg80211_get_chandef_type(chandef))) |
| 2443 | return -ENOBUFS; |
| 2444 | break; |
| 2445 | default: |
| 2446 | break; |
| 2447 | } |
| 2448 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2449 | return -ENOBUFS; |
| 2450 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2451 | return -ENOBUFS; |
| 2452 | if (chandef->center_freq2 && |
| 2453 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2454 | return -ENOBUFS; |
| 2455 | return 0; |
| 2456 | } |
| 2457 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2458 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 2459 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2460 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2461 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2462 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2463 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2464 | void *hdr; |
| 2465 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2466 | if (removal) |
| 2467 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2468 | |
| 2469 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2470 | if (!hdr) |
| 2471 | return -1; |
| 2472 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2473 | if (dev && |
| 2474 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2475 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2476 | goto nla_put_failure; |
| 2477 | |
| 2478 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2479 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2480 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2481 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2482 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2483 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2484 | rdev->devlist_generation ^ |
| 2485 | (cfg80211_rdev_list_generation << 2))) |
| 2486 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2487 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2488 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2489 | int ret; |
| 2490 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2491 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2492 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2493 | if (ret == 0) { |
| 2494 | if (nl80211_send_chandef(msg, &chandef)) |
| 2495 | goto nla_put_failure; |
| 2496 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2497 | } |
| 2498 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2499 | if (rdev->ops->get_tx_power) { |
| 2500 | int dbm, ret; |
| 2501 | |
| 2502 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2503 | if (ret == 0 && |
| 2504 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2505 | DBM_TO_MBM(dbm))) |
| 2506 | goto nla_put_failure; |
| 2507 | } |
| 2508 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2509 | if (wdev->ssid_len) { |
| 2510 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2511 | goto nla_put_failure; |
| 2512 | } |
| 2513 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2514 | genlmsg_end(msg, hdr); |
| 2515 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | |
| 2517 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2518 | genlmsg_cancel(msg, hdr); |
| 2519 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2523 | { |
| 2524 | int wp_idx = 0; |
| 2525 | int if_idx = 0; |
| 2526 | int wp_start = cb->args[0]; |
| 2527 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2528 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2529 | struct wireless_dev *wdev; |
| 2530 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2531 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2532 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2533 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2534 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2535 | if (wp_idx < wp_start) { |
| 2536 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2537 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2538 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2539 | if_idx = 0; |
| 2540 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2541 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2542 | if (if_idx < if_start) { |
| 2543 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2544 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2545 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2546 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2547 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2548 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2549 | goto out; |
| 2550 | } |
| 2551 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2552 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2553 | |
| 2554 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2555 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2556 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2557 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2558 | |
| 2559 | cb->args[0] = wp_idx; |
| 2560 | cb->args[1] = if_idx; |
| 2561 | |
| 2562 | return skb->len; |
| 2563 | } |
| 2564 | |
| 2565 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2566 | { |
| 2567 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2569 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2570 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2572 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2574 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2575 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2576 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2577 | nlmsg_free(msg); |
| 2578 | return -ENOBUFS; |
| 2579 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2580 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2581 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2582 | } |
| 2583 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2584 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2585 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2586 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2587 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2588 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2589 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2590 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2594 | { |
| 2595 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2596 | int flag; |
| 2597 | |
| 2598 | *mntrflags = 0; |
| 2599 | |
| 2600 | if (!nla) |
| 2601 | return -EINVAL; |
| 2602 | |
| 2603 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2604 | nla, mntr_flags_policy)) |
| 2605 | return -EINVAL; |
| 2606 | |
| 2607 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2608 | if (flags[flag]) |
| 2609 | *mntrflags |= (1<<flag); |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2614 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2615 | struct net_device *netdev, u8 use_4addr, |
| 2616 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2617 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2618 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2619 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2620 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2621 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2622 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2623 | |
| 2624 | switch (iftype) { |
| 2625 | case NL80211_IFTYPE_AP_VLAN: |
| 2626 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2627 | return 0; |
| 2628 | break; |
| 2629 | case NL80211_IFTYPE_STATION: |
| 2630 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2631 | return 0; |
| 2632 | break; |
| 2633 | default: |
| 2634 | break; |
| 2635 | } |
| 2636 | |
| 2637 | return -EOPNOTSUPP; |
| 2638 | } |
| 2639 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2640 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2641 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2643 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2644 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2645 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2646 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2647 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2648 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2649 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2650 | memset(¶ms, 0, sizeof(params)); |
| 2651 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2652 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2653 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2654 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2655 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2656 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2657 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2658 | if (ntype > NL80211_IFTYPE_MAX) |
| 2659 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2660 | } |
| 2661 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2662 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2663 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2664 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2666 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2667 | if (netif_running(dev)) |
| 2668 | return -EBUSY; |
| 2669 | |
| 2670 | wdev_lock(wdev); |
| 2671 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2672 | IEEE80211_MAX_MESH_ID_LEN); |
| 2673 | wdev->mesh_id_up_len = |
| 2674 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2675 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2676 | wdev->mesh_id_up_len); |
| 2677 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2678 | } |
| 2679 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2680 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2681 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2682 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2683 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2684 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2685 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2686 | } else { |
| 2687 | params.use_4addr = -1; |
| 2688 | } |
| 2689 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2690 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2692 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2693 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2694 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2695 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2696 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2697 | |
| 2698 | flags = &_flags; |
| 2699 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2700 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2701 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2702 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2703 | const u8 *mumimo_groups; |
| 2704 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2705 | |
| 2706 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2707 | return -EOPNOTSUPP; |
| 2708 | |
| 2709 | mumimo_groups = |
| 2710 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2711 | |
| 2712 | /* bits 0 and 63 are reserved and must be zero */ |
| 2713 | if ((mumimo_groups[0] & BIT(7)) || |
| 2714 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2715 | return -EINVAL; |
| 2716 | |
| 2717 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2718 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2719 | change = true; |
| 2720 | } |
| 2721 | |
| 2722 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2723 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2724 | |
| 2725 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2726 | return -EOPNOTSUPP; |
| 2727 | |
| 2728 | nla_memcpy(params.macaddr, |
| 2729 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2730 | ETH_ALEN); |
| 2731 | change = true; |
| 2732 | } |
| 2733 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2734 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2735 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2736 | return -EOPNOTSUPP; |
| 2737 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2738 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2739 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2740 | else |
| 2741 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2742 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2743 | if (!err && params.use_4addr != -1) |
| 2744 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2745 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2746 | return err; |
| 2747 | } |
| 2748 | |
| 2749 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2750 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2752 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2753 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2754 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2755 | int err; |
| 2756 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2757 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2758 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2759 | /* to avoid failing a new interface creation due to pending removal */ |
| 2760 | cfg80211_destroy_ifaces(rdev); |
| 2761 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2762 | memset(¶ms, 0, sizeof(params)); |
| 2763 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2764 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2765 | return -EINVAL; |
| 2766 | |
| 2767 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2768 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2769 | if (type > NL80211_IFTYPE_MAX) |
| 2770 | return -EINVAL; |
| 2771 | } |
| 2772 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2773 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2775 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2776 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2777 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2778 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2779 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2780 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2781 | ETH_ALEN); |
| 2782 | if (!is_valid_ether_addr(params.macaddr)) |
| 2783 | return -EADDRNOTAVAIL; |
| 2784 | } |
| 2785 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2786 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2787 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2788 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2789 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2790 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2791 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2792 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2793 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2794 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2795 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2796 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2797 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2798 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2799 | return -EOPNOTSUPP; |
| 2800 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2802 | if (!msg) |
| 2803 | return -ENOMEM; |
| 2804 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2805 | wdev = rdev_add_virtual_intf(rdev, |
| 2806 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2807 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2808 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2809 | if (WARN_ON(!wdev)) { |
| 2810 | nlmsg_free(msg); |
| 2811 | return -EPROTO; |
| 2812 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2813 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2814 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2815 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2816 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2817 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2818 | wdev->owner_nlportid = info->snd_portid; |
| 2819 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2820 | switch (type) { |
| 2821 | case NL80211_IFTYPE_MESH_POINT: |
| 2822 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2823 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2824 | wdev_lock(wdev); |
| 2825 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2826 | IEEE80211_MAX_MESH_ID_LEN); |
| 2827 | wdev->mesh_id_up_len = |
| 2828 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2829 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2830 | wdev->mesh_id_up_len); |
| 2831 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2832 | break; |
| 2833 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2834 | /* |
| 2835 | * P2P Device doesn't have a netdev, so doesn't go |
| 2836 | * through the netdev notifier and must be added here |
| 2837 | */ |
| 2838 | mutex_init(&wdev->mtx); |
| 2839 | INIT_LIST_HEAD(&wdev->event_list); |
| 2840 | spin_lock_init(&wdev->event_lock); |
| 2841 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2842 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2843 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2844 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2845 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2846 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2847 | break; |
| 2848 | default: |
| 2849 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2850 | } |
| 2851 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2852 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2853 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2854 | nlmsg_free(msg); |
| 2855 | return -ENOBUFS; |
| 2856 | } |
| 2857 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2858 | /* |
| 2859 | * For wdevs which have no associated netdev object (e.g. of type |
| 2860 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2861 | * For all other types, the event will be generated from the |
| 2862 | * netdev notifier |
| 2863 | */ |
| 2864 | if (!wdev->netdev) |
| 2865 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2866 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2867 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2871 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2873 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2874 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | if (!rdev->ops->del_virtual_intf) |
| 2876 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2877 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2878 | /* |
| 2879 | * If we remove a wireless device without a netdev then clear |
| 2880 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2881 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2882 | * since the wdev has been freed, unlike with a netdev where |
| 2883 | * we need the dev_put() for the netdev to really be freed. |
| 2884 | */ |
| 2885 | if (!wdev->netdev) |
| 2886 | info->user_ptr[1] = NULL; |
| 2887 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 2888 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2889 | } |
| 2890 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2891 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2892 | { |
| 2893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2894 | struct net_device *dev = info->user_ptr[1]; |
| 2895 | u16 noack_map; |
| 2896 | |
| 2897 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2898 | return -EINVAL; |
| 2899 | |
| 2900 | if (!rdev->ops->set_noack_map) |
| 2901 | return -EOPNOTSUPP; |
| 2902 | |
| 2903 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2904 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2905 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2906 | } |
| 2907 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2908 | struct get_key_cookie { |
| 2909 | struct sk_buff *msg; |
| 2910 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2911 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2912 | }; |
| 2913 | |
| 2914 | static void get_key_callback(void *c, struct key_params *params) |
| 2915 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2916 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2917 | struct get_key_cookie *cookie = c; |
| 2918 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2919 | if ((params->key && |
| 2920 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2921 | params->key_len, params->key)) || |
| 2922 | (params->seq && |
| 2923 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2924 | params->seq_len, params->seq)) || |
| 2925 | (params->cipher && |
| 2926 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2927 | params->cipher))) |
| 2928 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2930 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2931 | if (!key) |
| 2932 | goto nla_put_failure; |
| 2933 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2934 | if ((params->key && |
| 2935 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2936 | params->key_len, params->key)) || |
| 2937 | (params->seq && |
| 2938 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2939 | params->seq_len, params->seq)) || |
| 2940 | (params->cipher && |
| 2941 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2942 | params->cipher))) |
| 2943 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2944 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2945 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2946 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2947 | |
| 2948 | nla_nest_end(cookie->msg, key); |
| 2949 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2950 | return; |
| 2951 | nla_put_failure: |
| 2952 | cookie->error = 1; |
| 2953 | } |
| 2954 | |
| 2955 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2956 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2958 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2959 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2960 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2961 | const u8 *mac_addr = NULL; |
| 2962 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2963 | struct get_key_cookie cookie = { |
| 2964 | .error = 0, |
| 2965 | }; |
| 2966 | void *hdr; |
| 2967 | struct sk_buff *msg; |
| 2968 | |
| 2969 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2970 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2971 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2972 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2973 | return -EINVAL; |
| 2974 | |
| 2975 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2976 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2977 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2978 | pairwise = !!mac_addr; |
| 2979 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2980 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2981 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2982 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2983 | return -EINVAL; |
| 2984 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2985 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2986 | return -EINVAL; |
| 2987 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2988 | } |
| 2989 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2990 | if (!rdev->ops->get_key) |
| 2991 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2992 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 2993 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2994 | return -ENOENT; |
| 2995 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2997 | if (!msg) |
| 2998 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2999 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3000 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3001 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3002 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3003 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3004 | |
| 3005 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3006 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3008 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3009 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3010 | goto nla_put_failure; |
| 3011 | if (mac_addr && |
| 3012 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3013 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3014 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3015 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3016 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3017 | |
| 3018 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3019 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3020 | |
| 3021 | if (cookie.error) |
| 3022 | goto nla_put_failure; |
| 3023 | |
| 3024 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3025 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3026 | |
| 3027 | nla_put_failure: |
| 3028 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3029 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3030 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3031 | return err; |
| 3032 | } |
| 3033 | |
| 3034 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3037 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3038 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3039 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3040 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3041 | err = nl80211_parse_key(info, &key); |
| 3042 | if (err) |
| 3043 | return err; |
| 3044 | |
| 3045 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3046 | return -EINVAL; |
| 3047 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3048 | /* only support setting default key */ |
| 3049 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3050 | return -EINVAL; |
| 3051 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3052 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3053 | |
| 3054 | if (key.def) { |
| 3055 | if (!rdev->ops->set_default_key) { |
| 3056 | err = -EOPNOTSUPP; |
| 3057 | goto out; |
| 3058 | } |
| 3059 | |
| 3060 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3061 | if (err) |
| 3062 | goto out; |
| 3063 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3064 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3065 | key.def_uni, key.def_multi); |
| 3066 | |
| 3067 | if (err) |
| 3068 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3069 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3070 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3071 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3072 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3073 | } else { |
| 3074 | if (key.def_uni || !key.def_multi) { |
| 3075 | err = -EINVAL; |
| 3076 | goto out; |
| 3077 | } |
| 3078 | |
| 3079 | if (!rdev->ops->set_default_mgmt_key) { |
| 3080 | err = -EOPNOTSUPP; |
| 3081 | goto out; |
| 3082 | } |
| 3083 | |
| 3084 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3085 | if (err) |
| 3086 | goto out; |
| 3087 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3088 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3089 | if (err) |
| 3090 | goto out; |
| 3091 | |
| 3092 | #ifdef CONFIG_CFG80211_WEXT |
| 3093 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3094 | #endif |
| 3095 | } |
| 3096 | |
| 3097 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3098 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3099 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3100 | return err; |
| 3101 | } |
| 3102 | |
| 3103 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3106 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3107 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3108 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3109 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3110 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3111 | err = nl80211_parse_key(info, &key); |
| 3112 | if (err) |
| 3113 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3114 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3115 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3116 | return -EINVAL; |
| 3117 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3118 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3119 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3120 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3121 | if (key.type == -1) { |
| 3122 | if (mac_addr) |
| 3123 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3124 | else |
| 3125 | key.type = NL80211_KEYTYPE_GROUP; |
| 3126 | } |
| 3127 | |
| 3128 | /* for now */ |
| 3129 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3130 | key.type != NL80211_KEYTYPE_GROUP) |
| 3131 | return -EINVAL; |
| 3132 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3133 | if (!rdev->ops->add_key) |
| 3134 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3135 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3136 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3137 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3138 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3139 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3140 | |
| 3141 | wdev_lock(dev->ieee80211_ptr); |
| 3142 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3143 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3144 | err = rdev_add_key(rdev, dev, key.idx, |
| 3145 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3146 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3147 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3148 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3149 | return err; |
| 3150 | } |
| 3151 | |
| 3152 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3155 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3156 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3157 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3158 | struct key_parse key; |
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 | err = nl80211_parse_key(info, &key); |
| 3161 | if (err) |
| 3162 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3163 | |
| 3164 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3165 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3166 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3167 | if (key.type == -1) { |
| 3168 | if (mac_addr) |
| 3169 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3170 | else |
| 3171 | key.type = NL80211_KEYTYPE_GROUP; |
| 3172 | } |
| 3173 | |
| 3174 | /* for now */ |
| 3175 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3176 | key.type != NL80211_KEYTYPE_GROUP) |
| 3177 | return -EINVAL; |
| 3178 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3179 | if (!rdev->ops->del_key) |
| 3180 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3181 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3182 | wdev_lock(dev->ieee80211_ptr); |
| 3183 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3184 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3185 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3186 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3187 | err = -ENOENT; |
| 3188 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3189 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3190 | err = rdev_del_key(rdev, dev, key.idx, |
| 3191 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3192 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3193 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3194 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3195 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3196 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3197 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3198 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3199 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3200 | } |
| 3201 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3202 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3203 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3204 | return err; |
| 3205 | } |
| 3206 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3207 | /* This function returns an error or the number of nested attributes */ |
| 3208 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3209 | { |
| 3210 | struct nlattr *attr; |
| 3211 | int n_entries = 0, tmp; |
| 3212 | |
| 3213 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3214 | if (nla_len(attr) != ETH_ALEN) |
| 3215 | return -EINVAL; |
| 3216 | |
| 3217 | n_entries++; |
| 3218 | } |
| 3219 | |
| 3220 | return n_entries; |
| 3221 | } |
| 3222 | |
| 3223 | /* |
| 3224 | * This function parses ACL information and allocates memory for ACL data. |
| 3225 | * On successful return, the calling function is responsible to free the |
| 3226 | * ACL buffer returned by this function. |
| 3227 | */ |
| 3228 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3229 | struct genl_info *info) |
| 3230 | { |
| 3231 | enum nl80211_acl_policy acl_policy; |
| 3232 | struct nlattr *attr; |
| 3233 | struct cfg80211_acl_data *acl; |
| 3234 | int i = 0, n_entries, tmp; |
| 3235 | |
| 3236 | if (!wiphy->max_acl_mac_addrs) |
| 3237 | return ERR_PTR(-EOPNOTSUPP); |
| 3238 | |
| 3239 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3240 | return ERR_PTR(-EINVAL); |
| 3241 | |
| 3242 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3243 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3244 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3245 | return ERR_PTR(-EINVAL); |
| 3246 | |
| 3247 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3248 | return ERR_PTR(-EINVAL); |
| 3249 | |
| 3250 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3251 | if (n_entries < 0) |
| 3252 | return ERR_PTR(n_entries); |
| 3253 | |
| 3254 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3255 | return ERR_PTR(-ENOTSUPP); |
| 3256 | |
| 3257 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3258 | GFP_KERNEL); |
| 3259 | if (!acl) |
| 3260 | return ERR_PTR(-ENOMEM); |
| 3261 | |
| 3262 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3263 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3264 | i++; |
| 3265 | } |
| 3266 | |
| 3267 | acl->n_acl_entries = n_entries; |
| 3268 | acl->acl_policy = acl_policy; |
| 3269 | |
| 3270 | return acl; |
| 3271 | } |
| 3272 | |
| 3273 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3274 | { |
| 3275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3276 | struct net_device *dev = info->user_ptr[1]; |
| 3277 | struct cfg80211_acl_data *acl; |
| 3278 | int err; |
| 3279 | |
| 3280 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3281 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3282 | return -EOPNOTSUPP; |
| 3283 | |
| 3284 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3285 | return -EINVAL; |
| 3286 | |
| 3287 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3288 | if (IS_ERR(acl)) |
| 3289 | return PTR_ERR(acl); |
| 3290 | |
| 3291 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3292 | |
| 3293 | kfree(acl); |
| 3294 | |
| 3295 | return err; |
| 3296 | } |
| 3297 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3298 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3299 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3300 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3301 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3302 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3303 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3304 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3305 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3306 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3307 | return -EINVAL; |
| 3308 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3309 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3310 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3311 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3312 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3313 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3314 | if (!bcn->head_len) |
| 3315 | return -EINVAL; |
| 3316 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3317 | } |
| 3318 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3319 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3320 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3321 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3322 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3323 | } |
| 3324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3325 | if (!haveinfo) |
| 3326 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3327 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3328 | if (attrs[NL80211_ATTR_IE]) { |
| 3329 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3330 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3331 | } |
| 3332 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3333 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3334 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3335 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3336 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3337 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3338 | } |
| 3339 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3340 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3341 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3342 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3343 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3344 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3345 | } |
| 3346 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3347 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3348 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3349 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3350 | } |
| 3351 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3352 | return 0; |
| 3353 | } |
| 3354 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3355 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3356 | struct cfg80211_ap_settings *params) |
| 3357 | { |
| 3358 | struct wireless_dev *wdev; |
| 3359 | bool ret = false; |
| 3360 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3361 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3362 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3363 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3364 | continue; |
| 3365 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3366 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3367 | continue; |
| 3368 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3369 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3370 | ret = true; |
| 3371 | break; |
| 3372 | } |
| 3373 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3374 | return ret; |
| 3375 | } |
| 3376 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3377 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3378 | enum nl80211_auth_type auth_type, |
| 3379 | enum nl80211_commands cmd) |
| 3380 | { |
| 3381 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3382 | return false; |
| 3383 | |
| 3384 | switch (cmd) { |
| 3385 | case NL80211_CMD_AUTHENTICATE: |
| 3386 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3387 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3388 | return false; |
| 3389 | return true; |
| 3390 | case NL80211_CMD_CONNECT: |
| 3391 | case NL80211_CMD_START_AP: |
| 3392 | /* SAE not supported yet */ |
| 3393 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3394 | return false; |
| 3395 | return true; |
| 3396 | default: |
| 3397 | return false; |
| 3398 | } |
| 3399 | } |
| 3400 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3401 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3402 | { |
| 3403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3404 | struct net_device *dev = info->user_ptr[1]; |
| 3405 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3406 | struct cfg80211_ap_settings params; |
| 3407 | int err; |
| 3408 | |
| 3409 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3410 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3411 | return -EOPNOTSUPP; |
| 3412 | |
| 3413 | if (!rdev->ops->start_ap) |
| 3414 | return -EOPNOTSUPP; |
| 3415 | |
| 3416 | if (wdev->beacon_interval) |
| 3417 | return -EALREADY; |
| 3418 | |
| 3419 | memset(¶ms, 0, sizeof(params)); |
| 3420 | |
| 3421 | /* these are required for START_AP */ |
| 3422 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3423 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3424 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3425 | return -EINVAL; |
| 3426 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3427 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3428 | if (err) |
| 3429 | return err; |
| 3430 | |
| 3431 | params.beacon_interval = |
| 3432 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3433 | params.dtim_period = |
| 3434 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3435 | |
| 3436 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3437 | if (err) |
| 3438 | return err; |
| 3439 | |
| 3440 | /* |
| 3441 | * In theory, some of these attributes should be required here |
| 3442 | * but since they were not used when the command was originally |
| 3443 | * added, keep them optional for old user space programs to let |
| 3444 | * them continue to work with drivers that do not need the |
| 3445 | * additional information -- drivers must check! |
| 3446 | */ |
| 3447 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3448 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3449 | params.ssid_len = |
| 3450 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3451 | if (params.ssid_len == 0 || |
| 3452 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3453 | return -EINVAL; |
| 3454 | } |
| 3455 | |
| 3456 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3457 | params.hidden_ssid = nla_get_u32( |
| 3458 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3459 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3460 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3461 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3462 | return -EINVAL; |
| 3463 | } |
| 3464 | |
| 3465 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3466 | |
| 3467 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3468 | params.auth_type = nla_get_u32( |
| 3469 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3470 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3471 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3472 | return -EINVAL; |
| 3473 | } else |
| 3474 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3475 | |
| 3476 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3477 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3478 | if (err) |
| 3479 | return err; |
| 3480 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3481 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3482 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3483 | return -EOPNOTSUPP; |
| 3484 | params.inactivity_timeout = nla_get_u16( |
| 3485 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3486 | } |
| 3487 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3488 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3489 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3490 | return -EINVAL; |
| 3491 | params.p2p_ctwindow = |
| 3492 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3493 | if (params.p2p_ctwindow > 127) |
| 3494 | return -EINVAL; |
| 3495 | if (params.p2p_ctwindow != 0 && |
| 3496 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3497 | return -EINVAL; |
| 3498 | } |
| 3499 | |
| 3500 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3501 | u8 tmp; |
| 3502 | |
| 3503 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3504 | return -EINVAL; |
| 3505 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3506 | if (tmp > 1) |
| 3507 | return -EINVAL; |
| 3508 | params.p2p_opp_ps = tmp; |
| 3509 | if (params.p2p_opp_ps != 0 && |
| 3510 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3511 | return -EINVAL; |
| 3512 | } |
| 3513 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3514 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3515 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3516 | if (err) |
| 3517 | return err; |
| 3518 | } else if (wdev->preset_chandef.chan) { |
| 3519 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3520 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3521 | return -EINVAL; |
| 3522 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3523 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3524 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3525 | return -EINVAL; |
| 3526 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3527 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3528 | params.smps_mode = |
| 3529 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3530 | switch (params.smps_mode) { |
| 3531 | case NL80211_SMPS_OFF: |
| 3532 | break; |
| 3533 | case NL80211_SMPS_STATIC: |
| 3534 | if (!(rdev->wiphy.features & |
| 3535 | NL80211_FEATURE_STATIC_SMPS)) |
| 3536 | return -EINVAL; |
| 3537 | break; |
| 3538 | case NL80211_SMPS_DYNAMIC: |
| 3539 | if (!(rdev->wiphy.features & |
| 3540 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3541 | return -EINVAL; |
| 3542 | break; |
| 3543 | default: |
| 3544 | return -EINVAL; |
| 3545 | } |
| 3546 | } else { |
| 3547 | params.smps_mode = NL80211_SMPS_OFF; |
| 3548 | } |
| 3549 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3550 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3551 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3552 | return -EOPNOTSUPP; |
| 3553 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3554 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3555 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3556 | if (IS_ERR(params.acl)) |
| 3557 | return PTR_ERR(params.acl); |
| 3558 | } |
| 3559 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3560 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3561 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3562 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3563 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3564 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3565 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3566 | wdev->ssid_len = params.ssid_len; |
| 3567 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3568 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3569 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3570 | |
| 3571 | kfree(params.acl); |
| 3572 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3573 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3574 | } |
| 3575 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3576 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3577 | { |
| 3578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3579 | struct net_device *dev = info->user_ptr[1]; |
| 3580 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3581 | struct cfg80211_beacon_data params; |
| 3582 | int err; |
| 3583 | |
| 3584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3585 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3586 | return -EOPNOTSUPP; |
| 3587 | |
| 3588 | if (!rdev->ops->change_beacon) |
| 3589 | return -EOPNOTSUPP; |
| 3590 | |
| 3591 | if (!wdev->beacon_interval) |
| 3592 | return -EINVAL; |
| 3593 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3594 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3595 | if (err) |
| 3596 | return err; |
| 3597 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3598 | wdev_lock(wdev); |
| 3599 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3600 | wdev_unlock(wdev); |
| 3601 | |
| 3602 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | 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] | 3606 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3608 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3609 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3610 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3611 | } |
| 3612 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3613 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3614 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3615 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3616 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3617 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3618 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3619 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3620 | }; |
| 3621 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3622 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3623 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3624 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3625 | { |
| 3626 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3627 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3628 | int flag; |
| 3629 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3630 | /* |
| 3631 | * Try parsing the new attribute first so userspace |
| 3632 | * can specify both for older kernels. |
| 3633 | */ |
| 3634 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3635 | if (nla) { |
| 3636 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3637 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3638 | sta_flags = nla_data(nla); |
| 3639 | params->sta_flags_mask = sta_flags->mask; |
| 3640 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3641 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3642 | if ((params->sta_flags_mask | |
| 3643 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3644 | return -EINVAL; |
| 3645 | return 0; |
| 3646 | } |
| 3647 | |
| 3648 | /* if present, parse the old attribute */ |
| 3649 | |
| 3650 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3651 | if (!nla) |
| 3652 | return 0; |
| 3653 | |
| 3654 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3655 | nla, sta_flags_policy)) |
| 3656 | return -EINVAL; |
| 3657 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3658 | /* |
| 3659 | * Only allow certain flags for interface types so that |
| 3660 | * other attributes are silently ignored. Remember that |
| 3661 | * this is backward compatibility code with old userspace |
| 3662 | * and shouldn't be hit in other cases anyway. |
| 3663 | */ |
| 3664 | switch (iftype) { |
| 3665 | case NL80211_IFTYPE_AP: |
| 3666 | case NL80211_IFTYPE_AP_VLAN: |
| 3667 | case NL80211_IFTYPE_P2P_GO: |
| 3668 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3669 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3670 | BIT(NL80211_STA_FLAG_WME) | |
| 3671 | BIT(NL80211_STA_FLAG_MFP); |
| 3672 | break; |
| 3673 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3674 | case NL80211_IFTYPE_STATION: |
| 3675 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3676 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3677 | break; |
| 3678 | case NL80211_IFTYPE_MESH_POINT: |
| 3679 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3680 | BIT(NL80211_STA_FLAG_MFP) | |
| 3681 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3682 | default: |
| 3683 | return -EINVAL; |
| 3684 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3685 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3686 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3687 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3688 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3689 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3690 | /* no longer support new API additions in old API */ |
| 3691 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3692 | return -EINVAL; |
| 3693 | } |
| 3694 | } |
| 3695 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3696 | return 0; |
| 3697 | } |
| 3698 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3699 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3700 | int attr) |
| 3701 | { |
| 3702 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3703 | u32 bitrate; |
| 3704 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3705 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3706 | |
| 3707 | rate = nla_nest_start(msg, attr); |
| 3708 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3709 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3710 | |
| 3711 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3712 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3713 | /* report 16-bit bitrate only if we can */ |
| 3714 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3715 | if (bitrate > 0 && |
| 3716 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3717 | return false; |
| 3718 | if (bitrate_compat > 0 && |
| 3719 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3720 | return false; |
| 3721 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 3722 | switch (info->bw) { |
| 3723 | case RATE_INFO_BW_5: |
| 3724 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 3725 | break; |
| 3726 | case RATE_INFO_BW_10: |
| 3727 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 3728 | break; |
| 3729 | default: |
| 3730 | WARN_ON(1); |
| 3731 | /* fall through */ |
| 3732 | case RATE_INFO_BW_20: |
| 3733 | rate_flg = 0; |
| 3734 | break; |
| 3735 | case RATE_INFO_BW_40: |
| 3736 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 3737 | break; |
| 3738 | case RATE_INFO_BW_80: |
| 3739 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 3740 | break; |
| 3741 | case RATE_INFO_BW_160: |
| 3742 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 3743 | break; |
| 3744 | } |
| 3745 | |
| 3746 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 3747 | return false; |
| 3748 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3749 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3750 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3751 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3752 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3753 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3754 | return false; |
| 3755 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3756 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3757 | return false; |
| 3758 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3759 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3760 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3761 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3762 | return false; |
| 3763 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3764 | |
| 3765 | nla_nest_end(msg, rate); |
| 3766 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3767 | } |
| 3768 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3769 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3770 | int id) |
| 3771 | { |
| 3772 | void *attr; |
| 3773 | int i = 0; |
| 3774 | |
| 3775 | if (!mask) |
| 3776 | return true; |
| 3777 | |
| 3778 | attr = nla_nest_start(msg, id); |
| 3779 | if (!attr) |
| 3780 | return false; |
| 3781 | |
| 3782 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3783 | if (!(mask & BIT(i))) |
| 3784 | continue; |
| 3785 | |
| 3786 | if (nla_put_u8(msg, i, signal[i])) |
| 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | nla_nest_end(msg, attr); |
| 3791 | |
| 3792 | return true; |
| 3793 | } |
| 3794 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3795 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 3796 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3797 | struct cfg80211_registered_device *rdev, |
| 3798 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3799 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3800 | { |
| 3801 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3802 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3803 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 3804 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3805 | if (!hdr) |
| 3806 | return -1; |
| 3807 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3808 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3809 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3810 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3811 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3812 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3813 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3814 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3815 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3816 | |
| 3817 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3818 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 3819 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3820 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 3821 | sinfo->memb)) \ |
| 3822 | goto nla_put_failure; \ |
| 3823 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3824 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 3825 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 3826 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 3827 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 3828 | goto nla_put_failure; \ |
| 3829 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3830 | |
| 3831 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 3832 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 3833 | |
| 3834 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 3835 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3836 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3837 | (u32)sinfo->rx_bytes)) |
| 3838 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3839 | |
| 3840 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 3841 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3842 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3843 | (u32)sinfo->tx_bytes)) |
| 3844 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3845 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3846 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 3847 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3848 | PUT_SINFO(LLID, llid, u16); |
| 3849 | PUT_SINFO(PLID, plid, u16); |
| 3850 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3851 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3852 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3853 | switch (rdev->wiphy.signal_type) { |
| 3854 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3855 | PUT_SINFO(SIGNAL, signal, u8); |
| 3856 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3857 | break; |
| 3858 | default: |
| 3859 | break; |
| 3860 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3861 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3862 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3863 | sinfo->chain_signal, |
| 3864 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3865 | goto nla_put_failure; |
| 3866 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3867 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3868 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3869 | sinfo->chain_signal_avg, |
| 3870 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3871 | goto nla_put_failure; |
| 3872 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3873 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3874 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3875 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3876 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3877 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3878 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3879 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3880 | NL80211_STA_INFO_RX_BITRATE)) |
| 3881 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3882 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3883 | |
| 3884 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 3885 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 3886 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 3887 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 3888 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 3889 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 3890 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 3891 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 3892 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 3893 | |
| 3894 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3895 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3896 | if (!bss_param) |
| 3897 | goto nla_put_failure; |
| 3898 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3899 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3900 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3901 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3902 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3903 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3904 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3905 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3906 | sinfo->bss_param.dtim_period) || |
| 3907 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3908 | sinfo->bss_param.beacon_interval)) |
| 3909 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3910 | |
| 3911 | nla_nest_end(msg, bss_param); |
| 3912 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3913 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3914 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3915 | sizeof(struct nl80211_sta_flag_update), |
| 3916 | &sinfo->sta_flags)) |
| 3917 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3918 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3919 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 3920 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 3921 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 3922 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3923 | |
| 3924 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3925 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3926 | |
| 3927 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 3928 | struct nlattr *tidsattr; |
| 3929 | int tid; |
| 3930 | |
| 3931 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 3932 | if (!tidsattr) |
| 3933 | goto nla_put_failure; |
| 3934 | |
| 3935 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 3936 | struct cfg80211_tid_stats *tidstats; |
| 3937 | struct nlattr *tidattr; |
| 3938 | |
| 3939 | tidstats = &sinfo->pertid[tid]; |
| 3940 | |
| 3941 | if (!tidstats->filled) |
| 3942 | continue; |
| 3943 | |
| 3944 | tidattr = nla_nest_start(msg, tid + 1); |
| 3945 | if (!tidattr) |
| 3946 | goto nla_put_failure; |
| 3947 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3948 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3949 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3950 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 3951 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3952 | goto nla_put_failure; \ |
| 3953 | } while (0) |
| 3954 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3955 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 3956 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 3957 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 3958 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3959 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 3960 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 3961 | nla_nest_end(msg, tidattr); |
| 3962 | } |
| 3963 | |
| 3964 | nla_nest_end(msg, tidsattr); |
| 3965 | } |
| 3966 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3967 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3968 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 3969 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3970 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3971 | sinfo->assoc_req_ies)) |
| 3972 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3973 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3974 | genlmsg_end(msg, hdr); |
| 3975 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3976 | |
| 3977 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3978 | genlmsg_cancel(msg, hdr); |
| 3979 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3980 | } |
| 3981 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3982 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3983 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3984 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3985 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3986 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3987 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3988 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3989 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3990 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3991 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3992 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3993 | if (err) |
| 3994 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3995 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3996 | if (!wdev->netdev) { |
| 3997 | err = -EINVAL; |
| 3998 | goto out_err; |
| 3999 | } |
| 4000 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4001 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4002 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4003 | goto out_err; |
| 4004 | } |
| 4005 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4006 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4007 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4008 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4009 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4010 | if (err == -ENOENT) |
| 4011 | break; |
| 4012 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4013 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4014 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4015 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4016 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4017 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4018 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4019 | &sinfo) < 0) |
| 4020 | goto out; |
| 4021 | |
| 4022 | sta_idx++; |
| 4023 | } |
| 4024 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4025 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4026 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4027 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4028 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4029 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4030 | |
| 4031 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4032 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4033 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4034 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4037 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4038 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4039 | struct sk_buff *msg; |
| 4040 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4041 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4042 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4043 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4044 | |
| 4045 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4046 | return -EINVAL; |
| 4047 | |
| 4048 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4050 | if (!rdev->ops->get_station) |
| 4051 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4052 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4053 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4054 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4055 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4056 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4057 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4058 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4059 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4060 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4061 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4062 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4063 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4064 | nlmsg_free(msg); |
| 4065 | return -ENOBUFS; |
| 4066 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4067 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4068 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4069 | } |
| 4070 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4071 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4072 | struct station_parameters *params, |
| 4073 | enum cfg80211_station_type statype) |
| 4074 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4075 | if (params->listen_interval != -1 && |
| 4076 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4077 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4078 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4079 | if (params->support_p2p_ps != -1 && |
| 4080 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4081 | return -EINVAL; |
| 4082 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4083 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4084 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4085 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4086 | return -EINVAL; |
| 4087 | |
| 4088 | /* When you run into this, adjust the code below for the new flag */ |
| 4089 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4090 | |
| 4091 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4092 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4093 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4094 | /* |
| 4095 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4096 | * code doesn't have the bug of including TDLS in the |
| 4097 | * mask everywhere. |
| 4098 | */ |
| 4099 | if (params->sta_flags_mask & |
| 4100 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4101 | BIT(NL80211_STA_FLAG_MFP) | |
| 4102 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4103 | return -EINVAL; |
| 4104 | break; |
| 4105 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4106 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4107 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4108 | return -EINVAL; |
| 4109 | /* ignore since it can't change */ |
| 4110 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4111 | break; |
| 4112 | default: |
| 4113 | /* disallow mesh-specific things */ |
| 4114 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4115 | return -EINVAL; |
| 4116 | if (params->local_pm) |
| 4117 | return -EINVAL; |
| 4118 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4119 | return -EINVAL; |
| 4120 | } |
| 4121 | |
| 4122 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4123 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4124 | /* TDLS can't be set, ... */ |
| 4125 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4126 | return -EINVAL; |
| 4127 | /* |
| 4128 | * ... but don't bother the driver with it. This works around |
| 4129 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4130 | * TLDS_PEER flag in the mask even for AP mode. |
| 4131 | */ |
| 4132 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4133 | } |
| 4134 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4135 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4136 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4137 | /* reject other things that can't change */ |
| 4138 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4139 | return -EINVAL; |
| 4140 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4141 | return -EINVAL; |
| 4142 | if (params->supported_rates) |
| 4143 | return -EINVAL; |
| 4144 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4145 | return -EINVAL; |
| 4146 | } |
| 4147 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4148 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4149 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4150 | if (params->vlan) |
| 4151 | return -EINVAL; |
| 4152 | } |
| 4153 | |
| 4154 | switch (statype) { |
| 4155 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4156 | /* Use this only for authorizing/unauthorizing a station */ |
| 4157 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4158 | return -EOPNOTSUPP; |
| 4159 | break; |
| 4160 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4161 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4162 | /* accept only the listed bits */ |
| 4163 | if (params->sta_flags_mask & |
| 4164 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4165 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4166 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4167 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4168 | BIT(NL80211_STA_FLAG_WME) | |
| 4169 | BIT(NL80211_STA_FLAG_MFP))) |
| 4170 | return -EINVAL; |
| 4171 | |
| 4172 | /* but authenticated/associated only if driver handles it */ |
| 4173 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4174 | params->sta_flags_mask & |
| 4175 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4176 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4177 | return -EINVAL; |
| 4178 | break; |
| 4179 | case CFG80211_STA_IBSS: |
| 4180 | case CFG80211_STA_AP_STA: |
| 4181 | /* reject any changes other than AUTHORIZED */ |
| 4182 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4183 | return -EINVAL; |
| 4184 | break; |
| 4185 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4186 | /* reject any changes other than AUTHORIZED or WME */ |
| 4187 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4188 | BIT(NL80211_STA_FLAG_WME))) |
| 4189 | return -EINVAL; |
| 4190 | /* force (at least) rates when authorizing */ |
| 4191 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4192 | !params->supported_rates) |
| 4193 | return -EINVAL; |
| 4194 | break; |
| 4195 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4196 | /* reject any changes */ |
| 4197 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4198 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4199 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4200 | return -EINVAL; |
| 4201 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4202 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4203 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4204 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4205 | return -EINVAL; |
| 4206 | break; |
| 4207 | } |
| 4208 | |
| 4209 | return 0; |
| 4210 | } |
| 4211 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4212 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4213 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4214 | * 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] | 4215 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4216 | static struct net_device *get_vlan(struct genl_info *info, |
| 4217 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4218 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4219 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4220 | struct net_device *v; |
| 4221 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4222 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4223 | if (!vlanattr) |
| 4224 | return NULL; |
| 4225 | |
| 4226 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4227 | if (!v) |
| 4228 | return ERR_PTR(-ENODEV); |
| 4229 | |
| 4230 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4231 | ret = -EINVAL; |
| 4232 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4233 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4234 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4235 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4236 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4237 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4238 | ret = -EINVAL; |
| 4239 | goto error; |
| 4240 | } |
| 4241 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4242 | if (!netif_running(v)) { |
| 4243 | ret = -ENETDOWN; |
| 4244 | goto error; |
| 4245 | } |
| 4246 | |
| 4247 | return v; |
| 4248 | error: |
| 4249 | dev_put(v); |
| 4250 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4251 | } |
| 4252 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4253 | static const struct nla_policy |
| 4254 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4255 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4256 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4257 | }; |
| 4258 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4259 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4260 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4261 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4262 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4263 | struct nlattr *nla; |
| 4264 | int err; |
| 4265 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4266 | /* parse WME attributes if present */ |
| 4267 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4268 | return 0; |
| 4269 | |
| 4270 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4271 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4272 | nl80211_sta_wme_policy); |
| 4273 | if (err) |
| 4274 | return err; |
| 4275 | |
| 4276 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4277 | params->uapsd_queues = nla_get_u8( |
| 4278 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4279 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4283 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4284 | |
| 4285 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4286 | return -EINVAL; |
| 4287 | |
| 4288 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4289 | |
| 4290 | return 0; |
| 4291 | } |
| 4292 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4293 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4294 | struct station_parameters *params) |
| 4295 | { |
| 4296 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4297 | params->supported_channels = |
| 4298 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4299 | params->supported_channels_len = |
| 4300 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4301 | /* |
| 4302 | * Need to include at least one (first channel, number of |
| 4303 | * channels) tuple for each subband, and must have proper |
| 4304 | * tuples for the rest of the data as well. |
| 4305 | */ |
| 4306 | if (params->supported_channels_len < 2) |
| 4307 | return -EINVAL; |
| 4308 | if (params->supported_channels_len % 2) |
| 4309 | return -EINVAL; |
| 4310 | } |
| 4311 | |
| 4312 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4313 | params->supported_oper_classes = |
| 4314 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4315 | params->supported_oper_classes_len = |
| 4316 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4317 | /* |
| 4318 | * The value of the Length field of the Supported Operating |
| 4319 | * Classes element is between 2 and 253. |
| 4320 | */ |
| 4321 | if (params->supported_oper_classes_len < 2 || |
| 4322 | params->supported_oper_classes_len > 253) |
| 4323 | return -EINVAL; |
| 4324 | } |
| 4325 | return 0; |
| 4326 | } |
| 4327 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4328 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4329 | struct station_parameters *params) |
| 4330 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4331 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4332 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4333 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4334 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4335 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4336 | params->ht_capa = |
| 4337 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4338 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4339 | params->vht_capa = |
| 4340 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4341 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4342 | err = nl80211_parse_sta_channel_info(info, params); |
| 4343 | if (err) |
| 4344 | return err; |
| 4345 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4346 | return nl80211_parse_sta_wme(info, params); |
| 4347 | } |
| 4348 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4349 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4350 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4352 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4353 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4354 | u8 *mac_addr; |
| 4355 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4356 | |
| 4357 | memset(¶ms, 0, sizeof(params)); |
| 4358 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4359 | if (!rdev->ops->change_station) |
| 4360 | return -EOPNOTSUPP; |
| 4361 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4362 | /* |
| 4363 | * AID and listen_interval properties can be set only for unassociated |
| 4364 | * station. Include these parameters here and will check them in |
| 4365 | * cfg80211_check_station_change(). |
| 4366 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4367 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4368 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4369 | |
| 4370 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4371 | params.listen_interval = |
| 4372 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4373 | else |
| 4374 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4375 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4376 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4377 | u8 tmp; |
| 4378 | |
| 4379 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4380 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4381 | return -EINVAL; |
| 4382 | |
| 4383 | params.support_p2p_ps = tmp; |
| 4384 | } else { |
| 4385 | params.support_p2p_ps = -1; |
| 4386 | } |
| 4387 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4388 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4389 | return -EINVAL; |
| 4390 | |
| 4391 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4392 | |
| 4393 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4394 | params.supported_rates = |
| 4395 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4396 | params.supported_rates_len = |
| 4397 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4398 | } |
| 4399 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4400 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4401 | params.capability = |
| 4402 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4403 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4404 | } |
| 4405 | |
| 4406 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4407 | params.ext_capab = |
| 4408 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4409 | params.ext_capab_len = |
| 4410 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4411 | } |
| 4412 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4413 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4414 | return -EINVAL; |
| 4415 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4416 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4417 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4418 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4419 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4420 | return -EINVAL; |
| 4421 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4422 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4423 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4424 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4425 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4426 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4427 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4428 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4429 | params.peer_aid = nla_get_u16( |
| 4430 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4431 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4432 | return -EINVAL; |
| 4433 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4434 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4435 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4436 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4437 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4438 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4439 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4440 | |
| 4441 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4442 | pm > NL80211_MESH_POWER_MAX) |
| 4443 | return -EINVAL; |
| 4444 | |
| 4445 | params.local_pm = pm; |
| 4446 | } |
| 4447 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4448 | /* Include parameters for TDLS peer (will check later) */ |
| 4449 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4450 | if (err) |
| 4451 | return err; |
| 4452 | |
| 4453 | params.vlan = get_vlan(info, rdev); |
| 4454 | if (IS_ERR(params.vlan)) |
| 4455 | return PTR_ERR(params.vlan); |
| 4456 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4457 | switch (dev->ieee80211_ptr->iftype) { |
| 4458 | case NL80211_IFTYPE_AP: |
| 4459 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4460 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4461 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4462 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4463 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4464 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4465 | break; |
| 4466 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4467 | err = -EOPNOTSUPP; |
| 4468 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4469 | } |
| 4470 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4471 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4472 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4473 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4474 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4475 | if (params.vlan) |
| 4476 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4477 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4478 | return err; |
| 4479 | } |
| 4480 | |
| 4481 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4484 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4485 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4486 | struct station_parameters params; |
| 4487 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4488 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4489 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4490 | |
| 4491 | memset(¶ms, 0, sizeof(params)); |
| 4492 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4493 | if (!rdev->ops->add_station) |
| 4494 | return -EOPNOTSUPP; |
| 4495 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4496 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4497 | return -EINVAL; |
| 4498 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4499 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4500 | return -EINVAL; |
| 4501 | |
| 4502 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4503 | return -EINVAL; |
| 4504 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4505 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4506 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4507 | return -EINVAL; |
| 4508 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4509 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4510 | params.supported_rates = |
| 4511 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4512 | params.supported_rates_len = |
| 4513 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4514 | params.listen_interval = |
| 4515 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4516 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4517 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4518 | u8 tmp; |
| 4519 | |
| 4520 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4521 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4522 | return -EINVAL; |
| 4523 | |
| 4524 | params.support_p2p_ps = tmp; |
| 4525 | } else { |
| 4526 | /* |
| 4527 | * if not specified, assume it's supported for P2P GO interface, |
| 4528 | * and is NOT supported for AP interface |
| 4529 | */ |
| 4530 | params.support_p2p_ps = |
| 4531 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4532 | } |
| 4533 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4534 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4535 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4536 | else |
| 4537 | 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] | 4538 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4539 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4540 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4541 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4542 | params.capability = |
| 4543 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4544 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4545 | } |
| 4546 | |
| 4547 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4548 | params.ext_capab = |
| 4549 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4550 | params.ext_capab_len = |
| 4551 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4552 | } |
| 4553 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4554 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4555 | params.ht_capa = |
| 4556 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4557 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4558 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4559 | params.vht_capa = |
| 4560 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4561 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4562 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4563 | params.opmode_notif_used = true; |
| 4564 | params.opmode_notif = |
| 4565 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4566 | } |
| 4567 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4568 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4569 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4570 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4571 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4572 | return -EINVAL; |
| 4573 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4574 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4575 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4576 | if (err) |
| 4577 | return err; |
| 4578 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4579 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4580 | if (err) |
| 4581 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4582 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4583 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4584 | return -EINVAL; |
| 4585 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4586 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4587 | * as userspace might just pass through the capabilities from the IEs |
| 4588 | * directly, rather than enforcing this restriction and returning an |
| 4589 | * error in this case. |
| 4590 | */ |
| 4591 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4592 | params.ht_capa = NULL; |
| 4593 | params.vht_capa = NULL; |
| 4594 | } |
| 4595 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4596 | /* When you run into this, adjust the code below for the new flag */ |
| 4597 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4598 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4599 | switch (dev->ieee80211_ptr->iftype) { |
| 4600 | case NL80211_IFTYPE_AP: |
| 4601 | case NL80211_IFTYPE_AP_VLAN: |
| 4602 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4603 | /* ignore WME attributes if iface/sta is not capable */ |
| 4604 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4605 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4606 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4607 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4608 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4609 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4610 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4611 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4612 | /* but don't bother the driver with it */ |
| 4613 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4614 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4615 | /* allow authenticated/associated only if driver handles it */ |
| 4616 | if (!(rdev->wiphy.features & |
| 4617 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4618 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4619 | return -EINVAL; |
| 4620 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4621 | /* Older userspace, or userspace wanting to be compatible with |
| 4622 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 4623 | * and assoc flags in the mask, but assumes the station will be |
| 4624 | * added as associated anyway since this was the required driver |
| 4625 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 4626 | * introduced. |
| 4627 | * In order to not bother drivers with this quirk in the API |
| 4628 | * set the flags in both the mask and set for new stations in |
| 4629 | * this case. |
| 4630 | */ |
| 4631 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 4632 | params.sta_flags_mask |= auth_assoc; |
| 4633 | params.sta_flags_set |= auth_assoc; |
| 4634 | } |
| 4635 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4636 | /* must be last in here for error handling */ |
| 4637 | params.vlan = get_vlan(info, rdev); |
| 4638 | if (IS_ERR(params.vlan)) |
| 4639 | return PTR_ERR(params.vlan); |
| 4640 | break; |
| 4641 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4642 | /* ignore uAPSD data */ |
| 4643 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4644 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4645 | /* associated is disallowed */ |
| 4646 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4647 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4648 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4649 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4650 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4651 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4652 | break; |
| 4653 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4654 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4655 | /* ignore uAPSD data */ |
| 4656 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4657 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4658 | /* these are disallowed */ |
| 4659 | if (params.sta_flags_mask & |
| 4660 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4661 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4662 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4663 | /* Only TDLS peers can be added */ |
| 4664 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4665 | return -EINVAL; |
| 4666 | /* Can only add if TDLS ... */ |
| 4667 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4668 | return -EOPNOTSUPP; |
| 4669 | /* ... with external setup is supported */ |
| 4670 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4671 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4672 | /* |
| 4673 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4674 | * as authorized, but it shouldn't yet be. |
| 4675 | */ |
| 4676 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4677 | break; |
| 4678 | default: |
| 4679 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4680 | } |
| 4681 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4682 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4683 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4684 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4685 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4686 | if (params.vlan) |
| 4687 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4688 | return err; |
| 4689 | } |
| 4690 | |
| 4691 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4692 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4694 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4695 | struct station_del_parameters params; |
| 4696 | |
| 4697 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4698 | |
| 4699 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4700 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4701 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4702 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4703 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4704 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4705 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4706 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4708 | if (!rdev->ops->del_station) |
| 4709 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4710 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4711 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4712 | params.subtype = |
| 4713 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4714 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4715 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4716 | return -EINVAL; |
| 4717 | } else { |
| 4718 | /* Default to Deauthentication frame */ |
| 4719 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4720 | } |
| 4721 | |
| 4722 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4723 | params.reason_code = |
| 4724 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4725 | if (params.reason_code == 0) |
| 4726 | return -EINVAL; /* 0 is reserved */ |
| 4727 | } else { |
| 4728 | /* Default to reason code 2 */ |
| 4729 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4730 | } |
| 4731 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4732 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4733 | } |
| 4734 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4735 | 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] | 4736 | int flags, struct net_device *dev, |
| 4737 | u8 *dst, u8 *next_hop, |
| 4738 | struct mpath_info *pinfo) |
| 4739 | { |
| 4740 | void *hdr; |
| 4741 | struct nlattr *pinfoattr; |
| 4742 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4743 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4744 | if (!hdr) |
| 4745 | return -1; |
| 4746 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4747 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4748 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4749 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4750 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4751 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4752 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4753 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4754 | if (!pinfoattr) |
| 4755 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4756 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4757 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4758 | pinfo->frame_qlen)) |
| 4759 | goto nla_put_failure; |
| 4760 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4761 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4762 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4763 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4764 | pinfo->metric)) || |
| 4765 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4766 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4767 | pinfo->exptime)) || |
| 4768 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4769 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4770 | pinfo->flags)) || |
| 4771 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4772 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4773 | pinfo->discovery_timeout)) || |
| 4774 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4775 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4776 | pinfo->discovery_retries))) |
| 4777 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4778 | |
| 4779 | nla_nest_end(msg, pinfoattr); |
| 4780 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4781 | genlmsg_end(msg, hdr); |
| 4782 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4783 | |
| 4784 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4785 | genlmsg_cancel(msg, hdr); |
| 4786 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4790 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4791 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4792 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4793 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4794 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4795 | u8 dst[ETH_ALEN]; |
| 4796 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4797 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4798 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4799 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4800 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4801 | if (err) |
| 4802 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4803 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4804 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4805 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4806 | goto out_err; |
| 4807 | } |
| 4808 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4809 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4810 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4811 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4812 | } |
| 4813 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4814 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4815 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4816 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4817 | if (err == -ENOENT) |
| 4818 | break; |
| 4819 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4820 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4821 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4822 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4823 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4824 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4825 | &pinfo) < 0) |
| 4826 | goto out; |
| 4827 | |
| 4828 | path_idx++; |
| 4829 | } |
| 4830 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4831 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4832 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4833 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4834 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4835 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4836 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4840 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4842 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4843 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4844 | struct mpath_info pinfo; |
| 4845 | struct sk_buff *msg; |
| 4846 | u8 *dst = NULL; |
| 4847 | u8 next_hop[ETH_ALEN]; |
| 4848 | |
| 4849 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4850 | |
| 4851 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4852 | return -EINVAL; |
| 4853 | |
| 4854 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4855 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4856 | if (!rdev->ops->get_mpath) |
| 4857 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4860 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4861 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4862 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4863 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4864 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4865 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4866 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4867 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4869 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4870 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4871 | dev, dst, next_hop, &pinfo) < 0) { |
| 4872 | nlmsg_free(msg); |
| 4873 | return -ENOBUFS; |
| 4874 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4876 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4880 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4882 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4883 | u8 *dst = NULL; |
| 4884 | u8 *next_hop = NULL; |
| 4885 | |
| 4886 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4887 | return -EINVAL; |
| 4888 | |
| 4889 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4890 | return -EINVAL; |
| 4891 | |
| 4892 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4893 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4894 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4895 | if (!rdev->ops->change_mpath) |
| 4896 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4897 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4898 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4899 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4900 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4901 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4902 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4903 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4904 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4907 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4908 | u8 *dst = NULL; |
| 4909 | u8 *next_hop = NULL; |
| 4910 | |
| 4911 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4912 | return -EINVAL; |
| 4913 | |
| 4914 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4915 | return -EINVAL; |
| 4916 | |
| 4917 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4918 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4920 | if (!rdev->ops->add_mpath) |
| 4921 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4922 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4924 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4925 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4926 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4932 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4933 | u8 *dst = NULL; |
| 4934 | |
| 4935 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4936 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4938 | if (!rdev->ops->del_mpath) |
| 4939 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4940 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4941 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4942 | } |
| 4943 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4944 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4945 | { |
| 4946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4947 | int err; |
| 4948 | struct net_device *dev = info->user_ptr[1]; |
| 4949 | struct mpath_info pinfo; |
| 4950 | struct sk_buff *msg; |
| 4951 | u8 *dst = NULL; |
| 4952 | u8 mpp[ETH_ALEN]; |
| 4953 | |
| 4954 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4955 | |
| 4956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4957 | return -EINVAL; |
| 4958 | |
| 4959 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4960 | |
| 4961 | if (!rdev->ops->get_mpp) |
| 4962 | return -EOPNOTSUPP; |
| 4963 | |
| 4964 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4965 | return -EOPNOTSUPP; |
| 4966 | |
| 4967 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4968 | if (err) |
| 4969 | return err; |
| 4970 | |
| 4971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4972 | if (!msg) |
| 4973 | return -ENOMEM; |
| 4974 | |
| 4975 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4976 | dev, dst, mpp, &pinfo) < 0) { |
| 4977 | nlmsg_free(msg); |
| 4978 | return -ENOBUFS; |
| 4979 | } |
| 4980 | |
| 4981 | return genlmsg_reply(msg, info); |
| 4982 | } |
| 4983 | |
| 4984 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4985 | struct netlink_callback *cb) |
| 4986 | { |
| 4987 | struct mpath_info pinfo; |
| 4988 | struct cfg80211_registered_device *rdev; |
| 4989 | struct wireless_dev *wdev; |
| 4990 | u8 dst[ETH_ALEN]; |
| 4991 | u8 mpp[ETH_ALEN]; |
| 4992 | int path_idx = cb->args[2]; |
| 4993 | int err; |
| 4994 | |
| 4995 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4996 | if (err) |
| 4997 | return err; |
| 4998 | |
| 4999 | if (!rdev->ops->dump_mpp) { |
| 5000 | err = -EOPNOTSUPP; |
| 5001 | goto out_err; |
| 5002 | } |
| 5003 | |
| 5004 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5005 | err = -EOPNOTSUPP; |
| 5006 | goto out_err; |
| 5007 | } |
| 5008 | |
| 5009 | while (1) { |
| 5010 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5011 | mpp, &pinfo); |
| 5012 | if (err == -ENOENT) |
| 5013 | break; |
| 5014 | if (err) |
| 5015 | goto out_err; |
| 5016 | |
| 5017 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5018 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5019 | wdev->netdev, dst, mpp, |
| 5020 | &pinfo) < 0) |
| 5021 | goto out; |
| 5022 | |
| 5023 | path_idx++; |
| 5024 | } |
| 5025 | |
| 5026 | out: |
| 5027 | cb->args[2] = path_idx; |
| 5028 | err = skb->len; |
| 5029 | out_err: |
| 5030 | nl80211_finish_wdev_dump(rdev); |
| 5031 | return err; |
| 5032 | } |
| 5033 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5034 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5037 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5038 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5039 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5040 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5041 | |
| 5042 | memset(¶ms, 0, sizeof(params)); |
| 5043 | /* default to not changing parameters */ |
| 5044 | params.use_cts_prot = -1; |
| 5045 | params.use_short_preamble = -1; |
| 5046 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5047 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5048 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5049 | params.p2p_ctwindow = -1; |
| 5050 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5051 | |
| 5052 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5053 | params.use_cts_prot = |
| 5054 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5055 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5056 | params.use_short_preamble = |
| 5057 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5058 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5059 | params.use_short_slot_time = |
| 5060 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5061 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5062 | params.basic_rates = |
| 5063 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5064 | params.basic_rates_len = |
| 5065 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5066 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5067 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5068 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5069 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5070 | params.ht_opmode = |
| 5071 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5072 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5073 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5074 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5075 | return -EINVAL; |
| 5076 | params.p2p_ctwindow = |
| 5077 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5078 | if (params.p2p_ctwindow < 0) |
| 5079 | return -EINVAL; |
| 5080 | if (params.p2p_ctwindow != 0 && |
| 5081 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5082 | return -EINVAL; |
| 5083 | } |
| 5084 | |
| 5085 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5086 | u8 tmp; |
| 5087 | |
| 5088 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5089 | return -EINVAL; |
| 5090 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5091 | if (tmp > 1) |
| 5092 | return -EINVAL; |
| 5093 | params.p2p_opp_ps = tmp; |
| 5094 | if (params.p2p_opp_ps && |
| 5095 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5096 | return -EINVAL; |
| 5097 | } |
| 5098 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | if (!rdev->ops->change_bss) |
| 5100 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5101 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5102 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5103 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5104 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5105 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5106 | wdev_lock(wdev); |
| 5107 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5108 | wdev_unlock(wdev); |
| 5109 | |
| 5110 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5111 | } |
| 5112 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5113 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5114 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5115 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5116 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5117 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5118 | u32 owner_nlportid; |
| 5119 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5120 | /* |
| 5121 | * You should only get this when cfg80211 hasn't yet initialized |
| 5122 | * completely when built-in to the kernel right between the time |
| 5123 | * window between nl80211_init() and regulatory_init(), if that is |
| 5124 | * even possible. |
| 5125 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5126 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5127 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5128 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5129 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5130 | user_reg_hint_type = |
| 5131 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5132 | else |
| 5133 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5134 | |
| 5135 | switch (user_reg_hint_type) { |
| 5136 | case NL80211_USER_REG_HINT_USER: |
| 5137 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5138 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5139 | return -EINVAL; |
| 5140 | |
| 5141 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5142 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5143 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5144 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5145 | owner_nlportid = info->snd_portid; |
| 5146 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5147 | } else { |
| 5148 | owner_nlportid = 0; |
| 5149 | is_indoor = true; |
| 5150 | } |
| 5151 | |
| 5152 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5153 | default: |
| 5154 | return -EINVAL; |
| 5155 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5158 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5159 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5160 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5161 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5162 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5163 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5164 | struct mesh_config cur_params; |
| 5165 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5166 | void *hdr; |
| 5167 | struct nlattr *pinfoattr; |
| 5168 | struct sk_buff *msg; |
| 5169 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5170 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5171 | return -EOPNOTSUPP; |
| 5172 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5173 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5174 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5175 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5176 | wdev_lock(wdev); |
| 5177 | /* If not connected, get default parameters */ |
| 5178 | if (!wdev->mesh_id_len) |
| 5179 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5180 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5181 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5182 | wdev_unlock(wdev); |
| 5183 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5184 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5185 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5186 | |
| 5187 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5188 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5189 | if (!msg) |
| 5190 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5191 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5192 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5193 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5194 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5195 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5196 | if (!pinfoattr) |
| 5197 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5198 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5199 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5200 | cur_params.dot11MeshRetryTimeout) || |
| 5201 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5202 | cur_params.dot11MeshConfirmTimeout) || |
| 5203 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5204 | cur_params.dot11MeshHoldingTimeout) || |
| 5205 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5206 | cur_params.dot11MeshMaxPeerLinks) || |
| 5207 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5208 | cur_params.dot11MeshMaxRetries) || |
| 5209 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5210 | cur_params.dot11MeshTTL) || |
| 5211 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5212 | cur_params.element_ttl) || |
| 5213 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5214 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5215 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5216 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5217 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5218 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5219 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5220 | cur_params.path_refresh_time) || |
| 5221 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5222 | cur_params.min_discovery_timeout) || |
| 5223 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5224 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5225 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5226 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5227 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5228 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5229 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5230 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5231 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5232 | cur_params.dot11MeshHWMPRootMode) || |
| 5233 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5234 | cur_params.dot11MeshHWMPRannInterval) || |
| 5235 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5236 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5237 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5238 | cur_params.dot11MeshForwarding) || |
| 5239 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5240 | cur_params.rssi_threshold) || |
| 5241 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5242 | cur_params.ht_opmode) || |
| 5243 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5244 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5245 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5246 | cur_params.dot11MeshHWMProotInterval) || |
| 5247 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5248 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5249 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5250 | cur_params.power_mode) || |
| 5251 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5252 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5253 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5254 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5255 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5256 | nla_nest_end(msg, pinfoattr); |
| 5257 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5258 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5259 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5260 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5261 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5262 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5263 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5264 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5265 | } |
| 5266 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5267 | 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] | 5268 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5269 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5270 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5271 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5272 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5273 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5274 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5275 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5276 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5277 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5278 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5279 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5280 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5281 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5282 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5283 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5284 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5285 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5286 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5287 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5288 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5289 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5290 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5291 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5292 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5293 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5294 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5295 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5296 | }; |
| 5297 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5298 | static const struct nla_policy |
| 5299 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5300 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5301 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5302 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5303 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5304 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5305 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5306 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5307 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5308 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5309 | }; |
| 5310 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5311 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5312 | { |
| 5313 | u8 val = nla_get_u8(nla); |
| 5314 | if (val < min || val > max) |
| 5315 | return -EINVAL; |
| 5316 | *out = val; |
| 5317 | return 0; |
| 5318 | } |
| 5319 | |
| 5320 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5321 | { |
| 5322 | u8 val = nla_get_u8(nla); |
| 5323 | if (val < min || val > max) |
| 5324 | return -EINVAL; |
| 5325 | *out = val; |
| 5326 | return 0; |
| 5327 | } |
| 5328 | |
| 5329 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5330 | { |
| 5331 | u16 val = nla_get_u16(nla); |
| 5332 | if (val < min || val > max) |
| 5333 | return -EINVAL; |
| 5334 | *out = val; |
| 5335 | return 0; |
| 5336 | } |
| 5337 | |
| 5338 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5339 | { |
| 5340 | u32 val = nla_get_u32(nla); |
| 5341 | if (val < min || val > max) |
| 5342 | return -EINVAL; |
| 5343 | *out = val; |
| 5344 | return 0; |
| 5345 | } |
| 5346 | |
| 5347 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5348 | { |
| 5349 | s32 val = nla_get_s32(nla); |
| 5350 | if (val < min || val > max) |
| 5351 | return -EINVAL; |
| 5352 | *out = val; |
| 5353 | return 0; |
| 5354 | } |
| 5355 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5356 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5357 | struct mesh_config *cfg, |
| 5358 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5359 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5360 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5361 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5362 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5363 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5364 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5365 | do { \ |
| 5366 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5367 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5368 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5369 | mask |= (1 << (attr - 1)); \ |
| 5370 | } \ |
| 5371 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5372 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5373 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5374 | return -EINVAL; |
| 5375 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5376 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5377 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5378 | return -EINVAL; |
| 5379 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5380 | /* This makes sure that there aren't more than 32 mesh config |
| 5381 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5382 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5383 | |
| 5384 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5385 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5386 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5387 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5388 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5389 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5390 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5391 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5392 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5393 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5394 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5395 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5396 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5397 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5398 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5399 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5400 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5401 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5402 | 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] | 5403 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5404 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5405 | 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] | 5406 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5407 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5408 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5409 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5410 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5411 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5412 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5413 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5414 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5415 | 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] | 5416 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5417 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5418 | 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] | 5419 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5420 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5421 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5422 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5423 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5424 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5425 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5426 | 1, 65535, mask, |
| 5427 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5428 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5429 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5430 | 1, 65535, mask, |
| 5431 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5432 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5433 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5434 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5435 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5436 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5437 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5438 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5439 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5440 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5441 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5442 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5443 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5444 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5445 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5446 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5447 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5448 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5449 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5450 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5451 | 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] | 5452 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5453 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5454 | /* |
| 5455 | * Check HT operation mode based on |
| 5456 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5457 | */ |
| 5458 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5459 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5460 | |
| 5461 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5462 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5463 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5464 | return -EINVAL; |
| 5465 | |
| 5466 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5467 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5468 | return -EINVAL; |
| 5469 | |
| 5470 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5471 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5472 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5473 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 5474 | return -EINVAL; |
| 5475 | break; |
| 5476 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 5477 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 5478 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5479 | return -EINVAL; |
| 5480 | break; |
| 5481 | } |
| 5482 | cfg->ht_opmode = ht_opmode; |
| 5483 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5484 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5485 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5486 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5487 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5488 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5489 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5490 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5491 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5492 | dot11MeshHWMPconfirmationInterval, |
| 5493 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5494 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5495 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5496 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5497 | NL80211_MESH_POWER_ACTIVE, |
| 5498 | NL80211_MESH_POWER_MAX, |
| 5499 | mask, NL80211_MESHCONF_POWER_MODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5500 | nl80211_check_u32); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5501 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5502 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5503 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5504 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5505 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5506 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5507 | if (mask_out) |
| 5508 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5509 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5510 | return 0; |
| 5511 | |
| 5512 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5513 | } |
| 5514 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5515 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5516 | struct mesh_setup *setup) |
| 5517 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5519 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5520 | |
| 5521 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5522 | return -EINVAL; |
| 5523 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5524 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5525 | nl80211_mesh_setup_params_policy)) |
| 5526 | return -EINVAL; |
| 5527 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5528 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5529 | setup->sync_method = |
| 5530 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5531 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5532 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5533 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5534 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5535 | setup->path_sel_proto = |
| 5536 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5537 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5538 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5539 | |
| 5540 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5541 | setup->path_metric = |
| 5542 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5543 | IEEE80211_PATH_METRIC_VENDOR : |
| 5544 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5545 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5546 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5547 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5548 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5549 | if (!is_valid_ie_attr(ieattr)) |
| 5550 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5551 | setup->ie = nla_data(ieattr); |
| 5552 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5553 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5554 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5555 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5556 | return -EINVAL; |
| 5557 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5558 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5559 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5560 | if (setup->is_secure) |
| 5561 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5562 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5563 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5564 | if (!setup->user_mpm) |
| 5565 | return -EINVAL; |
| 5566 | setup->auth_id = |
| 5567 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5568 | } |
| 5569 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5570 | return 0; |
| 5571 | } |
| 5572 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5573 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5574 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5575 | { |
| 5576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5577 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5578 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5579 | struct mesh_config cfg; |
| 5580 | u32 mask; |
| 5581 | int err; |
| 5582 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5583 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5584 | return -EOPNOTSUPP; |
| 5585 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5586 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5587 | return -EOPNOTSUPP; |
| 5588 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5589 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5590 | if (err) |
| 5591 | return err; |
| 5592 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5593 | wdev_lock(wdev); |
| 5594 | if (!wdev->mesh_id_len) |
| 5595 | err = -ENOLINK; |
| 5596 | |
| 5597 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5598 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5599 | |
| 5600 | wdev_unlock(wdev); |
| 5601 | |
| 5602 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5605 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5606 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5607 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5608 | struct nlattr *nl_reg_rules; |
| 5609 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5610 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5611 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5612 | (regdom->dfs_region && |
| 5613 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5614 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5615 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5616 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5617 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5618 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5619 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5620 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5621 | struct nlattr *nl_reg_rule; |
| 5622 | const struct ieee80211_reg_rule *reg_rule; |
| 5623 | const struct ieee80211_freq_range *freq_range; |
| 5624 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5625 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5626 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5627 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5628 | freq_range = ®_rule->freq_range; |
| 5629 | power_rule = ®_rule->power_rule; |
| 5630 | |
| 5631 | nl_reg_rule = nla_nest_start(msg, i); |
| 5632 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5633 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5634 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5635 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5636 | if (!max_bandwidth_khz) |
| 5637 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5638 | reg_rule); |
| 5639 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5640 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5641 | reg_rule->flags) || |
| 5642 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5643 | freq_range->start_freq_khz) || |
| 5644 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5645 | freq_range->end_freq_khz) || |
| 5646 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5647 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5648 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5649 | power_rule->max_antenna_gain) || |
| 5650 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5651 | power_rule->max_eirp) || |
| 5652 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5653 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5654 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5655 | |
| 5656 | nla_nest_end(msg, nl_reg_rule); |
| 5657 | } |
| 5658 | |
| 5659 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5660 | return 0; |
| 5661 | |
| 5662 | nla_put_failure: |
| 5663 | return -EMSGSIZE; |
| 5664 | } |
| 5665 | |
| 5666 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5667 | { |
| 5668 | const struct ieee80211_regdomain *regdom = NULL; |
| 5669 | struct cfg80211_registered_device *rdev; |
| 5670 | struct wiphy *wiphy = NULL; |
| 5671 | struct sk_buff *msg; |
| 5672 | void *hdr; |
| 5673 | |
| 5674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5675 | if (!msg) |
| 5676 | return -ENOBUFS; |
| 5677 | |
| 5678 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5679 | NL80211_CMD_GET_REG); |
| 5680 | if (!hdr) |
| 5681 | goto put_failure; |
| 5682 | |
| 5683 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5684 | bool self_managed; |
| 5685 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5686 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5687 | if (IS_ERR(rdev)) { |
| 5688 | nlmsg_free(msg); |
| 5689 | return PTR_ERR(rdev); |
| 5690 | } |
| 5691 | |
| 5692 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5693 | self_managed = wiphy->regulatory_flags & |
| 5694 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5695 | regdom = get_wiphy_regdom(wiphy); |
| 5696 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5697 | /* a self-managed-reg device must have a private regdom */ |
| 5698 | if (WARN_ON(!regdom && self_managed)) { |
| 5699 | nlmsg_free(msg); |
| 5700 | return -EINVAL; |
| 5701 | } |
| 5702 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5703 | if (regdom && |
| 5704 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5705 | goto nla_put_failure; |
| 5706 | } |
| 5707 | |
| 5708 | if (!wiphy && reg_last_request_cell_base() && |
| 5709 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5710 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5711 | goto nla_put_failure; |
| 5712 | |
| 5713 | rcu_read_lock(); |
| 5714 | |
| 5715 | if (!regdom) |
| 5716 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5717 | |
| 5718 | if (nl80211_put_regdom(regdom, msg)) |
| 5719 | goto nla_put_failure_rcu; |
| 5720 | |
| 5721 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5722 | |
| 5723 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5724 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5725 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5726 | nla_put_failure_rcu: |
| 5727 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5728 | nla_put_failure: |
| 5729 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5730 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5731 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5732 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5733 | } |
| 5734 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5735 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5736 | u32 seq, int flags, struct wiphy *wiphy, |
| 5737 | const struct ieee80211_regdomain *regdom) |
| 5738 | { |
| 5739 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5740 | NL80211_CMD_GET_REG); |
| 5741 | |
| 5742 | if (!hdr) |
| 5743 | return -1; |
| 5744 | |
| 5745 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5746 | |
| 5747 | if (nl80211_put_regdom(regdom, msg)) |
| 5748 | goto nla_put_failure; |
| 5749 | |
| 5750 | if (!wiphy && reg_last_request_cell_base() && |
| 5751 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5752 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5753 | goto nla_put_failure; |
| 5754 | |
| 5755 | if (wiphy && |
| 5756 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5757 | goto nla_put_failure; |
| 5758 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 5759 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5760 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5761 | goto nla_put_failure; |
| 5762 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5763 | genlmsg_end(msg, hdr); |
| 5764 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5765 | |
| 5766 | nla_put_failure: |
| 5767 | genlmsg_cancel(msg, hdr); |
| 5768 | return -EMSGSIZE; |
| 5769 | } |
| 5770 | |
| 5771 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5772 | struct netlink_callback *cb) |
| 5773 | { |
| 5774 | const struct ieee80211_regdomain *regdom = NULL; |
| 5775 | struct cfg80211_registered_device *rdev; |
| 5776 | int err, reg_idx, start = cb->args[2]; |
| 5777 | |
| 5778 | rtnl_lock(); |
| 5779 | |
| 5780 | if (cfg80211_regdomain && start == 0) { |
| 5781 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5782 | NLM_F_MULTI, NULL, |
| 5783 | rtnl_dereference(cfg80211_regdomain)); |
| 5784 | if (err < 0) |
| 5785 | goto out_err; |
| 5786 | } |
| 5787 | |
| 5788 | /* the global regdom is idx 0 */ |
| 5789 | reg_idx = 1; |
| 5790 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5791 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5792 | if (!regdom) |
| 5793 | continue; |
| 5794 | |
| 5795 | if (++reg_idx <= start) |
| 5796 | continue; |
| 5797 | |
| 5798 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5799 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5800 | if (err < 0) { |
| 5801 | reg_idx--; |
| 5802 | break; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | cb->args[2] = reg_idx; |
| 5807 | err = skb->len; |
| 5808 | out_err: |
| 5809 | rtnl_unlock(); |
| 5810 | return err; |
| 5811 | } |
| 5812 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5813 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 5814 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 5815 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 5816 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 5817 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 5818 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 5819 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 5820 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 5821 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 5822 | }; |
| 5823 | |
| 5824 | static int parse_reg_rule(struct nlattr *tb[], |
| 5825 | struct ieee80211_reg_rule *reg_rule) |
| 5826 | { |
| 5827 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 5828 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 5829 | |
| 5830 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 5831 | return -EINVAL; |
| 5832 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 5833 | return -EINVAL; |
| 5834 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 5835 | return -EINVAL; |
| 5836 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 5837 | return -EINVAL; |
| 5838 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 5839 | return -EINVAL; |
| 5840 | |
| 5841 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 5842 | |
| 5843 | freq_range->start_freq_khz = |
| 5844 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 5845 | freq_range->end_freq_khz = |
| 5846 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 5847 | freq_range->max_bandwidth_khz = |
| 5848 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 5849 | |
| 5850 | power_rule->max_eirp = |
| 5851 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 5852 | |
| 5853 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 5854 | power_rule->max_antenna_gain = |
| 5855 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 5856 | |
| 5857 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 5858 | reg_rule->dfs_cac_ms = |
| 5859 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 5860 | |
| 5861 | return 0; |
| 5862 | } |
| 5863 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5864 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5865 | { |
| 5866 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5867 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5868 | char *alpha2; |
| 5869 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5870 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5871 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5872 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5873 | |
| 5874 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5875 | return -EINVAL; |
| 5876 | |
| 5877 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5878 | return -EINVAL; |
| 5879 | |
| 5880 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5881 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5882 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5883 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5884 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5885 | 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] | 5886 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5887 | num_rules++; |
| 5888 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5889 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5892 | if (!reg_is_valid_request(alpha2)) |
| 5893 | return -EINVAL; |
| 5894 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5895 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5896 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5897 | |
| 5898 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5899 | if (!rd) |
| 5900 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5901 | |
| 5902 | rd->n_reg_rules = num_rules; |
| 5903 | rd->alpha2[0] = alpha2[0]; |
| 5904 | rd->alpha2[1] = alpha2[1]; |
| 5905 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5906 | /* |
| 5907 | * Disable DFS master mode if the DFS region was |
| 5908 | * not supported or known on this kernel. |
| 5909 | */ |
| 5910 | if (reg_supported_dfs_region(dfs_region)) |
| 5911 | rd->dfs_region = dfs_region; |
| 5912 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5913 | 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] | 5914 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5915 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5916 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5917 | reg_rule_policy); |
| 5918 | if (r) |
| 5919 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5920 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5921 | if (r) |
| 5922 | goto bad_reg; |
| 5923 | |
| 5924 | rule_idx++; |
| 5925 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5926 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5927 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5928 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5929 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5930 | } |
| 5931 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 5932 | /* set_regdom takes ownership of rd */ |
| 5933 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5934 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5935 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5936 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5937 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 5938 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5939 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5940 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5941 | { |
| 5942 | struct nlattr *attr1, *attr2; |
| 5943 | int n_channels = 0, tmp1, tmp2; |
| 5944 | |
| 5945 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5946 | n_channels++; |
| 5947 | /* |
| 5948 | * Some hardware has a limited channel list for |
| 5949 | * scanning, and it is pretty much nonsensical |
| 5950 | * to scan for a channel twice, so disallow that |
| 5951 | * and don't require drivers to check that the |
| 5952 | * channel list they get isn't longer than what |
| 5953 | * they can scan, as long as they can scan all |
| 5954 | * the channels they registered at once. |
| 5955 | */ |
| 5956 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5957 | if (attr1 != attr2 && |
| 5958 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5959 | return 0; |
| 5960 | } |
| 5961 | |
| 5962 | return n_channels; |
| 5963 | } |
| 5964 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5965 | 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] | 5966 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 5967 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 5971 | struct cfg80211_bss_selection *bss_select) |
| 5972 | { |
| 5973 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 5974 | struct nlattr *nest; |
| 5975 | int err; |
| 5976 | bool found = false; |
| 5977 | int i; |
| 5978 | |
| 5979 | /* only process one nested attribute */ |
| 5980 | nest = nla_data(nla); |
| 5981 | if (!nla_ok(nest, nla_len(nest))) |
| 5982 | return -EINVAL; |
| 5983 | |
| 5984 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), |
| 5985 | nla_len(nest), nl80211_bss_select_policy); |
| 5986 | if (err) |
| 5987 | return err; |
| 5988 | |
| 5989 | /* only one attribute may be given */ |
| 5990 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 5991 | if (attr[i]) { |
| 5992 | if (found) |
| 5993 | return -EINVAL; |
| 5994 | found = true; |
| 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 5999 | |
| 6000 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6001 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6002 | |
| 6003 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6004 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6005 | bss_select->param.band_pref = |
| 6006 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6007 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6008 | return -EINVAL; |
| 6009 | } |
| 6010 | |
| 6011 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6012 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6013 | |
| 6014 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6015 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6016 | bss_select->param.adjust.band = adj_param->band; |
| 6017 | bss_select->param.adjust.delta = adj_param->delta; |
| 6018 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6019 | return -EINVAL; |
| 6020 | } |
| 6021 | |
| 6022 | /* user-space did not provide behaviour attribute */ |
| 6023 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6024 | return -EINVAL; |
| 6025 | |
| 6026 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6027 | return -EINVAL; |
| 6028 | |
| 6029 | return 0; |
| 6030 | } |
| 6031 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6032 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6033 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6034 | { |
| 6035 | int i; |
| 6036 | |
| 6037 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6038 | eth_zero_addr(mac_addr); |
| 6039 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6040 | mac_addr[0] = 0x2; |
| 6041 | mac_addr_mask[0] = 0x3; |
| 6042 | |
| 6043 | return 0; |
| 6044 | } |
| 6045 | |
| 6046 | /* need both or none */ |
| 6047 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6048 | return -EINVAL; |
| 6049 | |
| 6050 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6051 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6052 | |
| 6053 | /* don't allow or configure an mcast address */ |
| 6054 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6055 | is_multicast_ether_addr(mac_addr)) |
| 6056 | return -EINVAL; |
| 6057 | |
| 6058 | /* |
| 6059 | * allow users to pass a MAC address that has bits set outside |
| 6060 | * of the mask, but don't bother drivers with having to deal |
| 6061 | * with such bits |
| 6062 | */ |
| 6063 | for (i = 0; i < ETH_ALEN; i++) |
| 6064 | mac_addr[i] &= mac_addr_mask[i]; |
| 6065 | |
| 6066 | return 0; |
| 6067 | } |
| 6068 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6069 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6072 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6073 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6074 | struct nlattr *attr; |
| 6075 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6076 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6077 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6078 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6079 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6080 | return -EINVAL; |
| 6081 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6082 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6083 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6084 | if (!rdev->ops->scan) |
| 6085 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6086 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6087 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6088 | err = -EBUSY; |
| 6089 | goto unlock; |
| 6090 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6091 | |
| 6092 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6093 | n_channels = validate_scan_freqs( |
| 6094 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6095 | if (!n_channels) { |
| 6096 | err = -EINVAL; |
| 6097 | goto unlock; |
| 6098 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6099 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6100 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6104 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6105 | n_ssids++; |
| 6106 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6107 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6108 | err = -EINVAL; |
| 6109 | goto unlock; |
| 6110 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6111 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6112 | if (info->attrs[NL80211_ATTR_IE]) |
| 6113 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6114 | else |
| 6115 | ie_len = 0; |
| 6116 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6117 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6118 | err = -EINVAL; |
| 6119 | goto unlock; |
| 6120 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6121 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6122 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6123 | + sizeof(*request->ssids) * n_ssids |
| 6124 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6125 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6126 | if (!request) { |
| 6127 | err = -ENOMEM; |
| 6128 | goto unlock; |
| 6129 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6130 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6131 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6132 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6133 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6134 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6135 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6136 | request->ie = (void *)(request->ssids + n_ssids); |
| 6137 | else |
| 6138 | request->ie = (void *)(request->channels + n_channels); |
| 6139 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6140 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6141 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6142 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6143 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6144 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6145 | struct ieee80211_channel *chan; |
| 6146 | |
| 6147 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6148 | |
| 6149 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6150 | err = -EINVAL; |
| 6151 | goto out_free; |
| 6152 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6153 | |
| 6154 | /* ignore disabled channels */ |
| 6155 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6156 | continue; |
| 6157 | |
| 6158 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6159 | i++; |
| 6160 | } |
| 6161 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6162 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6163 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6164 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6165 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6166 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6167 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6168 | if (!wiphy->bands[band]) |
| 6169 | continue; |
| 6170 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6171 | struct ieee80211_channel *chan; |
| 6172 | |
| 6173 | chan = &wiphy->bands[band]->channels[j]; |
| 6174 | |
| 6175 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6176 | continue; |
| 6177 | |
| 6178 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6179 | i++; |
| 6180 | } |
| 6181 | } |
| 6182 | } |
| 6183 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6184 | if (!i) { |
| 6185 | err = -EINVAL; |
| 6186 | goto out_free; |
| 6187 | } |
| 6188 | |
| 6189 | request->n_channels = i; |
| 6190 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6191 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6192 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6193 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6194 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6195 | err = -EINVAL; |
| 6196 | goto out_free; |
| 6197 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6198 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6199 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6200 | i++; |
| 6201 | } |
| 6202 | } |
| 6203 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6204 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6205 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6206 | memcpy((void *)request->ie, |
| 6207 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6208 | request->ie_len); |
| 6209 | } |
| 6210 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6211 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6212 | if (wiphy->bands[i]) |
| 6213 | request->rates[i] = |
| 6214 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6215 | |
| 6216 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6217 | nla_for_each_nested(attr, |
| 6218 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6219 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6220 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6221 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6222 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6223 | err = -EINVAL; |
| 6224 | goto out_free; |
| 6225 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6226 | |
| 6227 | if (!wiphy->bands[band]) |
| 6228 | continue; |
| 6229 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6230 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6231 | nla_data(attr), |
| 6232 | nla_len(attr), |
| 6233 | &request->rates[band]); |
| 6234 | if (err) |
| 6235 | goto out_free; |
| 6236 | } |
| 6237 | } |
| 6238 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6239 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6240 | if (!wiphy_ext_feature_isset(wiphy, |
| 6241 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6242 | err = -EOPNOTSUPP; |
| 6243 | goto out_free; |
| 6244 | } |
| 6245 | |
| 6246 | request->duration = |
| 6247 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6248 | request->duration_mandatory = |
| 6249 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6250 | } |
| 6251 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6252 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6253 | request->flags = nla_get_u32( |
| 6254 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6255 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6256 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6257 | err = -EOPNOTSUPP; |
| 6258 | goto out_free; |
| 6259 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6260 | |
| 6261 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6262 | if (!(wiphy->features & |
| 6263 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6264 | err = -EOPNOTSUPP; |
| 6265 | goto out_free; |
| 6266 | } |
| 6267 | |
| 6268 | if (wdev->current_bss) { |
| 6269 | err = -EOPNOTSUPP; |
| 6270 | goto out_free; |
| 6271 | } |
| 6272 | |
| 6273 | err = nl80211_parse_random_mac(info->attrs, |
| 6274 | request->mac_addr, |
| 6275 | request->mac_addr_mask); |
| 6276 | if (err) |
| 6277 | goto out_free; |
| 6278 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6279 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6280 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6281 | request->no_cck = |
| 6282 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6283 | |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6284 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6285 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6286 | ETH_ALEN); |
| 6287 | else |
| 6288 | eth_broadcast_addr(request->bssid); |
| 6289 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6290 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6291 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6292 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6293 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6294 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6295 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6296 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6297 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6298 | nl80211_send_scan_start(rdev, wdev); |
| 6299 | if (wdev->netdev) |
| 6300 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6302 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6303 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6304 | kfree(request); |
| 6305 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6306 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6307 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6308 | return err; |
| 6309 | } |
| 6310 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6311 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6312 | { |
| 6313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6314 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6315 | |
| 6316 | if (!rdev->ops->abort_scan) |
| 6317 | return -EOPNOTSUPP; |
| 6318 | |
| 6319 | if (rdev->scan_msg) |
| 6320 | return 0; |
| 6321 | |
| 6322 | if (!rdev->scan_req) |
| 6323 | return -ENOENT; |
| 6324 | |
| 6325 | rdev_abort_scan(rdev, wdev); |
| 6326 | return 0; |
| 6327 | } |
| 6328 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6329 | static int |
| 6330 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6331 | struct cfg80211_sched_scan_request *request, |
| 6332 | struct nlattr **attrs) |
| 6333 | { |
| 6334 | int tmp, err, i = 0; |
| 6335 | struct nlattr *attr; |
| 6336 | |
| 6337 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6338 | u32 interval; |
| 6339 | |
| 6340 | /* |
| 6341 | * If scan plans are not specified, |
| 6342 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6343 | * case one scan plan will be set with the specified scan |
| 6344 | * interval and infinite number of iterations. |
| 6345 | */ |
| 6346 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6347 | return -EINVAL; |
| 6348 | |
| 6349 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6350 | if (!interval) |
| 6351 | return -EINVAL; |
| 6352 | |
| 6353 | request->scan_plans[0].interval = |
| 6354 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6355 | if (!request->scan_plans[0].interval) |
| 6356 | return -EINVAL; |
| 6357 | |
| 6358 | if (request->scan_plans[0].interval > |
| 6359 | wiphy->max_sched_scan_plan_interval) |
| 6360 | request->scan_plans[0].interval = |
| 6361 | wiphy->max_sched_scan_plan_interval; |
| 6362 | |
| 6363 | return 0; |
| 6364 | } |
| 6365 | |
| 6366 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6367 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6368 | |
| 6369 | if (WARN_ON(i >= n_plans)) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6373 | nla_data(attr), nla_len(attr), |
| 6374 | nl80211_plan_policy); |
| 6375 | if (err) |
| 6376 | return err; |
| 6377 | |
| 6378 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6379 | return -EINVAL; |
| 6380 | |
| 6381 | request->scan_plans[i].interval = |
| 6382 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6383 | if (!request->scan_plans[i].interval || |
| 6384 | request->scan_plans[i].interval > |
| 6385 | wiphy->max_sched_scan_plan_interval) |
| 6386 | return -EINVAL; |
| 6387 | |
| 6388 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6389 | request->scan_plans[i].iterations = |
| 6390 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6391 | if (!request->scan_plans[i].iterations || |
| 6392 | (request->scan_plans[i].iterations > |
| 6393 | wiphy->max_sched_scan_plan_iterations)) |
| 6394 | return -EINVAL; |
| 6395 | } else if (i < n_plans - 1) { |
| 6396 | /* |
| 6397 | * All scan plans but the last one must specify |
| 6398 | * a finite number of iterations |
| 6399 | */ |
| 6400 | return -EINVAL; |
| 6401 | } |
| 6402 | |
| 6403 | i++; |
| 6404 | } |
| 6405 | |
| 6406 | /* |
| 6407 | * The last scan plan must not specify the number of |
| 6408 | * iterations, it is supposed to run infinitely |
| 6409 | */ |
| 6410 | if (request->scan_plans[n_plans - 1].iterations) |
| 6411 | return -EINVAL; |
| 6412 | |
| 6413 | return 0; |
| 6414 | } |
| 6415 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6416 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6417 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6418 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6419 | { |
| 6420 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6421 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6422 | 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] | 6423 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6424 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6425 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6426 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6427 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6428 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6429 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6430 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6431 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6432 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6433 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6434 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6435 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6436 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6437 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6438 | } |
| 6439 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6440 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6441 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6442 | tmp) |
| 6443 | n_ssids++; |
| 6444 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6445 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6446 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6447 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6448 | /* |
| 6449 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6450 | * the old implementation, matchsets containing only the RSSI attribute |
| 6451 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6452 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6453 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6454 | * older userspace that treated a matchset with only the RSSI as the |
| 6455 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6456 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6457 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6458 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6459 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6460 | tmp) { |
| 6461 | struct nlattr *rssi; |
| 6462 | |
| 6463 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6464 | nla_data(attr), nla_len(attr), |
| 6465 | nl80211_match_policy); |
| 6466 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6467 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6468 | /* add other standalone attributes here */ |
| 6469 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6470 | n_match_sets++; |
| 6471 | continue; |
| 6472 | } |
| 6473 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6474 | if (rssi) |
| 6475 | default_match_rssi = nla_get_s32(rssi); |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | /* However, if there's no other matchset, add the RSSI one */ |
| 6480 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6481 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6482 | |
| 6483 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6484 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6485 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6486 | if (attrs[NL80211_ATTR_IE]) |
| 6487 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6488 | else |
| 6489 | ie_len = 0; |
| 6490 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6491 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6492 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6493 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6494 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6495 | /* |
| 6496 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6497 | * each scan plan already specifies its own interval |
| 6498 | */ |
| 6499 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6500 | return ERR_PTR(-EINVAL); |
| 6501 | |
| 6502 | nla_for_each_nested(attr, |
| 6503 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6504 | n_plans++; |
| 6505 | } else { |
| 6506 | /* |
| 6507 | * The scan interval attribute is kept for backward |
| 6508 | * compatibility. If no scan plans are specified and sched scan |
| 6509 | * interval is specified, one scan plan will be set with this |
| 6510 | * scan interval and infinite number of iterations. |
| 6511 | */ |
| 6512 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6513 | return ERR_PTR(-EINVAL); |
| 6514 | |
| 6515 | n_plans = 1; |
| 6516 | } |
| 6517 | |
| 6518 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6519 | return ERR_PTR(-EINVAL); |
| 6520 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6521 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6522 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6523 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6524 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6525 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6526 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6527 | if (!request) |
| 6528 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6529 | |
| 6530 | if (n_ssids) |
| 6531 | request->ssids = (void *)&request->channels[n_channels]; |
| 6532 | request->n_ssids = n_ssids; |
| 6533 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6534 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6535 | request->ie = (void *)(request->ssids + n_ssids); |
| 6536 | else |
| 6537 | request->ie = (void *)(request->channels + n_channels); |
| 6538 | } |
| 6539 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6540 | if (n_match_sets) { |
| 6541 | if (request->ie) |
| 6542 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6543 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6544 | request->match_sets = |
| 6545 | (void *)(request->ssids + n_ssids); |
| 6546 | else |
| 6547 | request->match_sets = |
| 6548 | (void *)(request->channels + n_channels); |
| 6549 | } |
| 6550 | request->n_match_sets = n_match_sets; |
| 6551 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6552 | if (n_match_sets) |
| 6553 | request->scan_plans = (void *)(request->match_sets + |
| 6554 | n_match_sets); |
| 6555 | else if (request->ie) |
| 6556 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6557 | else if (n_ssids) |
| 6558 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6559 | else |
| 6560 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6561 | |
| 6562 | request->n_scan_plans = n_plans; |
| 6563 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6564 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6565 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6566 | /* user specified, bail out if channel not found */ |
| 6567 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6568 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6569 | tmp) { |
| 6570 | struct ieee80211_channel *chan; |
| 6571 | |
| 6572 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6573 | |
| 6574 | if (!chan) { |
| 6575 | err = -EINVAL; |
| 6576 | goto out_free; |
| 6577 | } |
| 6578 | |
| 6579 | /* ignore disabled channels */ |
| 6580 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6581 | continue; |
| 6582 | |
| 6583 | request->channels[i] = chan; |
| 6584 | i++; |
| 6585 | } |
| 6586 | } else { |
| 6587 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6588 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6589 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6590 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6591 | if (!wiphy->bands[band]) |
| 6592 | continue; |
| 6593 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6594 | struct ieee80211_channel *chan; |
| 6595 | |
| 6596 | chan = &wiphy->bands[band]->channels[j]; |
| 6597 | |
| 6598 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6599 | continue; |
| 6600 | |
| 6601 | request->channels[i] = chan; |
| 6602 | i++; |
| 6603 | } |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | if (!i) { |
| 6608 | err = -EINVAL; |
| 6609 | goto out_free; |
| 6610 | } |
| 6611 | |
| 6612 | request->n_channels = i; |
| 6613 | |
| 6614 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6615 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6616 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6617 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6618 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6619 | err = -EINVAL; |
| 6620 | goto out_free; |
| 6621 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6622 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6623 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6624 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6625 | i++; |
| 6626 | } |
| 6627 | } |
| 6628 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6629 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6630 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6631 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6632 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6633 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6634 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6635 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6636 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6637 | nla_data(attr), nla_len(attr), |
| 6638 | nl80211_match_policy); |
| 6639 | if (err) |
| 6640 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6641 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6642 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6643 | if (WARN_ON(i >= n_match_sets)) { |
| 6644 | /* this indicates a programming error, |
| 6645 | * the loop above should have verified |
| 6646 | * things properly |
| 6647 | */ |
| 6648 | err = -EINVAL; |
| 6649 | goto out_free; |
| 6650 | } |
| 6651 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6652 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6653 | err = -EINVAL; |
| 6654 | goto out_free; |
| 6655 | } |
| 6656 | memcpy(request->match_sets[i].ssid.ssid, |
| 6657 | nla_data(ssid), nla_len(ssid)); |
| 6658 | request->match_sets[i].ssid.ssid_len = |
| 6659 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 6660 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6661 | request->match_sets[i].rssi_thold = |
| 6662 | default_match_rssi; |
| 6663 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6664 | if (rssi) |
| 6665 | request->match_sets[i].rssi_thold = |
| 6666 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6667 | } |
| 6668 | i++; |
| 6669 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6670 | |
| 6671 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 6672 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6673 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6674 | |
| 6675 | request->min_rssi_thold = INT_MAX; |
| 6676 | for (i = 0; i < n_match_sets; i++) |
| 6677 | request->min_rssi_thold = |
| 6678 | min(request->match_sets[i].rssi_thold, |
| 6679 | request->min_rssi_thold); |
| 6680 | } else { |
| 6681 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6682 | } |
| 6683 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6684 | if (ie_len) { |
| 6685 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6686 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6687 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6688 | request->ie_len); |
| 6689 | } |
| 6690 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6691 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6692 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6693 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6694 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6695 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6696 | err = -EOPNOTSUPP; |
| 6697 | goto out_free; |
| 6698 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6699 | |
| 6700 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6701 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6702 | |
| 6703 | if (!wdev) /* must be net-detect */ |
| 6704 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6705 | |
| 6706 | if (!(wiphy->features & flg)) { |
| 6707 | err = -EOPNOTSUPP; |
| 6708 | goto out_free; |
| 6709 | } |
| 6710 | |
| 6711 | if (wdev && wdev->current_bss) { |
| 6712 | err = -EOPNOTSUPP; |
| 6713 | goto out_free; |
| 6714 | } |
| 6715 | |
| 6716 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6717 | request->mac_addr_mask); |
| 6718 | if (err) |
| 6719 | goto out_free; |
| 6720 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6721 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6722 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 6723 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 6724 | request->delay = |
| 6725 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 6726 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6727 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 6728 | if (err) |
| 6729 | goto out_free; |
| 6730 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6731 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6732 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6733 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6734 | |
| 6735 | out_free: |
| 6736 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6737 | return ERR_PTR(err); |
| 6738 | } |
| 6739 | |
| 6740 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6741 | struct genl_info *info) |
| 6742 | { |
| 6743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6744 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6745 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6746 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6747 | int err; |
| 6748 | |
| 6749 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6750 | !rdev->ops->sched_scan_start) |
| 6751 | return -EOPNOTSUPP; |
| 6752 | |
| 6753 | if (rdev->sched_scan_req) |
| 6754 | return -EINPROGRESS; |
| 6755 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6756 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 6757 | info->attrs); |
| 6758 | |
| 6759 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6760 | if (err) |
| 6761 | goto out_err; |
| 6762 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6763 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6764 | if (err) |
| 6765 | goto out_free; |
| 6766 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6767 | sched_scan_req->dev = dev; |
| 6768 | sched_scan_req->wiphy = &rdev->wiphy; |
| 6769 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 6770 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 6771 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 6772 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6773 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6774 | |
| 6775 | nl80211_send_sched_scan(rdev, dev, |
| 6776 | NL80211_CMD_START_SCHED_SCAN); |
| 6777 | return 0; |
| 6778 | |
| 6779 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 6780 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6781 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6782 | return err; |
| 6783 | } |
| 6784 | |
| 6785 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6786 | struct genl_info *info) |
| 6787 | { |
| 6788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6789 | |
| 6790 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6791 | !rdev->ops->sched_scan_stop) |
| 6792 | return -EOPNOTSUPP; |
| 6793 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6794 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6795 | } |
| 6796 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6797 | static int nl80211_start_radar_detection(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]; |
| 6802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6803 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6804 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6805 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6806 | int err; |
| 6807 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6808 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6809 | if (dfs_region == NL80211_DFS_UNSET) |
| 6810 | return -EINVAL; |
| 6811 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6812 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6813 | if (err) |
| 6814 | return err; |
| 6815 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6816 | if (netif_carrier_ok(dev)) |
| 6817 | return -EBUSY; |
| 6818 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6819 | if (wdev->cac_started) |
| 6820 | return -EBUSY; |
| 6821 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6822 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6823 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6824 | if (err < 0) |
| 6825 | return err; |
| 6826 | |
| 6827 | if (err == 0) |
| 6828 | return -EINVAL; |
| 6829 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6830 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6831 | return -EINVAL; |
| 6832 | |
| 6833 | if (!rdev->ops->start_radar_detection) |
| 6834 | return -EOPNOTSUPP; |
| 6835 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6836 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6837 | if (WARN_ON(!cac_time_ms)) |
| 6838 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6839 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 6840 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6841 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6842 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6843 | wdev->cac_started = true; |
| 6844 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6845 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6846 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6847 | return err; |
| 6848 | } |
| 6849 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6850 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6851 | { |
| 6852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6853 | struct net_device *dev = info->user_ptr[1]; |
| 6854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6855 | struct cfg80211_csa_settings params; |
| 6856 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6857 | * function is called under RTNL lock, so this should not be a problem. |
| 6858 | */ |
| 6859 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6860 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6861 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6862 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6863 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6864 | |
| 6865 | if (!rdev->ops->channel_switch || |
| 6866 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6867 | return -EOPNOTSUPP; |
| 6868 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6869 | switch (dev->ieee80211_ptr->iftype) { |
| 6870 | case NL80211_IFTYPE_AP: |
| 6871 | case NL80211_IFTYPE_P2P_GO: |
| 6872 | need_new_beacon = true; |
| 6873 | |
| 6874 | /* useless if AP is not running */ |
| 6875 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6876 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6877 | break; |
| 6878 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6879 | if (!wdev->ssid_len) |
| 6880 | return -ENOTCONN; |
| 6881 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6882 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6883 | if (!wdev->mesh_id_len) |
| 6884 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6885 | break; |
| 6886 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6887 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6888 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6889 | |
| 6890 | memset(¶ms, 0, sizeof(params)); |
| 6891 | |
| 6892 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6893 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6894 | return -EINVAL; |
| 6895 | |
| 6896 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6897 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6898 | return -EINVAL; |
| 6899 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6900 | /* Even though the attribute is u32, the specification says |
| 6901 | * u8, so let's make sure we don't overflow. |
| 6902 | */ |
| 6903 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6904 | if (cs_count > 255) |
| 6905 | return -EINVAL; |
| 6906 | |
| 6907 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6908 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6909 | if (!need_new_beacon) |
| 6910 | goto skip_beacons; |
| 6911 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6912 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6913 | if (err) |
| 6914 | return err; |
| 6915 | |
| 6916 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6917 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6918 | nl80211_policy); |
| 6919 | if (err) |
| 6920 | return err; |
| 6921 | |
| 6922 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6923 | if (err) |
| 6924 | return err; |
| 6925 | |
| 6926 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6927 | return -EINVAL; |
| 6928 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6929 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6930 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6931 | return -EINVAL; |
| 6932 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6933 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6934 | if (rdev->wiphy.max_num_csa_counters && |
| 6935 | (params.n_counter_offsets_beacon > |
| 6936 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6937 | return -EINVAL; |
| 6938 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6939 | params.counter_offsets_beacon = |
| 6940 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6941 | |
| 6942 | /* sanity checks - counters should fit and be the same */ |
| 6943 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6944 | u16 offset = params.counter_offsets_beacon[i]; |
| 6945 | |
| 6946 | if (offset >= params.beacon_csa.tail_len) |
| 6947 | return -EINVAL; |
| 6948 | |
| 6949 | if (params.beacon_csa.tail[offset] != params.count) |
| 6950 | return -EINVAL; |
| 6951 | } |
| 6952 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6953 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6954 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6955 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6956 | return -EINVAL; |
| 6957 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6958 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6959 | if (rdev->wiphy.max_num_csa_counters && |
| 6960 | (params.n_counter_offsets_beacon > |
| 6961 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6962 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6963 | |
| 6964 | params.counter_offsets_presp = |
| 6965 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6966 | |
| 6967 | /* sanity checks - counters should fit and be the same */ |
| 6968 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6969 | u16 offset = params.counter_offsets_presp[i]; |
| 6970 | |
| 6971 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6972 | return -EINVAL; |
| 6973 | |
| 6974 | if (params.beacon_csa.probe_resp[offset] != |
| 6975 | params.count) |
| 6976 | return -EINVAL; |
| 6977 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6978 | } |
| 6979 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6980 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6981 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6982 | if (err) |
| 6983 | return err; |
| 6984 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 6985 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 6986 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6987 | return -EINVAL; |
| 6988 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6989 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6990 | ¶ms.chandef, |
| 6991 | wdev->iftype); |
| 6992 | if (err < 0) |
| 6993 | return err; |
| 6994 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6995 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6996 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6997 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6998 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6999 | params.block_tx = true; |
| 7000 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7001 | wdev_lock(wdev); |
| 7002 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7003 | wdev_unlock(wdev); |
| 7004 | |
| 7005 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7006 | } |
| 7007 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7008 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7009 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7010 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7011 | struct wireless_dev *wdev, |
| 7012 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7013 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7014 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7015 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7016 | void *hdr; |
| 7017 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7018 | |
| 7019 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7020 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7021 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7022 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7023 | if (!hdr) |
| 7024 | return -1; |
| 7025 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7026 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7027 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7028 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7029 | goto nla_put_failure; |
| 7030 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7031 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7032 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7033 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7034 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7035 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7036 | |
| 7037 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7038 | if (!bss) |
| 7039 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7040 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7041 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7042 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7043 | |
| 7044 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7045 | /* indicate whether we have probe response data or not */ |
| 7046 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7047 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7048 | goto fail_unlock_rcu; |
| 7049 | |
| 7050 | /* this pointer prefers to be pointed to probe response data |
| 7051 | * but is always valid |
| 7052 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7053 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7054 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7055 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7056 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7057 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7058 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7059 | ies->len, ies->data)) |
| 7060 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7061 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7062 | |
| 7063 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7064 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7065 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7066 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7067 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7068 | goto fail_unlock_rcu; |
| 7069 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7070 | ies->len, ies->data)) |
| 7071 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7072 | } |
| 7073 | rcu_read_unlock(); |
| 7074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7075 | if (res->beacon_interval && |
| 7076 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7077 | goto nla_put_failure; |
| 7078 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7079 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7080 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7081 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7082 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7083 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7084 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7085 | if (intbss->parent_tsf && |
| 7086 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7087 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7088 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7089 | intbss->parent_bssid))) |
| 7090 | goto nla_put_failure; |
| 7091 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7092 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7093 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7094 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7095 | goto nla_put_failure; |
| 7096 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7097 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7098 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7099 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7100 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7101 | break; |
| 7102 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7103 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7104 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7105 | break; |
| 7106 | default: |
| 7107 | break; |
| 7108 | } |
| 7109 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7110 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7111 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7112 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7113 | if (intbss == wdev->current_bss && |
| 7114 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7115 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7116 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7117 | break; |
| 7118 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7119 | if (intbss == wdev->current_bss && |
| 7120 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7121 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7122 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7123 | break; |
| 7124 | default: |
| 7125 | break; |
| 7126 | } |
| 7127 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7128 | nla_nest_end(msg, bss); |
| 7129 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7130 | genlmsg_end(msg, hdr); |
| 7131 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7132 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7133 | fail_unlock_rcu: |
| 7134 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7135 | nla_put_failure: |
| 7136 | genlmsg_cancel(msg, hdr); |
| 7137 | return -EMSGSIZE; |
| 7138 | } |
| 7139 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7140 | 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] | 7141 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7142 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7143 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7144 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7145 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7146 | int err; |
| 7147 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7148 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7149 | if (err) |
| 7150 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7151 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7152 | wdev_lock(wdev); |
| 7153 | spin_lock_bh(&rdev->bss_lock); |
| 7154 | cfg80211_bss_expire(rdev); |
| 7155 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7156 | cb->seq = rdev->bss_generation; |
| 7157 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7158 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7159 | if (++idx <= start) |
| 7160 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7161 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7162 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7163 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7164 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7165 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7166 | } |
| 7167 | } |
| 7168 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7169 | spin_unlock_bh(&rdev->bss_lock); |
| 7170 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7171 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7172 | cb->args[2] = idx; |
| 7173 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7174 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7175 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7176 | } |
| 7177 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7178 | 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] | 7179 | int flags, struct net_device *dev, |
| 7180 | bool allow_radio_stats, |
| 7181 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7182 | { |
| 7183 | void *hdr; |
| 7184 | struct nlattr *infoattr; |
| 7185 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7186 | /* skip radio stats if userspace didn't request them */ |
| 7187 | if (!survey->channel && !allow_radio_stats) |
| 7188 | return 0; |
| 7189 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7190 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7191 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7192 | if (!hdr) |
| 7193 | return -ENOMEM; |
| 7194 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7195 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7196 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7197 | |
| 7198 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7199 | if (!infoattr) |
| 7200 | goto nla_put_failure; |
| 7201 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7202 | if (survey->channel && |
| 7203 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7204 | survey->channel->center_freq)) |
| 7205 | goto nla_put_failure; |
| 7206 | |
| 7207 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7208 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7209 | goto nla_put_failure; |
| 7210 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7211 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7212 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7213 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7214 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7215 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7216 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7217 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7218 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7219 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7220 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7221 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7222 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7223 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7224 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7225 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7226 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7227 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7228 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7229 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7230 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7231 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7232 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7233 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7234 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7235 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7236 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7237 | |
| 7238 | nla_nest_end(msg, infoattr); |
| 7239 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7240 | genlmsg_end(msg, hdr); |
| 7241 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7242 | |
| 7243 | nla_put_failure: |
| 7244 | genlmsg_cancel(msg, hdr); |
| 7245 | return -EMSGSIZE; |
| 7246 | } |
| 7247 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7248 | 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] | 7249 | { |
| 7250 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7251 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7252 | struct wireless_dev *wdev; |
| 7253 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7254 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7255 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7256 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7257 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7258 | if (res) |
| 7259 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7260 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7261 | /* prepare_wdev_dump parsed the attributes */ |
| 7262 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 7263 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7264 | if (!wdev->netdev) { |
| 7265 | res = -EINVAL; |
| 7266 | goto out_err; |
| 7267 | } |
| 7268 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7269 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7270 | res = -EOPNOTSUPP; |
| 7271 | goto out_err; |
| 7272 | } |
| 7273 | |
| 7274 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7275 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7276 | if (res == -ENOENT) |
| 7277 | break; |
| 7278 | if (res) |
| 7279 | goto out_err; |
| 7280 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7281 | /* don't send disabled channels, but do send non-channel data */ |
| 7282 | if (survey.channel && |
| 7283 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7284 | survey_idx++; |
| 7285 | continue; |
| 7286 | } |
| 7287 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7288 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7289 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7290 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7291 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7292 | goto out; |
| 7293 | survey_idx++; |
| 7294 | } |
| 7295 | |
| 7296 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7297 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7298 | res = skb->len; |
| 7299 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7300 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7301 | return res; |
| 7302 | } |
| 7303 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7304 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7305 | { |
| 7306 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7307 | NL80211_WPA_VERSION_2)); |
| 7308 | } |
| 7309 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7310 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7311 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7312 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7313 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7314 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7315 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 7316 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7317 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7318 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7319 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7320 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7321 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7322 | return -EINVAL; |
| 7323 | |
| 7324 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7325 | return -EINVAL; |
| 7326 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7327 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7328 | return -EINVAL; |
| 7329 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7330 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7331 | return -EINVAL; |
| 7332 | |
| 7333 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7334 | return -EINVAL; |
| 7335 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7336 | err = nl80211_parse_key(info, &key); |
| 7337 | if (err) |
| 7338 | return err; |
| 7339 | |
| 7340 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7341 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7342 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7343 | if (!key.p.key || !key.p.key_len) |
| 7344 | return -EINVAL; |
| 7345 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7346 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7347 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7348 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7349 | return -EINVAL; |
| 7350 | if (key.idx > 4) |
| 7351 | return -EINVAL; |
| 7352 | } else { |
| 7353 | key.p.key_len = 0; |
| 7354 | key.p.key = NULL; |
| 7355 | } |
| 7356 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7357 | if (key.idx >= 0) { |
| 7358 | int i; |
| 7359 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7360 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7361 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7362 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7363 | ok = true; |
| 7364 | break; |
| 7365 | } |
| 7366 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7367 | if (!ok) |
| 7368 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7369 | } |
| 7370 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7371 | if (!rdev->ops->auth) |
| 7372 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7373 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7374 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7375 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7376 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7377 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7378 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7379 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7380 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7381 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7382 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7383 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7384 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7385 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7386 | |
| 7387 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7388 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7389 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7390 | } |
| 7391 | |
| 7392 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7393 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7394 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7395 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7396 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7397 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7398 | return -EINVAL; |
| 7399 | |
| 7400 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7401 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7402 | return -EINVAL; |
| 7403 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7404 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7405 | /* need to include at least Auth Transaction and Status Code */ |
| 7406 | if (sae_data_len < 4) |
| 7407 | return -EINVAL; |
| 7408 | } |
| 7409 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7410 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7411 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7412 | /* |
| 7413 | * Since we no longer track auth state, ignore |
| 7414 | * requests to only change local state. |
| 7415 | */ |
| 7416 | if (local_state_change) |
| 7417 | return 0; |
| 7418 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7419 | wdev_lock(dev->ieee80211_ptr); |
| 7420 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7421 | ssid, ssid_len, ie, ie_len, |
| 7422 | key.p.key, key.p.key_len, key.idx, |
| 7423 | sae_data, sae_data_len); |
| 7424 | wdev_unlock(dev->ieee80211_ptr); |
| 7425 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7426 | } |
| 7427 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7428 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7429 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7430 | struct cfg80211_crypto_settings *settings, |
| 7431 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7432 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7433 | memset(settings, 0, sizeof(*settings)); |
| 7434 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7435 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7436 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7437 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7438 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7439 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7440 | proto = nla_get_u16( |
| 7441 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7442 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7443 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7444 | proto != ETH_P_PAE) |
| 7445 | return -EINVAL; |
| 7446 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7447 | settings->control_port_no_encrypt = true; |
| 7448 | } else |
| 7449 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7450 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7451 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7452 | void *data; |
| 7453 | int len, i; |
| 7454 | |
| 7455 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7456 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7457 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7458 | |
| 7459 | if (len % sizeof(u32)) |
| 7460 | return -EINVAL; |
| 7461 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7462 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7463 | return -EINVAL; |
| 7464 | |
| 7465 | memcpy(settings->ciphers_pairwise, data, len); |
| 7466 | |
| 7467 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7468 | if (!cfg80211_supported_cipher_suite( |
| 7469 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7470 | settings->ciphers_pairwise[i])) |
| 7471 | return -EINVAL; |
| 7472 | } |
| 7473 | |
| 7474 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7475 | settings->cipher_group = |
| 7476 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7477 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7478 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7479 | return -EINVAL; |
| 7480 | } |
| 7481 | |
| 7482 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7483 | settings->wpa_versions = |
| 7484 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7485 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7486 | return -EINVAL; |
| 7487 | } |
| 7488 | |
| 7489 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7490 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7491 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7492 | |
| 7493 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7494 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7495 | settings->n_akm_suites = len / sizeof(u32); |
| 7496 | |
| 7497 | if (len % sizeof(u32)) |
| 7498 | return -EINVAL; |
| 7499 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7500 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7501 | return -EINVAL; |
| 7502 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7503 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7504 | } |
| 7505 | |
| 7506 | return 0; |
| 7507 | } |
| 7508 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7509 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7510 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7511 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7512 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7513 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7514 | struct cfg80211_assoc_request req = {}; |
| 7515 | const u8 *bssid, *ssid; |
| 7516 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7517 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7518 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7519 | return -EINVAL; |
| 7520 | |
| 7521 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7522 | !info->attrs[NL80211_ATTR_SSID] || |
| 7523 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7524 | return -EINVAL; |
| 7525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7526 | if (!rdev->ops->assoc) |
| 7527 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7528 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7529 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7531 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7532 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7533 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7534 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7535 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7536 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7537 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7538 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7539 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7540 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7541 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7542 | |
| 7543 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7544 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7545 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7546 | } |
| 7547 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7548 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7549 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7550 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7551 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7552 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7553 | else if (mfp != NL80211_MFP_NO) |
| 7554 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7555 | } |
| 7556 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7557 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7558 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7559 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7560 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7561 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7562 | |
| 7563 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7564 | memcpy(&req.ht_capa_mask, |
| 7565 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7566 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7567 | |
| 7568 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7569 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7570 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7571 | memcpy(&req.ht_capa, |
| 7572 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7573 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7574 | } |
| 7575 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7576 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7577 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7578 | |
| 7579 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7580 | memcpy(&req.vht_capa_mask, |
| 7581 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7582 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7583 | |
| 7584 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7585 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7586 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7587 | memcpy(&req.vht_capa, |
| 7588 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7589 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7590 | } |
| 7591 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7592 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 7593 | if (!((rdev->wiphy.features & |
| 7594 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 7595 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 7596 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 7597 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7598 | return -EINVAL; |
| 7599 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7600 | } |
| 7601 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7602 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7603 | if (!err) { |
| 7604 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7605 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7606 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7607 | wdev_unlock(dev->ieee80211_ptr); |
| 7608 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7609 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7610 | return err; |
| 7611 | } |
| 7612 | |
| 7613 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7614 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7616 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7617 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7618 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7619 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7620 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7621 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7622 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7623 | return -EINVAL; |
| 7624 | |
| 7625 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7626 | return -EINVAL; |
| 7627 | |
| 7628 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7629 | return -EINVAL; |
| 7630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7631 | if (!rdev->ops->deauth) |
| 7632 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7633 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7634 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7635 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7636 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7637 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7638 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7639 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7640 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7641 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7642 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7643 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7644 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7645 | |
| 7646 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7647 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7648 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7649 | } |
| 7650 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7651 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7652 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7653 | wdev_lock(dev->ieee80211_ptr); |
| 7654 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7655 | local_state_change); |
| 7656 | wdev_unlock(dev->ieee80211_ptr); |
| 7657 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7663 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7664 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7665 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7666 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7667 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7668 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7669 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7670 | return -EINVAL; |
| 7671 | |
| 7672 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7673 | return -EINVAL; |
| 7674 | |
| 7675 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7676 | return -EINVAL; |
| 7677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7678 | if (!rdev->ops->disassoc) |
| 7679 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7680 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7681 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7682 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7683 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7684 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7685 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7686 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7687 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7688 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7689 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7690 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7691 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7692 | |
| 7693 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7694 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7695 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7696 | } |
| 7697 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7698 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7699 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7700 | wdev_lock(dev->ieee80211_ptr); |
| 7701 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7702 | local_state_change); |
| 7703 | wdev_unlock(dev->ieee80211_ptr); |
| 7704 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7705 | } |
| 7706 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7707 | static bool |
| 7708 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7709 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7710 | int rateval) |
| 7711 | { |
| 7712 | struct wiphy *wiphy = &rdev->wiphy; |
| 7713 | bool found = false; |
| 7714 | int band, i; |
| 7715 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7716 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7717 | struct ieee80211_supported_band *sband; |
| 7718 | |
| 7719 | sband = wiphy->bands[band]; |
| 7720 | if (!sband) |
| 7721 | continue; |
| 7722 | |
| 7723 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7724 | if (sband->bitrates[i].bitrate == rateval) { |
| 7725 | mcast_rate[band] = i + 1; |
| 7726 | found = true; |
| 7727 | break; |
| 7728 | } |
| 7729 | } |
| 7730 | } |
| 7731 | |
| 7732 | return found; |
| 7733 | } |
| 7734 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7735 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7738 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7739 | struct cfg80211_ibss_params ibss; |
| 7740 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7741 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7742 | int err; |
| 7743 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7744 | memset(&ibss, 0, sizeof(ibss)); |
| 7745 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7746 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7747 | return -EINVAL; |
| 7748 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7749 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7750 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7751 | return -EINVAL; |
| 7752 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7753 | ibss.beacon_interval = 100; |
| 7754 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame^] | 7755 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7756 | ibss.beacon_interval = |
| 7757 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame^] | 7758 | |
| 7759 | err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval); |
| 7760 | if (err) |
| 7761 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7763 | if (!rdev->ops->join_ibss) |
| 7764 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7765 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7766 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7767 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7768 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7769 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7770 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7771 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7772 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7773 | |
| 7774 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7775 | return -EINVAL; |
| 7776 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7777 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7778 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7779 | |
| 7780 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7781 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7782 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7783 | } |
| 7784 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7785 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7786 | if (err) |
| 7787 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7788 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7789 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7790 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7791 | return -EINVAL; |
| 7792 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7793 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7794 | case NL80211_CHAN_WIDTH_5: |
| 7795 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7796 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7797 | break; |
| 7798 | case NL80211_CHAN_WIDTH_20: |
| 7799 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 7800 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7801 | return -EINVAL; |
| 7802 | break; |
| 7803 | case NL80211_CHAN_WIDTH_80: |
| 7804 | case NL80211_CHAN_WIDTH_80P80: |
| 7805 | case NL80211_CHAN_WIDTH_160: |
| 7806 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 7807 | return -EINVAL; |
| 7808 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 7809 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 7810 | return -EINVAL; |
| 7811 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7812 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7813 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7814 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7815 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7816 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7817 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7818 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7819 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7820 | u8 *rates = |
| 7821 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7822 | int n_rates = |
| 7823 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7824 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7825 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7826 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7827 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7828 | &ibss.basic_rates); |
| 7829 | if (err) |
| 7830 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7831 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7832 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7833 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7834 | memcpy(&ibss.ht_capa_mask, |
| 7835 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7836 | sizeof(ibss.ht_capa_mask)); |
| 7837 | |
| 7838 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7839 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7840 | return -EINVAL; |
| 7841 | memcpy(&ibss.ht_capa, |
| 7842 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7843 | sizeof(ibss.ht_capa)); |
| 7844 | } |
| 7845 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7846 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7847 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7848 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7849 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7851 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7852 | bool no_ht = false; |
| 7853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7854 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7855 | info->attrs[NL80211_ATTR_KEYS], |
| 7856 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7857 | if (IS_ERR(connkeys)) |
| 7858 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7859 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7860 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7861 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 7862 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7863 | return -EINVAL; |
| 7864 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7865 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7866 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7867 | ibss.control_port = |
| 7868 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7869 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7870 | ibss.userspace_handles_dfs = |
| 7871 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7872 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7873 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7874 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7875 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7876 | return err; |
| 7877 | } |
| 7878 | |
| 7879 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7880 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7882 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7884 | if (!rdev->ops->leave_ibss) |
| 7885 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7888 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7890 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7891 | } |
| 7892 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7893 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7894 | { |
| 7895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7896 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7897 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7898 | u32 nla_rate; |
| 7899 | int err; |
| 7900 | |
| 7901 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 7902 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 7903 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7904 | return -EOPNOTSUPP; |
| 7905 | |
| 7906 | if (!rdev->ops->set_mcast_rate) |
| 7907 | return -EOPNOTSUPP; |
| 7908 | |
| 7909 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7910 | |
| 7911 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7912 | return -EINVAL; |
| 7913 | |
| 7914 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7915 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7916 | return -EINVAL; |
| 7917 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7918 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7919 | |
| 7920 | return err; |
| 7921 | } |
| 7922 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7923 | static struct sk_buff * |
| 7924 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7925 | struct wireless_dev *wdev, int approxlen, |
| 7926 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7927 | enum nl80211_attrs attr, |
| 7928 | const struct nl80211_vendor_cmd_info *info, |
| 7929 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7930 | { |
| 7931 | struct sk_buff *skb; |
| 7932 | void *hdr; |
| 7933 | struct nlattr *data; |
| 7934 | |
| 7935 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7936 | if (!skb) |
| 7937 | return NULL; |
| 7938 | |
| 7939 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7940 | if (!hdr) { |
| 7941 | kfree_skb(skb); |
| 7942 | return NULL; |
| 7943 | } |
| 7944 | |
| 7945 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7946 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7947 | |
| 7948 | if (info) { |
| 7949 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7950 | info->vendor_id)) |
| 7951 | goto nla_put_failure; |
| 7952 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7953 | info->subcmd)) |
| 7954 | goto nla_put_failure; |
| 7955 | } |
| 7956 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7957 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7958 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 7959 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7960 | goto nla_put_failure; |
| 7961 | if (wdev->netdev && |
| 7962 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 7963 | wdev->netdev->ifindex)) |
| 7964 | goto nla_put_failure; |
| 7965 | } |
| 7966 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7967 | data = nla_nest_start(skb, attr); |
| 7968 | |
| 7969 | ((void **)skb->cb)[0] = rdev; |
| 7970 | ((void **)skb->cb)[1] = hdr; |
| 7971 | ((void **)skb->cb)[2] = data; |
| 7972 | |
| 7973 | return skb; |
| 7974 | |
| 7975 | nla_put_failure: |
| 7976 | kfree_skb(skb); |
| 7977 | return NULL; |
| 7978 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7979 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7980 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 7981 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7982 | enum nl80211_commands cmd, |
| 7983 | enum nl80211_attrs attr, |
| 7984 | int vendor_event_idx, |
| 7985 | int approxlen, gfp_t gfp) |
| 7986 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7987 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7988 | const struct nl80211_vendor_cmd_info *info; |
| 7989 | |
| 7990 | switch (cmd) { |
| 7991 | case NL80211_CMD_TESTMODE: |
| 7992 | if (WARN_ON(vendor_event_idx != -1)) |
| 7993 | return NULL; |
| 7994 | info = NULL; |
| 7995 | break; |
| 7996 | case NL80211_CMD_VENDOR: |
| 7997 | if (WARN_ON(vendor_event_idx < 0 || |
| 7998 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7999 | return NULL; |
| 8000 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8001 | break; |
| 8002 | default: |
| 8003 | WARN_ON(1); |
| 8004 | return NULL; |
| 8005 | } |
| 8006 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8007 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8008 | cmd, attr, info, gfp); |
| 8009 | } |
| 8010 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8011 | |
| 8012 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8013 | { |
| 8014 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8015 | void *hdr = ((void **)skb->cb)[1]; |
| 8016 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8017 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8018 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8019 | /* clear CB data for netlink core to own from now on */ |
| 8020 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8021 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8022 | nla_nest_end(skb, data); |
| 8023 | genlmsg_end(skb, hdr); |
| 8024 | |
| 8025 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8026 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8027 | |
| 8028 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8029 | mcgrp, gfp); |
| 8030 | } |
| 8031 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8032 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8033 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8034 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8037 | struct wireless_dev *wdev = |
| 8038 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8039 | int err; |
| 8040 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8041 | if (!rdev->ops->testmode_cmd) |
| 8042 | return -EOPNOTSUPP; |
| 8043 | |
| 8044 | if (IS_ERR(wdev)) { |
| 8045 | err = PTR_ERR(wdev); |
| 8046 | if (err != -EINVAL) |
| 8047 | return err; |
| 8048 | wdev = NULL; |
| 8049 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8050 | return -EINVAL; |
| 8051 | } |
| 8052 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8053 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8054 | return -EINVAL; |
| 8055 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8056 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8057 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8058 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8059 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8060 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8061 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8062 | return err; |
| 8063 | } |
| 8064 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8065 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8066 | struct netlink_callback *cb) |
| 8067 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8068 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8069 | int err; |
| 8070 | long phy_idx; |
| 8071 | void *data = NULL; |
| 8072 | int data_len = 0; |
| 8073 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8074 | rtnl_lock(); |
| 8075 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8076 | if (cb->args[0]) { |
| 8077 | /* |
| 8078 | * 0 is a valid index, but not valid for args[0], |
| 8079 | * so we need to offset by 1. |
| 8080 | */ |
| 8081 | phy_idx = cb->args[0] - 1; |
| 8082 | } else { |
| 8083 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 8084 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 8085 | nl80211_policy); |
| 8086 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8087 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8088 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8089 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 8090 | nl80211_fam.attrbuf); |
| 8091 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8092 | err = PTR_ERR(rdev); |
| 8093 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8094 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8095 | phy_idx = rdev->wiphy_idx; |
| 8096 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8097 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8098 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 8099 | cb->args[1] = |
| 8100 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 8101 | } |
| 8102 | |
| 8103 | if (cb->args[1]) { |
| 8104 | data = nla_data((void *)cb->args[1]); |
| 8105 | data_len = nla_len((void *)cb->args[1]); |
| 8106 | } |
| 8107 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8108 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8109 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8110 | err = -ENOENT; |
| 8111 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8112 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8113 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8114 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8115 | err = -EOPNOTSUPP; |
| 8116 | goto out_err; |
| 8117 | } |
| 8118 | |
| 8119 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8120 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8121 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8122 | NL80211_CMD_TESTMODE); |
| 8123 | struct nlattr *tmdata; |
| 8124 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8125 | if (!hdr) |
| 8126 | break; |
| 8127 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8128 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8129 | genlmsg_cancel(skb, hdr); |
| 8130 | break; |
| 8131 | } |
| 8132 | |
| 8133 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8134 | if (!tmdata) { |
| 8135 | genlmsg_cancel(skb, hdr); |
| 8136 | break; |
| 8137 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8138 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8139 | nla_nest_end(skb, tmdata); |
| 8140 | |
| 8141 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8142 | genlmsg_cancel(skb, hdr); |
| 8143 | break; |
| 8144 | } else if (err) { |
| 8145 | genlmsg_cancel(skb, hdr); |
| 8146 | goto out_err; |
| 8147 | } |
| 8148 | |
| 8149 | genlmsg_end(skb, hdr); |
| 8150 | } |
| 8151 | |
| 8152 | err = skb->len; |
| 8153 | /* see above */ |
| 8154 | cb->args[0] = phy_idx + 1; |
| 8155 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8156 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8157 | return err; |
| 8158 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8159 | #endif |
| 8160 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8161 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8162 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8163 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8164 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8165 | struct cfg80211_connect_params connect; |
| 8166 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8167 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8168 | int err; |
| 8169 | |
| 8170 | memset(&connect, 0, sizeof(connect)); |
| 8171 | |
| 8172 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8173 | return -EINVAL; |
| 8174 | |
| 8175 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8176 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8177 | return -EINVAL; |
| 8178 | |
| 8179 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8180 | connect.auth_type = |
| 8181 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8182 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8183 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8184 | return -EINVAL; |
| 8185 | } else |
| 8186 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8187 | |
| 8188 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8189 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8190 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8191 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8192 | if (err) |
| 8193 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8194 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8195 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8196 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8197 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8198 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8199 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8200 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8201 | connect.bg_scan_period = -1; |
| 8202 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8203 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8204 | connect.bg_scan_period = |
| 8205 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8206 | } |
| 8207 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8208 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8209 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8210 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8211 | connect.bssid_hint = |
| 8212 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8213 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8214 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8215 | |
| 8216 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8217 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8218 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8219 | } |
| 8220 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8221 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8222 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8223 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8224 | connect.mfp != NL80211_MFP_NO) |
| 8225 | return -EINVAL; |
| 8226 | } else { |
| 8227 | connect.mfp = NL80211_MFP_NO; |
| 8228 | } |
| 8229 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8230 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8231 | connect.prev_bssid = |
| 8232 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8233 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8234 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8235 | connect.channel = nl80211_get_valid_chan( |
| 8236 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8237 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8238 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8239 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8240 | connect.channel_hint = nl80211_get_valid_chan( |
| 8241 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8242 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8243 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8244 | } |
| 8245 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8246 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8247 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8248 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8249 | if (IS_ERR(connkeys)) |
| 8250 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8251 | } |
| 8252 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8253 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8254 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8255 | |
| 8256 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8257 | memcpy(&connect.ht_capa_mask, |
| 8258 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8259 | sizeof(connect.ht_capa_mask)); |
| 8260 | |
| 8261 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8262 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8263 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8264 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8265 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8266 | memcpy(&connect.ht_capa, |
| 8267 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8268 | sizeof(connect.ht_capa)); |
| 8269 | } |
| 8270 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8271 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8272 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8273 | |
| 8274 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8275 | memcpy(&connect.vht_capa_mask, |
| 8276 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8277 | sizeof(connect.vht_capa_mask)); |
| 8278 | |
| 8279 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8280 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8281 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8282 | return -EINVAL; |
| 8283 | } |
| 8284 | memcpy(&connect.vht_capa, |
| 8285 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8286 | sizeof(connect.vht_capa)); |
| 8287 | } |
| 8288 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8289 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8290 | if (!((rdev->wiphy.features & |
| 8291 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8292 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8293 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8294 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8295 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8296 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8297 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8298 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8299 | } |
| 8300 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8301 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8302 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8303 | kzfree(connkeys); |
| 8304 | return -EOPNOTSUPP; |
| 8305 | } |
| 8306 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8307 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8308 | /* bss selection makes no sense if bssid is set */ |
| 8309 | if (connect.bssid) { |
| 8310 | kzfree(connkeys); |
| 8311 | return -EINVAL; |
| 8312 | } |
| 8313 | |
| 8314 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8315 | wiphy, &connect.bss_select); |
| 8316 | if (err) { |
| 8317 | kzfree(connkeys); |
| 8318 | return err; |
| 8319 | } |
| 8320 | } |
| 8321 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8322 | wdev_lock(dev->ieee80211_ptr); |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8323 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8324 | connect.prev_bssid); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8325 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8326 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8327 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8328 | return err; |
| 8329 | } |
| 8330 | |
| 8331 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8332 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8334 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8335 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8336 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8337 | |
| 8338 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8339 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8340 | else |
| 8341 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8342 | |
| 8343 | if (reason == 0) |
| 8344 | return -EINVAL; |
| 8345 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8346 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8347 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8348 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8349 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8350 | wdev_lock(dev->ieee80211_ptr); |
| 8351 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8352 | wdev_unlock(dev->ieee80211_ptr); |
| 8353 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8354 | } |
| 8355 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8356 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8357 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8359 | struct net *net; |
| 8360 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8361 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8362 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8363 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8364 | |
| 8365 | net = get_net_ns_by_pid(pid); |
| 8366 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8367 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8368 | |
| 8369 | net = get_net_ns_by_fd(fd); |
| 8370 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8371 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8372 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8373 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8374 | if (IS_ERR(net)) |
| 8375 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8376 | |
| 8377 | err = 0; |
| 8378 | |
| 8379 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8380 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8381 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8382 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8383 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8384 | return err; |
| 8385 | } |
| 8386 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8387 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8388 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8390 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8391 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8392 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8393 | struct cfg80211_pmksa pmksa; |
| 8394 | |
| 8395 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8396 | |
| 8397 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8398 | return -EINVAL; |
| 8399 | |
| 8400 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8401 | return -EINVAL; |
| 8402 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8403 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8404 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8405 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8406 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8407 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8408 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8409 | |
| 8410 | switch (info->genlhdr->cmd) { |
| 8411 | case NL80211_CMD_SET_PMKSA: |
| 8412 | rdev_ops = rdev->ops->set_pmksa; |
| 8413 | break; |
| 8414 | case NL80211_CMD_DEL_PMKSA: |
| 8415 | rdev_ops = rdev->ops->del_pmksa; |
| 8416 | break; |
| 8417 | default: |
| 8418 | WARN_ON(1); |
| 8419 | break; |
| 8420 | } |
| 8421 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8422 | if (!rdev_ops) |
| 8423 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8424 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8425 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8426 | } |
| 8427 | |
| 8428 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8429 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8431 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8432 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8433 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8434 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8435 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8436 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8437 | if (!rdev->ops->flush_pmksa) |
| 8438 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8439 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8440 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8441 | } |
| 8442 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8443 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8444 | { |
| 8445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8446 | struct net_device *dev = info->user_ptr[1]; |
| 8447 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8448 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8449 | u16 status_code; |
| 8450 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8451 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8452 | |
| 8453 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8454 | !rdev->ops->tdls_mgmt) |
| 8455 | return -EOPNOTSUPP; |
| 8456 | |
| 8457 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8458 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8459 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8460 | !info->attrs[NL80211_ATTR_IE] || |
| 8461 | !info->attrs[NL80211_ATTR_MAC]) |
| 8462 | return -EINVAL; |
| 8463 | |
| 8464 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8465 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8466 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8467 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8468 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8469 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8470 | peer_capability = |
| 8471 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8472 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8473 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8474 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8475 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8476 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8477 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8481 | { |
| 8482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8483 | struct net_device *dev = info->user_ptr[1]; |
| 8484 | enum nl80211_tdls_operation operation; |
| 8485 | u8 *peer; |
| 8486 | |
| 8487 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8488 | !rdev->ops->tdls_oper) |
| 8489 | return -EOPNOTSUPP; |
| 8490 | |
| 8491 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8492 | !info->attrs[NL80211_ATTR_MAC]) |
| 8493 | return -EINVAL; |
| 8494 | |
| 8495 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8496 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8497 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8498 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8499 | } |
| 8500 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8501 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8502 | struct genl_info *info) |
| 8503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8505 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8506 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8507 | struct sk_buff *msg; |
| 8508 | void *hdr; |
| 8509 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8510 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8511 | int err; |
| 8512 | |
| 8513 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8514 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8515 | return -EINVAL; |
| 8516 | |
| 8517 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8518 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8519 | if (!rdev->ops->remain_on_channel || |
| 8520 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8521 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8522 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8523 | /* |
| 8524 | * We should be on that channel for at least a minimum amount of |
| 8525 | * time (10ms) but no longer than the driver supports. |
| 8526 | */ |
| 8527 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8528 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8529 | return -EINVAL; |
| 8530 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8531 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8532 | if (err) |
| 8533 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8534 | |
| 8535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8536 | if (!msg) |
| 8537 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8538 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8539 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8540 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8541 | if (!hdr) { |
| 8542 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8543 | goto free_msg; |
| 8544 | } |
| 8545 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8546 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8547 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8548 | |
| 8549 | if (err) |
| 8550 | goto free_msg; |
| 8551 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8552 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8553 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8554 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8555 | |
| 8556 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8557 | |
| 8558 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8559 | |
| 8560 | nla_put_failure: |
| 8561 | err = -ENOBUFS; |
| 8562 | free_msg: |
| 8563 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8564 | return err; |
| 8565 | } |
| 8566 | |
| 8567 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8568 | struct genl_info *info) |
| 8569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8571 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8572 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8573 | |
| 8574 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8575 | return -EINVAL; |
| 8576 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8577 | if (!rdev->ops->cancel_remain_on_channel) |
| 8578 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8579 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8580 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8581 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8582 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8583 | } |
| 8584 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8585 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8586 | u8 *rates, u8 rates_len) |
| 8587 | { |
| 8588 | u8 i; |
| 8589 | u32 mask = 0; |
| 8590 | |
| 8591 | for (i = 0; i < rates_len; i++) { |
| 8592 | int rate = (rates[i] & 0x7f) * 5; |
| 8593 | int ridx; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8594 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8595 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 8596 | struct ieee80211_rate *srate = |
| 8597 | &sband->bitrates[ridx]; |
| 8598 | if (rate == srate->bitrate) { |
| 8599 | mask |= 1 << ridx; |
| 8600 | break; |
| 8601 | } |
| 8602 | } |
| 8603 | if (ridx == sband->n_bitrates) |
| 8604 | return 0; /* rate not found */ |
| 8605 | } |
| 8606 | |
| 8607 | return mask; |
| 8608 | } |
| 8609 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8610 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 8611 | u8 *rates, u8 rates_len, |
| 8612 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 8613 | { |
| 8614 | u8 i; |
| 8615 | |
| 8616 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 8617 | |
| 8618 | for (i = 0; i < rates_len; i++) { |
| 8619 | int ridx, rbit; |
| 8620 | |
| 8621 | ridx = rates[i] / 8; |
| 8622 | rbit = BIT(rates[i] % 8); |
| 8623 | |
| 8624 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 8625 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8626 | return false; |
| 8627 | |
| 8628 | /* check availability */ |
| 8629 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 8630 | mcs[ridx] |= rbit; |
| 8631 | else |
| 8632 | return false; |
| 8633 | } |
| 8634 | |
| 8635 | return true; |
| 8636 | } |
| 8637 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8638 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 8639 | { |
| 8640 | u16 mcs_mask = 0; |
| 8641 | |
| 8642 | switch (vht_mcs_map) { |
| 8643 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 8644 | break; |
| 8645 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 8646 | mcs_mask = 0x00FF; |
| 8647 | break; |
| 8648 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8649 | mcs_mask = 0x01FF; |
| 8650 | break; |
| 8651 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8652 | mcs_mask = 0x03FF; |
| 8653 | break; |
| 8654 | default: |
| 8655 | break; |
| 8656 | } |
| 8657 | |
| 8658 | return mcs_mask; |
| 8659 | } |
| 8660 | |
| 8661 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8662 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8663 | { |
| 8664 | u8 nss; |
| 8665 | |
| 8666 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8667 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8668 | vht_mcs_map >>= 2; |
| 8669 | } |
| 8670 | } |
| 8671 | |
| 8672 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8673 | struct nl80211_txrate_vht *txrate, |
| 8674 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8675 | { |
| 8676 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8677 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8678 | u8 i; |
| 8679 | |
| 8680 | if (!sband->vht_cap.vht_supported) |
| 8681 | return false; |
| 8682 | |
| 8683 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8684 | |
| 8685 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8686 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8687 | |
| 8688 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8689 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8690 | mcs[i] = txrate->mcs[i]; |
| 8691 | else |
| 8692 | return false; |
| 8693 | } |
| 8694 | |
| 8695 | return true; |
| 8696 | } |
| 8697 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8698 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8699 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8700 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8701 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8702 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8703 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8704 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8705 | }; |
| 8706 | |
| 8707 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8708 | struct genl_info *info) |
| 8709 | { |
| 8710 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8712 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8713 | int rem, i; |
| 8714 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8715 | struct nlattr *tx_rates; |
| 8716 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8717 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8719 | if (!rdev->ops->set_bitrate_mask) |
| 8720 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8721 | |
| 8722 | memset(&mask, 0, sizeof(mask)); |
| 8723 | /* Default to all rates enabled */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8724 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8725 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8726 | |
| 8727 | if (!sband) |
| 8728 | continue; |
| 8729 | |
| 8730 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8731 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8732 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8733 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8734 | |
| 8735 | if (!sband->vht_cap.vht_supported) |
| 8736 | continue; |
| 8737 | |
| 8738 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8739 | 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] | 8740 | } |
| 8741 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8742 | /* if no rates are given set it back to the defaults */ |
| 8743 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8744 | goto out; |
| 8745 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8746 | /* |
| 8747 | * The nested attribute uses enum nl80211_band as the index. This maps |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8748 | * directly to the enum nl80211_band values used in cfg80211. |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8749 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8750 | 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] | 8751 | 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] | 8752 | enum nl80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8753 | int err; |
| 8754 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8755 | if (band < 0 || band >= NUM_NL80211_BANDS) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8756 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8757 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8758 | if (sband == NULL) |
| 8759 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8760 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8761 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8762 | if (err) |
| 8763 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8764 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8765 | mask.control[band].legacy = rateset_to_mask( |
| 8766 | sband, |
| 8767 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8768 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8769 | if ((mask.control[band].legacy == 0) && |
| 8770 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8771 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8772 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8773 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8774 | if (!ht_rateset_to_mask( |
| 8775 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8776 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8777 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8778 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8779 | return -EINVAL; |
| 8780 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8781 | if (tb[NL80211_TXRATE_VHT]) { |
| 8782 | if (!vht_set_mcs_mask( |
| 8783 | sband, |
| 8784 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8785 | mask.control[band].vht_mcs)) |
| 8786 | return -EINVAL; |
| 8787 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8788 | if (tb[NL80211_TXRATE_GI]) { |
| 8789 | mask.control[band].gi = |
| 8790 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8791 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8792 | return -EINVAL; |
| 8793 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8794 | |
| 8795 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8796 | /* don't allow empty legacy rates if HT or VHT |
| 8797 | * are not even supported. |
| 8798 | */ |
| 8799 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8800 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8801 | return -EINVAL; |
| 8802 | |
| 8803 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8804 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8805 | goto out; |
| 8806 | |
| 8807 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8808 | if (mask.control[band].vht_mcs[i]) |
| 8809 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8810 | |
| 8811 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8812 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8813 | } |
| 8814 | } |
| 8815 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8816 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8817 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8818 | } |
| 8819 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8820 | 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] | 8821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8823 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8824 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8825 | |
| 8826 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8827 | return -EINVAL; |
| 8828 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8829 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8830 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8831 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8832 | switch (wdev->iftype) { |
| 8833 | case NL80211_IFTYPE_STATION: |
| 8834 | case NL80211_IFTYPE_ADHOC: |
| 8835 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8836 | case NL80211_IFTYPE_AP: |
| 8837 | case NL80211_IFTYPE_AP_VLAN: |
| 8838 | case NL80211_IFTYPE_MESH_POINT: |
| 8839 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8840 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8841 | break; |
| 8842 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8843 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8844 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8845 | |
| 8846 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8847 | if (!rdev->ops->mgmt_tx) |
| 8848 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8849 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8850 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8851 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8852 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8853 | } |
| 8854 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8855 | 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] | 8856 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8858 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8859 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8860 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8861 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8862 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8863 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8864 | struct cfg80211_mgmt_tx_params params = { |
| 8865 | .dont_wait_for_ack = |
| 8866 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8867 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8868 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8869 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8870 | return -EINVAL; |
| 8871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8872 | if (!rdev->ops->mgmt_tx) |
| 8873 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8874 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8875 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8876 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8877 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8878 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8879 | case NL80211_IFTYPE_STATION: |
| 8880 | case NL80211_IFTYPE_ADHOC: |
| 8881 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8882 | case NL80211_IFTYPE_AP: |
| 8883 | case NL80211_IFTYPE_AP_VLAN: |
| 8884 | case NL80211_IFTYPE_MESH_POINT: |
| 8885 | case NL80211_IFTYPE_P2P_GO: |
| 8886 | break; |
| 8887 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8888 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8889 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8890 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8891 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8892 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8893 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8894 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8895 | |
| 8896 | /* |
| 8897 | * We should wait on the channel for at least a minimum amount |
| 8898 | * of time (10ms) but no longer than the driver supports. |
| 8899 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8900 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8901 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8902 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8903 | } |
| 8904 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8905 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8906 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8907 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8908 | return -EINVAL; |
| 8909 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8910 | 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] | 8911 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8912 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8913 | * the driver. The latter will use the current one |
| 8914 | */ |
| 8915 | chandef.chan = NULL; |
| 8916 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8917 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8918 | if (err) |
| 8919 | return err; |
| 8920 | } |
| 8921 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8922 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8923 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8924 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8925 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8926 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8927 | |
| 8928 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8929 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8930 | int i; |
| 8931 | |
| 8932 | if (len % sizeof(u16)) |
| 8933 | return -EINVAL; |
| 8934 | |
| 8935 | params.n_csa_offsets = len / sizeof(u16); |
| 8936 | params.csa_offsets = |
| 8937 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8938 | |
| 8939 | /* check that all the offsets fit the frame */ |
| 8940 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8941 | if (params.csa_offsets[i] >= params.len) |
| 8942 | return -EINVAL; |
| 8943 | } |
| 8944 | } |
| 8945 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8946 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8947 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8948 | if (!msg) |
| 8949 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8950 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8951 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8952 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8953 | if (!hdr) { |
| 8954 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8955 | goto free_msg; |
| 8956 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8957 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8958 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8959 | params.chan = chandef.chan; |
| 8960 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8961 | if (err) |
| 8962 | goto free_msg; |
| 8963 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8964 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8965 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8966 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8967 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8968 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8969 | genlmsg_end(msg, hdr); |
| 8970 | return genlmsg_reply(msg, info); |
| 8971 | } |
| 8972 | |
| 8973 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8974 | |
| 8975 | nla_put_failure: |
| 8976 | err = -ENOBUFS; |
| 8977 | free_msg: |
| 8978 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8979 | return err; |
| 8980 | } |
| 8981 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8982 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8983 | { |
| 8984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8985 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8986 | u64 cookie; |
| 8987 | |
| 8988 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8989 | return -EINVAL; |
| 8990 | |
| 8991 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8992 | return -EOPNOTSUPP; |
| 8993 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8994 | switch (wdev->iftype) { |
| 8995 | case NL80211_IFTYPE_STATION: |
| 8996 | case NL80211_IFTYPE_ADHOC: |
| 8997 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8998 | case NL80211_IFTYPE_AP: |
| 8999 | case NL80211_IFTYPE_AP_VLAN: |
| 9000 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9001 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9002 | break; |
| 9003 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9004 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9005 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9006 | |
| 9007 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9008 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9009 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9010 | } |
| 9011 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9012 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9013 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9015 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9016 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9017 | u8 ps_state; |
| 9018 | bool state; |
| 9019 | int err; |
| 9020 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9021 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9022 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9023 | |
| 9024 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9025 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9026 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9027 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9028 | |
| 9029 | wdev = dev->ieee80211_ptr; |
| 9030 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9031 | if (!rdev->ops->set_power_mgmt) |
| 9032 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9033 | |
| 9034 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9035 | |
| 9036 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9037 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9038 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9039 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9040 | if (!err) |
| 9041 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9042 | return err; |
| 9043 | } |
| 9044 | |
| 9045 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9046 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9048 | enum nl80211_ps_state ps_state; |
| 9049 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9050 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9051 | struct sk_buff *msg; |
| 9052 | void *hdr; |
| 9053 | int err; |
| 9054 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9055 | wdev = dev->ieee80211_ptr; |
| 9056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9057 | if (!rdev->ops->set_power_mgmt) |
| 9058 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9059 | |
| 9060 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9061 | if (!msg) |
| 9062 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9063 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9064 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9065 | NL80211_CMD_GET_POWER_SAVE); |
| 9066 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9067 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9068 | goto free_msg; |
| 9069 | } |
| 9070 | |
| 9071 | if (wdev->ps) |
| 9072 | ps_state = NL80211_PS_ENABLED; |
| 9073 | else |
| 9074 | ps_state = NL80211_PS_DISABLED; |
| 9075 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9076 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9077 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9078 | |
| 9079 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9080 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9082 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9083 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9084 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9085 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9086 | return err; |
| 9087 | } |
| 9088 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9089 | static const struct nla_policy |
| 9090 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9091 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9092 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9093 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9094 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9095 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9096 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9097 | }; |
| 9098 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9099 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9100 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9101 | { |
| 9102 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9103 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9104 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9105 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9106 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9107 | return -EINVAL; |
| 9108 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9109 | if (!rdev->ops->set_cqm_txe_config) |
| 9110 | return -EOPNOTSUPP; |
| 9111 | |
| 9112 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9113 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9114 | return -EOPNOTSUPP; |
| 9115 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9116 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9117 | } |
| 9118 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9119 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9120 | s32 threshold, u32 hysteresis) |
| 9121 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9123 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9124 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9125 | |
| 9126 | if (threshold > 0) |
| 9127 | return -EINVAL; |
| 9128 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9129 | /* disabling - hysteresis should also be zero then */ |
| 9130 | if (threshold == 0) |
| 9131 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9132 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9133 | if (!rdev->ops->set_cqm_rssi_config) |
| 9134 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9135 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9136 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9137 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9138 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9139 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9140 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9141 | } |
| 9142 | |
| 9143 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9144 | { |
| 9145 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9146 | struct nlattr *cqm; |
| 9147 | int err; |
| 9148 | |
| 9149 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9150 | if (!cqm) |
| 9151 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9152 | |
| 9153 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9154 | nl80211_attr_cqm_policy); |
| 9155 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9156 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9157 | |
| 9158 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9159 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9160 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9161 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9162 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9163 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9164 | } |
| 9165 | |
| 9166 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9167 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9168 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9169 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9170 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9171 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9172 | |
| 9173 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9174 | } |
| 9175 | |
| 9176 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9177 | } |
| 9178 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9179 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9180 | { |
| 9181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9182 | struct net_device *dev = info->user_ptr[1]; |
| 9183 | struct ocb_setup setup = {}; |
| 9184 | int err; |
| 9185 | |
| 9186 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9187 | if (err) |
| 9188 | return err; |
| 9189 | |
| 9190 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9191 | } |
| 9192 | |
| 9193 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9194 | { |
| 9195 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9196 | struct net_device *dev = info->user_ptr[1]; |
| 9197 | |
| 9198 | return cfg80211_leave_ocb(rdev, dev); |
| 9199 | } |
| 9200 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9201 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9202 | { |
| 9203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9204 | struct net_device *dev = info->user_ptr[1]; |
| 9205 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9206 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9207 | int err; |
| 9208 | |
| 9209 | /* start with default */ |
| 9210 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9211 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9212 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9213 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9214 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9215 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9216 | if (err) |
| 9217 | return err; |
| 9218 | } |
| 9219 | |
| 9220 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9221 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9222 | return -EINVAL; |
| 9223 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9224 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9225 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9226 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9227 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9228 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9229 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9230 | return -EINVAL; |
| 9231 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9232 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9233 | setup.beacon_interval = |
| 9234 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame^] | 9235 | |
| 9236 | err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval); |
| 9237 | if (err) |
| 9238 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9239 | } |
| 9240 | |
| 9241 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9242 | setup.dtim_period = |
| 9243 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9244 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9245 | return -EINVAL; |
| 9246 | } |
| 9247 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9248 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9249 | /* parse additional setup parameters if given */ |
| 9250 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9251 | if (err) |
| 9252 | return err; |
| 9253 | } |
| 9254 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9255 | if (setup.user_mpm) |
| 9256 | cfg.auto_open_plinks = false; |
| 9257 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9258 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9259 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9260 | if (err) |
| 9261 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9262 | } else { |
| 9263 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9264 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9265 | } |
| 9266 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9267 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9268 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9269 | int n_rates = |
| 9270 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9271 | struct ieee80211_supported_band *sband; |
| 9272 | |
| 9273 | if (!setup.chandef.chan) |
| 9274 | return -EINVAL; |
| 9275 | |
| 9276 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9277 | |
| 9278 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9279 | &setup.basic_rates); |
| 9280 | if (err) |
| 9281 | return err; |
| 9282 | } |
| 9283 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9284 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9285 | } |
| 9286 | |
| 9287 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9288 | { |
| 9289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9290 | struct net_device *dev = info->user_ptr[1]; |
| 9291 | |
| 9292 | return cfg80211_leave_mesh(rdev, dev); |
| 9293 | } |
| 9294 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9295 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9296 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9297 | struct cfg80211_registered_device *rdev) |
| 9298 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9299 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9300 | struct nlattr *nl_pats, *nl_pat; |
| 9301 | int i, pat_len; |
| 9302 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9303 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9304 | return 0; |
| 9305 | |
| 9306 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9307 | if (!nl_pats) |
| 9308 | return -ENOBUFS; |
| 9309 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9310 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9311 | nl_pat = nla_nest_start(msg, i + 1); |
| 9312 | if (!nl_pat) |
| 9313 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9314 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9315 | 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] | 9316 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9317 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9318 | wowlan->patterns[i].pattern) || |
| 9319 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9320 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9321 | return -ENOBUFS; |
| 9322 | nla_nest_end(msg, nl_pat); |
| 9323 | } |
| 9324 | nla_nest_end(msg, nl_pats); |
| 9325 | |
| 9326 | return 0; |
| 9327 | } |
| 9328 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9329 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9330 | struct cfg80211_wowlan_tcp *tcp) |
| 9331 | { |
| 9332 | struct nlattr *nl_tcp; |
| 9333 | |
| 9334 | if (!tcp) |
| 9335 | return 0; |
| 9336 | |
| 9337 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9338 | if (!nl_tcp) |
| 9339 | return -ENOBUFS; |
| 9340 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9341 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9342 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9343 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9344 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9345 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9346 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9347 | tcp->payload_len, tcp->payload) || |
| 9348 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9349 | tcp->data_interval) || |
| 9350 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9351 | tcp->wake_len, tcp->wake_data) || |
| 9352 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9353 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9354 | return -ENOBUFS; |
| 9355 | |
| 9356 | if (tcp->payload_seq.len && |
| 9357 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9358 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9359 | return -ENOBUFS; |
| 9360 | |
| 9361 | if (tcp->payload_tok.len && |
| 9362 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9363 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9364 | &tcp->payload_tok)) |
| 9365 | return -ENOBUFS; |
| 9366 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9367 | nla_nest_end(msg, nl_tcp); |
| 9368 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9369 | return 0; |
| 9370 | } |
| 9371 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9372 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9373 | struct cfg80211_sched_scan_request *req) |
| 9374 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9375 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9376 | int i; |
| 9377 | |
| 9378 | if (!req) |
| 9379 | return 0; |
| 9380 | |
| 9381 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9382 | if (!nd) |
| 9383 | return -ENOBUFS; |
| 9384 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9385 | if (req->n_scan_plans == 1 && |
| 9386 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9387 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9388 | return -ENOBUFS; |
| 9389 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9390 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9391 | return -ENOBUFS; |
| 9392 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9393 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9394 | if (!freqs) |
| 9395 | return -ENOBUFS; |
| 9396 | |
| 9397 | for (i = 0; i < req->n_channels; i++) |
| 9398 | nla_put_u32(msg, i, req->channels[i]->center_freq); |
| 9399 | |
| 9400 | nla_nest_end(msg, freqs); |
| 9401 | |
| 9402 | if (req->n_match_sets) { |
| 9403 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
| 9404 | for (i = 0; i < req->n_match_sets; i++) { |
| 9405 | match = nla_nest_start(msg, i); |
| 9406 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9407 | req->match_sets[i].ssid.ssid_len, |
| 9408 | req->match_sets[i].ssid.ssid); |
| 9409 | nla_nest_end(msg, match); |
| 9410 | } |
| 9411 | nla_nest_end(msg, matches); |
| 9412 | } |
| 9413 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9414 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9415 | if (!scan_plans) |
| 9416 | return -ENOBUFS; |
| 9417 | |
| 9418 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9419 | scan_plan = nla_nest_start(msg, i + 1); |
| 9420 | if (!scan_plan || |
| 9421 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9422 | req->scan_plans[i].interval) || |
| 9423 | (req->scan_plans[i].iterations && |
| 9424 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9425 | req->scan_plans[i].iterations))) |
| 9426 | return -ENOBUFS; |
| 9427 | nla_nest_end(msg, scan_plan); |
| 9428 | } |
| 9429 | nla_nest_end(msg, scan_plans); |
| 9430 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9431 | nla_nest_end(msg, nd); |
| 9432 | |
| 9433 | return 0; |
| 9434 | } |
| 9435 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9436 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9437 | { |
| 9438 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9439 | struct sk_buff *msg; |
| 9440 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9441 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9442 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9443 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9444 | return -EOPNOTSUPP; |
| 9445 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9446 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9447 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9448 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9449 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9450 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9451 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9452 | } |
| 9453 | |
| 9454 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9455 | if (!msg) |
| 9456 | return -ENOMEM; |
| 9457 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9458 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9459 | NL80211_CMD_GET_WOWLAN); |
| 9460 | if (!hdr) |
| 9461 | goto nla_put_failure; |
| 9462 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9463 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9464 | struct nlattr *nl_wowlan; |
| 9465 | |
| 9466 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9467 | if (!nl_wowlan) |
| 9468 | goto nla_put_failure; |
| 9469 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9470 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9471 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9472 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9473 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9474 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9475 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9476 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9477 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9478 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9479 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9480 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9481 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9482 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9483 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9484 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9485 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9486 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9487 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9488 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9489 | if (nl80211_send_wowlan_tcp(msg, |
| 9490 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9491 | goto nla_put_failure; |
| 9492 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9493 | if (nl80211_send_wowlan_nd( |
| 9494 | msg, |
| 9495 | rdev->wiphy.wowlan_config->nd_config)) |
| 9496 | goto nla_put_failure; |
| 9497 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9498 | nla_nest_end(msg, nl_wowlan); |
| 9499 | } |
| 9500 | |
| 9501 | genlmsg_end(msg, hdr); |
| 9502 | return genlmsg_reply(msg, info); |
| 9503 | |
| 9504 | nla_put_failure: |
| 9505 | nlmsg_free(msg); |
| 9506 | return -ENOBUFS; |
| 9507 | } |
| 9508 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9509 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9510 | struct nlattr *attr, |
| 9511 | struct cfg80211_wowlan *trig) |
| 9512 | { |
| 9513 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9514 | struct cfg80211_wowlan_tcp *cfg; |
| 9515 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9516 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9517 | u32 size; |
| 9518 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9519 | int err, port; |
| 9520 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9521 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9522 | return -EINVAL; |
| 9523 | |
| 9524 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9525 | nla_data(attr), nla_len(attr), |
| 9526 | nl80211_wowlan_tcp_policy); |
| 9527 | if (err) |
| 9528 | return err; |
| 9529 | |
| 9530 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9531 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9532 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9533 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9534 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9535 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9536 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9537 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9538 | return -EINVAL; |
| 9539 | |
| 9540 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9541 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9542 | return -EINVAL; |
| 9543 | |
| 9544 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9545 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9546 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9547 | return -EINVAL; |
| 9548 | |
| 9549 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9550 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9551 | return -EINVAL; |
| 9552 | |
| 9553 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9554 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9555 | return -EINVAL; |
| 9556 | |
| 9557 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9558 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9559 | |
| 9560 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9561 | tokens_size = tokln - sizeof(*tok); |
| 9562 | |
| 9563 | if (!tok->len || tokens_size % tok->len) |
| 9564 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9565 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9566 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9567 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9568 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9569 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9570 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9571 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9572 | return -EINVAL; |
| 9573 | if (tok->offset + tok->len > data_size) |
| 9574 | return -EINVAL; |
| 9575 | } |
| 9576 | |
| 9577 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9578 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9579 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9580 | return -EINVAL; |
| 9581 | if (seq->len == 0 || seq->len > 4) |
| 9582 | return -EINVAL; |
| 9583 | if (seq->len + seq->offset > data_size) |
| 9584 | return -EINVAL; |
| 9585 | } |
| 9586 | |
| 9587 | size = sizeof(*cfg); |
| 9588 | size += data_size; |
| 9589 | size += wake_size + wake_mask_size; |
| 9590 | size += tokens_size; |
| 9591 | |
| 9592 | cfg = kzalloc(size, GFP_KERNEL); |
| 9593 | if (!cfg) |
| 9594 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9595 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9596 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9597 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9598 | ETH_ALEN); |
| 9599 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9600 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9601 | else |
| 9602 | port = 0; |
| 9603 | #ifdef CONFIG_INET |
| 9604 | /* allocate a socket and port for it and use it */ |
| 9605 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9606 | IPPROTO_TCP, &cfg->sock, 1); |
| 9607 | if (err) { |
| 9608 | kfree(cfg); |
| 9609 | return err; |
| 9610 | } |
| 9611 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9612 | sock_release(cfg->sock); |
| 9613 | kfree(cfg); |
| 9614 | return -EADDRINUSE; |
| 9615 | } |
| 9616 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9617 | #else |
| 9618 | if (!port) { |
| 9619 | kfree(cfg); |
| 9620 | return -EINVAL; |
| 9621 | } |
| 9622 | cfg->src_port = port; |
| 9623 | #endif |
| 9624 | |
| 9625 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9626 | cfg->payload_len = data_size; |
| 9627 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9628 | memcpy((void *)cfg->payload, |
| 9629 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9630 | data_size); |
| 9631 | if (seq) |
| 9632 | cfg->payload_seq = *seq; |
| 9633 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9634 | cfg->wake_len = wake_size; |
| 9635 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9636 | memcpy((void *)cfg->wake_data, |
| 9637 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9638 | wake_size); |
| 9639 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9640 | data_size + wake_size; |
| 9641 | memcpy((void *)cfg->wake_mask, |
| 9642 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9643 | wake_mask_size); |
| 9644 | if (tok) { |
| 9645 | cfg->tokens_size = tokens_size; |
| 9646 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9647 | } |
| 9648 | |
| 9649 | trig->tcp = cfg; |
| 9650 | |
| 9651 | return 0; |
| 9652 | } |
| 9653 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9654 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9655 | const struct wiphy_wowlan_support *wowlan, |
| 9656 | struct nlattr *attr, |
| 9657 | struct cfg80211_wowlan *trig) |
| 9658 | { |
| 9659 | struct nlattr **tb; |
| 9660 | int err; |
| 9661 | |
| 9662 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9663 | if (!tb) |
| 9664 | return -ENOMEM; |
| 9665 | |
| 9666 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9667 | err = -EOPNOTSUPP; |
| 9668 | goto out; |
| 9669 | } |
| 9670 | |
| 9671 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9672 | nla_data(attr), nla_len(attr), |
| 9673 | nl80211_policy); |
| 9674 | if (err) |
| 9675 | goto out; |
| 9676 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9677 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9678 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9679 | if (err) |
| 9680 | trig->nd_config = NULL; |
| 9681 | |
| 9682 | out: |
| 9683 | kfree(tb); |
| 9684 | return err; |
| 9685 | } |
| 9686 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9687 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9688 | { |
| 9689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9690 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9691 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9692 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9693 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9694 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9695 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9696 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9697 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9698 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9699 | return -EOPNOTSUPP; |
| 9700 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9701 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9702 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9703 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9704 | goto set_wakeup; |
| 9705 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9706 | |
| 9707 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9708 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9709 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9710 | nl80211_wowlan_policy); |
| 9711 | if (err) |
| 9712 | return err; |
| 9713 | |
| 9714 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9715 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9716 | return -EINVAL; |
| 9717 | new_triggers.any = true; |
| 9718 | } |
| 9719 | |
| 9720 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9721 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9722 | return -EINVAL; |
| 9723 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9724 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9725 | } |
| 9726 | |
| 9727 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9728 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9729 | return -EINVAL; |
| 9730 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9731 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9732 | } |
| 9733 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9734 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9735 | return -EINVAL; |
| 9736 | |
| 9737 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9738 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9739 | return -EINVAL; |
| 9740 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9741 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9742 | } |
| 9743 | |
| 9744 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9745 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9746 | return -EINVAL; |
| 9747 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9748 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9749 | } |
| 9750 | |
| 9751 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9752 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9753 | return -EINVAL; |
| 9754 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9755 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9756 | } |
| 9757 | |
| 9758 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9759 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9760 | return -EINVAL; |
| 9761 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9762 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9763 | } |
| 9764 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9765 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9766 | struct nlattr *pat; |
| 9767 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9768 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9769 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9770 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9771 | regular = true; |
| 9772 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9773 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9774 | rem) |
| 9775 | n_patterns++; |
| 9776 | if (n_patterns > wowlan->n_patterns) |
| 9777 | return -EINVAL; |
| 9778 | |
| 9779 | new_triggers.patterns = kcalloc(n_patterns, |
| 9780 | sizeof(new_triggers.patterns[0]), |
| 9781 | GFP_KERNEL); |
| 9782 | if (!new_triggers.patterns) |
| 9783 | return -ENOMEM; |
| 9784 | |
| 9785 | new_triggers.n_patterns = n_patterns; |
| 9786 | i = 0; |
| 9787 | |
| 9788 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9789 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9790 | u8 *mask_pat; |
| 9791 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9792 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9793 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9794 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9795 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9796 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9797 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9798 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9799 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9800 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9801 | goto error; |
| 9802 | if (pat_len > wowlan->pattern_max_len || |
| 9803 | pat_len < wowlan->pattern_min_len) |
| 9804 | goto error; |
| 9805 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9806 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9807 | pkt_offset = 0; |
| 9808 | else |
| 9809 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9810 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9811 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9812 | goto error; |
| 9813 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9814 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9815 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9816 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9817 | err = -ENOMEM; |
| 9818 | goto error; |
| 9819 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9820 | new_triggers.patterns[i].mask = mask_pat; |
| 9821 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9822 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9823 | mask_pat += mask_len; |
| 9824 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9825 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9826 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9827 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9828 | pat_len); |
| 9829 | i++; |
| 9830 | } |
| 9831 | } |
| 9832 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9833 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9834 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9835 | err = nl80211_parse_wowlan_tcp( |
| 9836 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9837 | &new_triggers); |
| 9838 | if (err) |
| 9839 | goto error; |
| 9840 | } |
| 9841 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9842 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9843 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9844 | err = nl80211_parse_wowlan_nd( |
| 9845 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9846 | &new_triggers); |
| 9847 | if (err) |
| 9848 | goto error; |
| 9849 | } |
| 9850 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9851 | /* The 'any' trigger means the device continues operating more or less |
| 9852 | * as in its normal operation mode and wakes up the host on most of the |
| 9853 | * normal interrupts (like packet RX, ...) |
| 9854 | * It therefore makes little sense to combine with the more constrained |
| 9855 | * wakeup trigger modes. |
| 9856 | */ |
| 9857 | if (new_triggers.any && regular) { |
| 9858 | err = -EINVAL; |
| 9859 | goto error; |
| 9860 | } |
| 9861 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9862 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9863 | if (!ntrig) { |
| 9864 | err = -ENOMEM; |
| 9865 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9866 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9867 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9868 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9869 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9870 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9871 | if (rdev->ops->set_wakeup && |
| 9872 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9873 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9874 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9875 | return 0; |
| 9876 | error: |
| 9877 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9878 | kfree(new_triggers.patterns[i].mask); |
| 9879 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9880 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9881 | sock_release(new_triggers.tcp->sock); |
| 9882 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 9883 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9884 | return err; |
| 9885 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9886 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9887 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9888 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9889 | struct cfg80211_registered_device *rdev) |
| 9890 | { |
| 9891 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9892 | int i, j, pat_len; |
| 9893 | struct cfg80211_coalesce_rules *rule; |
| 9894 | |
| 9895 | if (!rdev->coalesce->n_rules) |
| 9896 | return 0; |
| 9897 | |
| 9898 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9899 | if (!nl_rules) |
| 9900 | return -ENOBUFS; |
| 9901 | |
| 9902 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9903 | nl_rule = nla_nest_start(msg, i + 1); |
| 9904 | if (!nl_rule) |
| 9905 | return -ENOBUFS; |
| 9906 | |
| 9907 | rule = &rdev->coalesce->rules[i]; |
| 9908 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9909 | rule->delay)) |
| 9910 | return -ENOBUFS; |
| 9911 | |
| 9912 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9913 | rule->condition)) |
| 9914 | return -ENOBUFS; |
| 9915 | |
| 9916 | nl_pats = nla_nest_start(msg, |
| 9917 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9918 | if (!nl_pats) |
| 9919 | return -ENOBUFS; |
| 9920 | |
| 9921 | for (j = 0; j < rule->n_patterns; j++) { |
| 9922 | nl_pat = nla_nest_start(msg, j + 1); |
| 9923 | if (!nl_pat) |
| 9924 | return -ENOBUFS; |
| 9925 | pat_len = rule->patterns[j].pattern_len; |
| 9926 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9927 | DIV_ROUND_UP(pat_len, 8), |
| 9928 | rule->patterns[j].mask) || |
| 9929 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9930 | rule->patterns[j].pattern) || |
| 9931 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9932 | rule->patterns[j].pkt_offset)) |
| 9933 | return -ENOBUFS; |
| 9934 | nla_nest_end(msg, nl_pat); |
| 9935 | } |
| 9936 | nla_nest_end(msg, nl_pats); |
| 9937 | nla_nest_end(msg, nl_rule); |
| 9938 | } |
| 9939 | nla_nest_end(msg, nl_rules); |
| 9940 | |
| 9941 | return 0; |
| 9942 | } |
| 9943 | |
| 9944 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9945 | { |
| 9946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9947 | struct sk_buff *msg; |
| 9948 | void *hdr; |
| 9949 | |
| 9950 | if (!rdev->wiphy.coalesce) |
| 9951 | return -EOPNOTSUPP; |
| 9952 | |
| 9953 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9954 | if (!msg) |
| 9955 | return -ENOMEM; |
| 9956 | |
| 9957 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9958 | NL80211_CMD_GET_COALESCE); |
| 9959 | if (!hdr) |
| 9960 | goto nla_put_failure; |
| 9961 | |
| 9962 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9963 | goto nla_put_failure; |
| 9964 | |
| 9965 | genlmsg_end(msg, hdr); |
| 9966 | return genlmsg_reply(msg, info); |
| 9967 | |
| 9968 | nla_put_failure: |
| 9969 | nlmsg_free(msg); |
| 9970 | return -ENOBUFS; |
| 9971 | } |
| 9972 | |
| 9973 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9974 | { |
| 9975 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9976 | int i, j; |
| 9977 | struct cfg80211_coalesce_rules *rule; |
| 9978 | |
| 9979 | if (!coalesce) |
| 9980 | return; |
| 9981 | |
| 9982 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9983 | rule = &coalesce->rules[i]; |
| 9984 | for (j = 0; j < rule->n_patterns; j++) |
| 9985 | kfree(rule->patterns[j].mask); |
| 9986 | kfree(rule->patterns); |
| 9987 | } |
| 9988 | kfree(coalesce->rules); |
| 9989 | kfree(coalesce); |
| 9990 | rdev->coalesce = NULL; |
| 9991 | } |
| 9992 | |
| 9993 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9994 | struct nlattr *rule, |
| 9995 | struct cfg80211_coalesce_rules *new_rule) |
| 9996 | { |
| 9997 | int err, i; |
| 9998 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9999 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10000 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10001 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10002 | |
| 10003 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 10004 | nla_len(rule), nl80211_coalesce_policy); |
| 10005 | if (err) |
| 10006 | return err; |
| 10007 | |
| 10008 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10009 | new_rule->delay = |
| 10010 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10011 | if (new_rule->delay > coalesce->max_delay) |
| 10012 | return -EINVAL; |
| 10013 | |
| 10014 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10015 | new_rule->condition = |
| 10016 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10017 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10018 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10019 | return -EINVAL; |
| 10020 | |
| 10021 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10022 | return -EINVAL; |
| 10023 | |
| 10024 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10025 | rem) |
| 10026 | n_patterns++; |
| 10027 | if (n_patterns > coalesce->n_patterns) |
| 10028 | return -EINVAL; |
| 10029 | |
| 10030 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10031 | GFP_KERNEL); |
| 10032 | if (!new_rule->patterns) |
| 10033 | return -ENOMEM; |
| 10034 | |
| 10035 | new_rule->n_patterns = n_patterns; |
| 10036 | i = 0; |
| 10037 | |
| 10038 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10039 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10040 | u8 *mask_pat; |
| 10041 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10042 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 10043 | nla_len(pat), NULL); |
| 10044 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10045 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10046 | return -EINVAL; |
| 10047 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10048 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10049 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10050 | return -EINVAL; |
| 10051 | if (pat_len > coalesce->pattern_max_len || |
| 10052 | pat_len < coalesce->pattern_min_len) |
| 10053 | return -EINVAL; |
| 10054 | |
| 10055 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10056 | pkt_offset = 0; |
| 10057 | else |
| 10058 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10059 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10060 | return -EINVAL; |
| 10061 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10062 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10063 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10064 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10065 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10066 | |
| 10067 | new_rule->patterns[i].mask = mask_pat; |
| 10068 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10069 | mask_len); |
| 10070 | |
| 10071 | mask_pat += mask_len; |
| 10072 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10073 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10074 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10075 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10076 | i++; |
| 10077 | } |
| 10078 | |
| 10079 | return 0; |
| 10080 | } |
| 10081 | |
| 10082 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10083 | { |
| 10084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10085 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10086 | struct cfg80211_coalesce new_coalesce = {}; |
| 10087 | struct cfg80211_coalesce *n_coalesce; |
| 10088 | int err, rem_rule, n_rules = 0, i, j; |
| 10089 | struct nlattr *rule; |
| 10090 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10091 | |
| 10092 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10093 | return -EOPNOTSUPP; |
| 10094 | |
| 10095 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10096 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10097 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10098 | return 0; |
| 10099 | } |
| 10100 | |
| 10101 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10102 | rem_rule) |
| 10103 | n_rules++; |
| 10104 | if (n_rules > coalesce->n_rules) |
| 10105 | return -EINVAL; |
| 10106 | |
| 10107 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10108 | GFP_KERNEL); |
| 10109 | if (!new_coalesce.rules) |
| 10110 | return -ENOMEM; |
| 10111 | |
| 10112 | new_coalesce.n_rules = n_rules; |
| 10113 | i = 0; |
| 10114 | |
| 10115 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10116 | rem_rule) { |
| 10117 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10118 | &new_coalesce.rules[i]); |
| 10119 | if (err) |
| 10120 | goto error; |
| 10121 | |
| 10122 | i++; |
| 10123 | } |
| 10124 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10125 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10126 | if (err) |
| 10127 | goto error; |
| 10128 | |
| 10129 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10130 | if (!n_coalesce) { |
| 10131 | err = -ENOMEM; |
| 10132 | goto error; |
| 10133 | } |
| 10134 | cfg80211_rdev_free_coalesce(rdev); |
| 10135 | rdev->coalesce = n_coalesce; |
| 10136 | |
| 10137 | return 0; |
| 10138 | error: |
| 10139 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10140 | tmp_rule = &new_coalesce.rules[i]; |
| 10141 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10142 | kfree(tmp_rule->patterns[j].mask); |
| 10143 | kfree(tmp_rule->patterns); |
| 10144 | } |
| 10145 | kfree(new_coalesce.rules); |
| 10146 | |
| 10147 | return err; |
| 10148 | } |
| 10149 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10150 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10151 | { |
| 10152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10153 | struct net_device *dev = info->user_ptr[1]; |
| 10154 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10155 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10156 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10157 | int err; |
| 10158 | |
| 10159 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10160 | return -EINVAL; |
| 10161 | |
| 10162 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 10163 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10164 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10165 | nl80211_rekey_policy); |
| 10166 | if (err) |
| 10167 | return err; |
| 10168 | |
| 10169 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10170 | return -ERANGE; |
| 10171 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10172 | return -ERANGE; |
| 10173 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10174 | return -ERANGE; |
| 10175 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10176 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10177 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10178 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10179 | |
| 10180 | wdev_lock(wdev); |
| 10181 | if (!wdev->current_bss) { |
| 10182 | err = -ENOTCONN; |
| 10183 | goto out; |
| 10184 | } |
| 10185 | |
| 10186 | if (!rdev->ops->set_rekey_data) { |
| 10187 | err = -EOPNOTSUPP; |
| 10188 | goto out; |
| 10189 | } |
| 10190 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10191 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10192 | out: |
| 10193 | wdev_unlock(wdev); |
| 10194 | return err; |
| 10195 | } |
| 10196 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10197 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10198 | struct genl_info *info) |
| 10199 | { |
| 10200 | struct net_device *dev = info->user_ptr[1]; |
| 10201 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10202 | |
| 10203 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10204 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10205 | return -EINVAL; |
| 10206 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10207 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10208 | return -EBUSY; |
| 10209 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10210 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10211 | return 0; |
| 10212 | } |
| 10213 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10214 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10215 | struct genl_info *info) |
| 10216 | { |
| 10217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10218 | struct net_device *dev = info->user_ptr[1]; |
| 10219 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10220 | struct sk_buff *msg; |
| 10221 | void *hdr; |
| 10222 | const u8 *addr; |
| 10223 | u64 cookie; |
| 10224 | int err; |
| 10225 | |
| 10226 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10227 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10228 | return -EOPNOTSUPP; |
| 10229 | |
| 10230 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10231 | return -EINVAL; |
| 10232 | |
| 10233 | if (!rdev->ops->probe_client) |
| 10234 | return -EOPNOTSUPP; |
| 10235 | |
| 10236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10237 | if (!msg) |
| 10238 | return -ENOMEM; |
| 10239 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10240 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10241 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10242 | if (!hdr) { |
| 10243 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10244 | goto free_msg; |
| 10245 | } |
| 10246 | |
| 10247 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10248 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10249 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10250 | if (err) |
| 10251 | goto free_msg; |
| 10252 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10253 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10254 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10255 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10256 | |
| 10257 | genlmsg_end(msg, hdr); |
| 10258 | |
| 10259 | return genlmsg_reply(msg, info); |
| 10260 | |
| 10261 | nla_put_failure: |
| 10262 | err = -ENOBUFS; |
| 10263 | free_msg: |
| 10264 | nlmsg_free(msg); |
| 10265 | return err; |
| 10266 | } |
| 10267 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10268 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10269 | { |
| 10270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10271 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10272 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10273 | |
| 10274 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10275 | return -EOPNOTSUPP; |
| 10276 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10277 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10278 | if (!nreg) |
| 10279 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10280 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10281 | /* First, check if already registered. */ |
| 10282 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10283 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10284 | if (reg->nlportid == info->snd_portid) { |
| 10285 | rv = -EALREADY; |
| 10286 | goto out_err; |
| 10287 | } |
| 10288 | } |
| 10289 | /* Add it to the list */ |
| 10290 | nreg->nlportid = info->snd_portid; |
| 10291 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10292 | |
| 10293 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10294 | |
| 10295 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10296 | out_err: |
| 10297 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10298 | kfree(nreg); |
| 10299 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10300 | } |
| 10301 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10302 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10303 | { |
| 10304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10305 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10306 | int err; |
| 10307 | |
| 10308 | if (!rdev->ops->start_p2p_device) |
| 10309 | return -EOPNOTSUPP; |
| 10310 | |
| 10311 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10312 | return -EOPNOTSUPP; |
| 10313 | |
| 10314 | if (wdev->p2p_started) |
| 10315 | return 0; |
| 10316 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10317 | if (rfkill_blocked(rdev->rfkill)) |
| 10318 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10319 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10320 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10321 | if (err) |
| 10322 | return err; |
| 10323 | |
| 10324 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10325 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10326 | |
| 10327 | return 0; |
| 10328 | } |
| 10329 | |
| 10330 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10331 | { |
| 10332 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10333 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10334 | |
| 10335 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10336 | return -EOPNOTSUPP; |
| 10337 | |
| 10338 | if (!rdev->ops->stop_p2p_device) |
| 10339 | return -EOPNOTSUPP; |
| 10340 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10341 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10342 | |
| 10343 | return 0; |
| 10344 | } |
| 10345 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10346 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 10347 | struct genl_info *info) |
| 10348 | { |
| 10349 | void *hdr; |
| 10350 | struct sk_buff *msg; |
| 10351 | |
| 10352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10353 | if (!msg) |
| 10354 | return -ENOMEM; |
| 10355 | |
| 10356 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10357 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 10358 | if (!hdr) |
| 10359 | goto nla_put_failure; |
| 10360 | |
| 10361 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 10362 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 10363 | goto nla_put_failure; |
| 10364 | |
| 10365 | genlmsg_end(msg, hdr); |
| 10366 | return genlmsg_reply(msg, info); |
| 10367 | |
| 10368 | nla_put_failure: |
| 10369 | kfree_skb(msg); |
| 10370 | return -ENOBUFS; |
| 10371 | } |
| 10372 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10373 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 10374 | { |
| 10375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10376 | struct cfg80211_update_ft_ies_params ft_params; |
| 10377 | struct net_device *dev = info->user_ptr[1]; |
| 10378 | |
| 10379 | if (!rdev->ops->update_ft_ies) |
| 10380 | return -EOPNOTSUPP; |
| 10381 | |
| 10382 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 10383 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 10384 | return -EINVAL; |
| 10385 | |
| 10386 | memset(&ft_params, 0, sizeof(ft_params)); |
| 10387 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 10388 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10389 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10390 | |
| 10391 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 10392 | } |
| 10393 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10394 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 10395 | struct genl_info *info) |
| 10396 | { |
| 10397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10398 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10399 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 10400 | u16 duration; |
| 10401 | int ret; |
| 10402 | |
| 10403 | if (!rdev->ops->crit_proto_start) |
| 10404 | return -EOPNOTSUPP; |
| 10405 | |
| 10406 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 10407 | return -EINVAL; |
| 10408 | |
| 10409 | if (rdev->crit_proto_nlportid) |
| 10410 | return -EBUSY; |
| 10411 | |
| 10412 | /* determine protocol if provided */ |
| 10413 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 10414 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 10415 | |
| 10416 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 10417 | return -EINVAL; |
| 10418 | |
| 10419 | /* timeout must be provided */ |
| 10420 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 10421 | return -EINVAL; |
| 10422 | |
| 10423 | duration = |
| 10424 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 10425 | |
| 10426 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 10427 | return -ERANGE; |
| 10428 | |
| 10429 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 10430 | if (!ret) |
| 10431 | rdev->crit_proto_nlportid = info->snd_portid; |
| 10432 | |
| 10433 | return ret; |
| 10434 | } |
| 10435 | |
| 10436 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 10437 | struct genl_info *info) |
| 10438 | { |
| 10439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10440 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10441 | |
| 10442 | if (!rdev->ops->crit_proto_stop) |
| 10443 | return -EOPNOTSUPP; |
| 10444 | |
| 10445 | if (rdev->crit_proto_nlportid) { |
| 10446 | rdev->crit_proto_nlportid = 0; |
| 10447 | rdev_crit_proto_stop(rdev, wdev); |
| 10448 | } |
| 10449 | return 0; |
| 10450 | } |
| 10451 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10452 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 10453 | { |
| 10454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10455 | struct wireless_dev *wdev = |
| 10456 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10457 | int i, err; |
| 10458 | u32 vid, subcmd; |
| 10459 | |
| 10460 | if (!rdev->wiphy.vendor_commands) |
| 10461 | return -EOPNOTSUPP; |
| 10462 | |
| 10463 | if (IS_ERR(wdev)) { |
| 10464 | err = PTR_ERR(wdev); |
| 10465 | if (err != -EINVAL) |
| 10466 | return err; |
| 10467 | wdev = NULL; |
| 10468 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10469 | return -EINVAL; |
| 10470 | } |
| 10471 | |
| 10472 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 10473 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 10474 | return -EINVAL; |
| 10475 | |
| 10476 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 10477 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10478 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 10479 | const struct wiphy_vendor_command *vcmd; |
| 10480 | void *data = NULL; |
| 10481 | int len = 0; |
| 10482 | |
| 10483 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 10484 | |
| 10485 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10486 | continue; |
| 10487 | |
| 10488 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10489 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10490 | if (!wdev) |
| 10491 | return -EINVAL; |
| 10492 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10493 | !wdev->netdev) |
| 10494 | return -EINVAL; |
| 10495 | |
| 10496 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10497 | if (wdev->netdev && |
| 10498 | !netif_running(wdev->netdev)) |
| 10499 | return -ENETDOWN; |
| 10500 | if (!wdev->netdev && !wdev->p2p_started) |
| 10501 | return -ENETDOWN; |
| 10502 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10503 | |
| 10504 | if (!vcmd->doit) |
| 10505 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10506 | } else { |
| 10507 | wdev = NULL; |
| 10508 | } |
| 10509 | |
| 10510 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 10511 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10512 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 10513 | } |
| 10514 | |
| 10515 | rdev->cur_cmd_info = info; |
| 10516 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 10517 | data, len); |
| 10518 | rdev->cur_cmd_info = NULL; |
| 10519 | return err; |
| 10520 | } |
| 10521 | |
| 10522 | return -EOPNOTSUPP; |
| 10523 | } |
| 10524 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10525 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 10526 | struct netlink_callback *cb, |
| 10527 | struct cfg80211_registered_device **rdev, |
| 10528 | struct wireless_dev **wdev) |
| 10529 | { |
| 10530 | u32 vid, subcmd; |
| 10531 | unsigned int i; |
| 10532 | int vcmd_idx = -1; |
| 10533 | int err; |
| 10534 | void *data = NULL; |
| 10535 | unsigned int data_len = 0; |
| 10536 | |
| 10537 | rtnl_lock(); |
| 10538 | |
| 10539 | if (cb->args[0]) { |
| 10540 | /* subtract the 1 again here */ |
| 10541 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 10542 | struct wireless_dev *tmp; |
| 10543 | |
| 10544 | if (!wiphy) { |
| 10545 | err = -ENODEV; |
| 10546 | goto out_unlock; |
| 10547 | } |
| 10548 | *rdev = wiphy_to_rdev(wiphy); |
| 10549 | *wdev = NULL; |
| 10550 | |
| 10551 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 10552 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10553 | if (tmp->identifier == cb->args[1] - 1) { |
| 10554 | *wdev = tmp; |
| 10555 | break; |
| 10556 | } |
| 10557 | } |
| 10558 | } |
| 10559 | |
| 10560 | /* keep rtnl locked in successful case */ |
| 10561 | return 0; |
| 10562 | } |
| 10563 | |
| 10564 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10565 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 10566 | nl80211_policy); |
| 10567 | if (err) |
| 10568 | goto out_unlock; |
| 10569 | |
| 10570 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 10571 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 10572 | err = -EINVAL; |
| 10573 | goto out_unlock; |
| 10574 | } |
| 10575 | |
| 10576 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 10577 | nl80211_fam.attrbuf); |
| 10578 | if (IS_ERR(*wdev)) |
| 10579 | *wdev = NULL; |
| 10580 | |
| 10581 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 10582 | nl80211_fam.attrbuf); |
| 10583 | if (IS_ERR(*rdev)) { |
| 10584 | err = PTR_ERR(*rdev); |
| 10585 | goto out_unlock; |
| 10586 | } |
| 10587 | |
| 10588 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 10589 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 10590 | |
| 10591 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 10592 | const struct wiphy_vendor_command *vcmd; |
| 10593 | |
| 10594 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 10595 | |
| 10596 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 10597 | continue; |
| 10598 | |
| 10599 | if (!vcmd->dumpit) { |
| 10600 | err = -EOPNOTSUPP; |
| 10601 | goto out_unlock; |
| 10602 | } |
| 10603 | |
| 10604 | vcmd_idx = i; |
| 10605 | break; |
| 10606 | } |
| 10607 | |
| 10608 | if (vcmd_idx < 0) { |
| 10609 | err = -EOPNOTSUPP; |
| 10610 | goto out_unlock; |
| 10611 | } |
| 10612 | |
| 10613 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 10614 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10615 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 10616 | } |
| 10617 | |
| 10618 | /* 0 is the first index - add 1 to parse only once */ |
| 10619 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 10620 | /* add 1 to know if it was NULL */ |
| 10621 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 10622 | cb->args[2] = vcmd_idx; |
| 10623 | cb->args[3] = (unsigned long)data; |
| 10624 | cb->args[4] = data_len; |
| 10625 | |
| 10626 | /* keep rtnl locked in successful case */ |
| 10627 | return 0; |
| 10628 | out_unlock: |
| 10629 | rtnl_unlock(); |
| 10630 | return err; |
| 10631 | } |
| 10632 | |
| 10633 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 10634 | struct netlink_callback *cb) |
| 10635 | { |
| 10636 | struct cfg80211_registered_device *rdev; |
| 10637 | struct wireless_dev *wdev; |
| 10638 | unsigned int vcmd_idx; |
| 10639 | const struct wiphy_vendor_command *vcmd; |
| 10640 | void *data; |
| 10641 | int data_len; |
| 10642 | int err; |
| 10643 | struct nlattr *vendor_data; |
| 10644 | |
| 10645 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 10646 | if (err) |
| 10647 | return err; |
| 10648 | |
| 10649 | vcmd_idx = cb->args[2]; |
| 10650 | data = (void *)cb->args[3]; |
| 10651 | data_len = cb->args[4]; |
| 10652 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 10653 | |
| 10654 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 10655 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 10656 | if (!wdev) |
| 10657 | return -EINVAL; |
| 10658 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 10659 | !wdev->netdev) |
| 10660 | return -EINVAL; |
| 10661 | |
| 10662 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 10663 | if (wdev->netdev && |
| 10664 | !netif_running(wdev->netdev)) |
| 10665 | return -ENETDOWN; |
| 10666 | if (!wdev->netdev && !wdev->p2p_started) |
| 10667 | return -ENETDOWN; |
| 10668 | } |
| 10669 | } |
| 10670 | |
| 10671 | while (1) { |
| 10672 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10673 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10674 | NL80211_CMD_VENDOR); |
| 10675 | if (!hdr) |
| 10676 | break; |
| 10677 | |
| 10678 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10679 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10680 | wdev_id(wdev), |
| 10681 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 10682 | genlmsg_cancel(skb, hdr); |
| 10683 | break; |
| 10684 | } |
| 10685 | |
| 10686 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 10687 | if (!vendor_data) { |
| 10688 | genlmsg_cancel(skb, hdr); |
| 10689 | break; |
| 10690 | } |
| 10691 | |
| 10692 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 10693 | (unsigned long *)&cb->args[5]); |
| 10694 | nla_nest_end(skb, vendor_data); |
| 10695 | |
| 10696 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10697 | genlmsg_cancel(skb, hdr); |
| 10698 | break; |
| 10699 | } else if (err) { |
| 10700 | genlmsg_cancel(skb, hdr); |
| 10701 | goto out; |
| 10702 | } |
| 10703 | |
| 10704 | genlmsg_end(skb, hdr); |
| 10705 | } |
| 10706 | |
| 10707 | err = skb->len; |
| 10708 | out: |
| 10709 | rtnl_unlock(); |
| 10710 | return err; |
| 10711 | } |
| 10712 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10713 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 10714 | enum nl80211_commands cmd, |
| 10715 | enum nl80211_attrs attr, |
| 10716 | int approxlen) |
| 10717 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10718 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10719 | |
| 10720 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 10721 | return NULL; |
| 10722 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10723 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10724 | rdev->cur_cmd_info->snd_portid, |
| 10725 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10726 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10727 | } |
| 10728 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 10729 | |
| 10730 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 10731 | { |
| 10732 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10733 | void *hdr = ((void **)skb->cb)[1]; |
| 10734 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10735 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10736 | /* clear CB data for netlink core to own from now on */ |
| 10737 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10738 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10739 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 10740 | kfree_skb(skb); |
| 10741 | return -EINVAL; |
| 10742 | } |
| 10743 | |
| 10744 | nla_nest_end(skb, data); |
| 10745 | genlmsg_end(skb, hdr); |
| 10746 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 10747 | } |
| 10748 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 10749 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10750 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 10751 | struct genl_info *info) |
| 10752 | { |
| 10753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10754 | struct cfg80211_qos_map *qos_map = NULL; |
| 10755 | struct net_device *dev = info->user_ptr[1]; |
| 10756 | u8 *pos, len, num_des, des_len, des; |
| 10757 | int ret; |
| 10758 | |
| 10759 | if (!rdev->ops->set_qos_map) |
| 10760 | return -EOPNOTSUPP; |
| 10761 | |
| 10762 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 10763 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10764 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 10765 | |
| 10766 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 10767 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 10768 | return -EINVAL; |
| 10769 | |
| 10770 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 10771 | if (!qos_map) |
| 10772 | return -ENOMEM; |
| 10773 | |
| 10774 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 10775 | if (num_des) { |
| 10776 | des_len = num_des * |
| 10777 | sizeof(struct cfg80211_dscp_exception); |
| 10778 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 10779 | qos_map->num_des = num_des; |
| 10780 | for (des = 0; des < num_des; des++) { |
| 10781 | if (qos_map->dscp_exception[des].up > 7) { |
| 10782 | kfree(qos_map); |
| 10783 | return -EINVAL; |
| 10784 | } |
| 10785 | } |
| 10786 | pos += des_len; |
| 10787 | } |
| 10788 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 10789 | } |
| 10790 | |
| 10791 | wdev_lock(dev->ieee80211_ptr); |
| 10792 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 10793 | if (!ret) |
| 10794 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 10795 | wdev_unlock(dev->ieee80211_ptr); |
| 10796 | |
| 10797 | kfree(qos_map); |
| 10798 | return ret; |
| 10799 | } |
| 10800 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10801 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10802 | { |
| 10803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10804 | struct net_device *dev = info->user_ptr[1]; |
| 10805 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10806 | const u8 *peer; |
| 10807 | u8 tsid, up; |
| 10808 | u16 admitted_time = 0; |
| 10809 | int err; |
| 10810 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10811 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10812 | return -EOPNOTSUPP; |
| 10813 | |
| 10814 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 10815 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 10816 | return -EINVAL; |
| 10817 | |
| 10818 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10819 | if (tsid >= IEEE80211_NUM_TIDS) |
| 10820 | return -EINVAL; |
| 10821 | |
| 10822 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 10823 | if (up >= IEEE80211_NUM_UPS) |
| 10824 | return -EINVAL; |
| 10825 | |
| 10826 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10827 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10828 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 10829 | * need more attributes for that (e.g. BA session requirement); |
| 10830 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10831 | */ |
| 10832 | return -EINVAL; |
| 10833 | } |
| 10834 | |
| 10835 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10836 | |
| 10837 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 10838 | admitted_time = |
| 10839 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 10840 | if (!admitted_time) |
| 10841 | return -EINVAL; |
| 10842 | } |
| 10843 | |
| 10844 | wdev_lock(wdev); |
| 10845 | switch (wdev->iftype) { |
| 10846 | case NL80211_IFTYPE_STATION: |
| 10847 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10848 | if (wdev->current_bss) |
| 10849 | break; |
| 10850 | err = -ENOTCONN; |
| 10851 | goto out; |
| 10852 | default: |
| 10853 | err = -EOPNOTSUPP; |
| 10854 | goto out; |
| 10855 | } |
| 10856 | |
| 10857 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 10858 | |
| 10859 | out: |
| 10860 | wdev_unlock(wdev); |
| 10861 | return err; |
| 10862 | } |
| 10863 | |
| 10864 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 10865 | { |
| 10866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10867 | struct net_device *dev = info->user_ptr[1]; |
| 10868 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10869 | const u8 *peer; |
| 10870 | u8 tsid; |
| 10871 | int err; |
| 10872 | |
| 10873 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 10874 | return -EINVAL; |
| 10875 | |
| 10876 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 10877 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10878 | |
| 10879 | wdev_lock(wdev); |
| 10880 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 10881 | wdev_unlock(wdev); |
| 10882 | |
| 10883 | return err; |
| 10884 | } |
| 10885 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10886 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 10887 | struct genl_info *info) |
| 10888 | { |
| 10889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10890 | struct net_device *dev = info->user_ptr[1]; |
| 10891 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10892 | struct cfg80211_chan_def chandef = {}; |
| 10893 | const u8 *addr; |
| 10894 | u8 oper_class; |
| 10895 | int err; |
| 10896 | |
| 10897 | if (!rdev->ops->tdls_channel_switch || |
| 10898 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10899 | return -EOPNOTSUPP; |
| 10900 | |
| 10901 | switch (dev->ieee80211_ptr->iftype) { |
| 10902 | case NL80211_IFTYPE_STATION: |
| 10903 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10904 | break; |
| 10905 | default: |
| 10906 | return -EOPNOTSUPP; |
| 10907 | } |
| 10908 | |
| 10909 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 10910 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 10911 | return -EINVAL; |
| 10912 | |
| 10913 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10914 | if (err) |
| 10915 | return err; |
| 10916 | |
| 10917 | /* |
| 10918 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 10919 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 10920 | * specification is not defined for them. |
| 10921 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10922 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10923 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 10924 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 10925 | return -EINVAL; |
| 10926 | |
| 10927 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 10928 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 10929 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10930 | return -EINVAL; |
| 10931 | |
| 10932 | /* don't allow switching to DFS channels */ |
| 10933 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10934 | return -EINVAL; |
| 10935 | |
| 10936 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10937 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10938 | |
| 10939 | wdev_lock(wdev); |
| 10940 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10941 | wdev_unlock(wdev); |
| 10942 | |
| 10943 | return err; |
| 10944 | } |
| 10945 | |
| 10946 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10947 | struct genl_info *info) |
| 10948 | { |
| 10949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10950 | struct net_device *dev = info->user_ptr[1]; |
| 10951 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10952 | const u8 *addr; |
| 10953 | |
| 10954 | if (!rdev->ops->tdls_channel_switch || |
| 10955 | !rdev->ops->tdls_cancel_channel_switch || |
| 10956 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10957 | return -EOPNOTSUPP; |
| 10958 | |
| 10959 | switch (dev->ieee80211_ptr->iftype) { |
| 10960 | case NL80211_IFTYPE_STATION: |
| 10961 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10962 | break; |
| 10963 | default: |
| 10964 | return -EOPNOTSUPP; |
| 10965 | } |
| 10966 | |
| 10967 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10968 | return -EINVAL; |
| 10969 | |
| 10970 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10971 | |
| 10972 | wdev_lock(wdev); |
| 10973 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10974 | wdev_unlock(wdev); |
| 10975 | |
| 10976 | return 0; |
| 10977 | } |
| 10978 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10979 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10980 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10981 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10982 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10983 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10984 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10985 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10986 | /* 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] | 10987 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10988 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10989 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10990 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10991 | 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] | 10992 | struct genl_info *info) |
| 10993 | { |
| 10994 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10995 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10996 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10997 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10998 | |
| 10999 | if (rtnl) |
| 11000 | rtnl_lock(); |
| 11001 | |
| 11002 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 11003 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11004 | if (IS_ERR(rdev)) { |
| 11005 | if (rtnl) |
| 11006 | rtnl_unlock(); |
| 11007 | return PTR_ERR(rdev); |
| 11008 | } |
| 11009 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11010 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 11011 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11012 | ASSERT_RTNL(); |
| 11013 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11014 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 11015 | info->attrs); |
| 11016 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11017 | if (rtnl) |
| 11018 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11019 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11020 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11021 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11022 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11023 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11024 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11025 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 11026 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11027 | if (rtnl) |
| 11028 | rtnl_unlock(); |
| 11029 | return -EINVAL; |
| 11030 | } |
| 11031 | |
| 11032 | info->user_ptr[1] = dev; |
| 11033 | } else { |
| 11034 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11035 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11036 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11037 | if (dev) { |
| 11038 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 11039 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11040 | if (rtnl) |
| 11041 | rtnl_unlock(); |
| 11042 | return -ENETDOWN; |
| 11043 | } |
| 11044 | |
| 11045 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11046 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 11047 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11048 | if (rtnl) |
| 11049 | rtnl_unlock(); |
| 11050 | return -ENETDOWN; |
| 11051 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11052 | } |
| 11053 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11054 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11055 | } |
| 11056 | |
| 11057 | return 0; |
| 11058 | } |
| 11059 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11060 | 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] | 11061 | struct genl_info *info) |
| 11062 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11063 | if (info->user_ptr[1]) { |
| 11064 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 11065 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11066 | |
| 11067 | if (wdev->netdev) |
| 11068 | dev_put(wdev->netdev); |
| 11069 | } else { |
| 11070 | dev_put(info->user_ptr[1]); |
| 11071 | } |
| 11072 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11073 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11074 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 11075 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11076 | |
| 11077 | /* If needed, clear the netlink message payload from the SKB |
| 11078 | * as it might contain key data that shouldn't stick around on |
| 11079 | * the heap after the SKB is freed. The netlink message header |
| 11080 | * is still needed for further processing, so leave it intact. |
| 11081 | */ |
| 11082 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 11083 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 11084 | |
| 11085 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 11086 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11087 | } |
| 11088 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 11089 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11090 | { |
| 11091 | .cmd = NL80211_CMD_GET_WIPHY, |
| 11092 | .doit = nl80211_get_wiphy, |
| 11093 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11094 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11095 | .policy = nl80211_policy, |
| 11096 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11097 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11098 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11099 | }, |
| 11100 | { |
| 11101 | .cmd = NL80211_CMD_SET_WIPHY, |
| 11102 | .doit = nl80211_set_wiphy, |
| 11103 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11104 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11105 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11106 | }, |
| 11107 | { |
| 11108 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 11109 | .doit = nl80211_get_interface, |
| 11110 | .dumpit = nl80211_dump_interface, |
| 11111 | .policy = nl80211_policy, |
| 11112 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11113 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11114 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11115 | }, |
| 11116 | { |
| 11117 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 11118 | .doit = nl80211_set_interface, |
| 11119 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11120 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11121 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11122 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11123 | }, |
| 11124 | { |
| 11125 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 11126 | .doit = nl80211_new_interface, |
| 11127 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11128 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11129 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11130 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11131 | }, |
| 11132 | { |
| 11133 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 11134 | .doit = nl80211_del_interface, |
| 11135 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11136 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 11137 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11138 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11139 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11140 | { |
| 11141 | .cmd = NL80211_CMD_GET_KEY, |
| 11142 | .doit = nl80211_get_key, |
| 11143 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11144 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11146 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11147 | }, |
| 11148 | { |
| 11149 | .cmd = NL80211_CMD_SET_KEY, |
| 11150 | .doit = nl80211_set_key, |
| 11151 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11152 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11153 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11154 | NL80211_FLAG_NEED_RTNL | |
| 11155 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11156 | }, |
| 11157 | { |
| 11158 | .cmd = NL80211_CMD_NEW_KEY, |
| 11159 | .doit = nl80211_new_key, |
| 11160 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11161 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11162 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11163 | NL80211_FLAG_NEED_RTNL | |
| 11164 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11165 | }, |
| 11166 | { |
| 11167 | .cmd = NL80211_CMD_DEL_KEY, |
| 11168 | .doit = nl80211_del_key, |
| 11169 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11170 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11172 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11173 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11174 | { |
| 11175 | .cmd = NL80211_CMD_SET_BEACON, |
| 11176 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11177 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11178 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11180 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11181 | }, |
| 11182 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11183 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11184 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11185 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11186 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11187 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11188 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11189 | }, |
| 11190 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11191 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11192 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11193 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11194 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11195 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11196 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11197 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11198 | { |
| 11199 | .cmd = NL80211_CMD_GET_STATION, |
| 11200 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11201 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11202 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11203 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11204 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11205 | }, |
| 11206 | { |
| 11207 | .cmd = NL80211_CMD_SET_STATION, |
| 11208 | .doit = nl80211_set_station, |
| 11209 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11210 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11211 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11212 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11213 | }, |
| 11214 | { |
| 11215 | .cmd = NL80211_CMD_NEW_STATION, |
| 11216 | .doit = nl80211_new_station, |
| 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 | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11220 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11221 | }, |
| 11222 | { |
| 11223 | .cmd = NL80211_CMD_DEL_STATION, |
| 11224 | .doit = nl80211_del_station, |
| 11225 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11226 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11228 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11229 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11230 | { |
| 11231 | .cmd = NL80211_CMD_GET_MPATH, |
| 11232 | .doit = nl80211_get_mpath, |
| 11233 | .dumpit = nl80211_dump_mpath, |
| 11234 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11235 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +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, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11238 | }, |
| 11239 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11240 | .cmd = NL80211_CMD_GET_MPP, |
| 11241 | .doit = nl80211_get_mpp, |
| 11242 | .dumpit = nl80211_dump_mpp, |
| 11243 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11244 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 11245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11246 | NL80211_FLAG_NEED_RTNL, |
| 11247 | }, |
| 11248 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11249 | .cmd = NL80211_CMD_SET_MPATH, |
| 11250 | .doit = nl80211_set_mpath, |
| 11251 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11252 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11254 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11255 | }, |
| 11256 | { |
| 11257 | .cmd = NL80211_CMD_NEW_MPATH, |
| 11258 | .doit = nl80211_new_mpath, |
| 11259 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11260 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11261 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11262 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11263 | }, |
| 11264 | { |
| 11265 | .cmd = NL80211_CMD_DEL_MPATH, |
| 11266 | .doit = nl80211_del_mpath, |
| 11267 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11268 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11269 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11270 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11271 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11272 | { |
| 11273 | .cmd = NL80211_CMD_SET_BSS, |
| 11274 | .doit = nl80211_set_bss, |
| 11275 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11276 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11278 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 11279 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11280 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11281 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11282 | .doit = nl80211_get_reg_do, |
| 11283 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11284 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11285 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11286 | /* can be retrieved by unprivileged users */ |
| 11287 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11288 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 11289 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11290 | .cmd = NL80211_CMD_SET_REG, |
| 11291 | .doit = nl80211_set_reg, |
| 11292 | .policy = nl80211_policy, |
| 11293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11294 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11295 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 11296 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 11297 | { |
| 11298 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 11299 | .doit = nl80211_req_set_reg, |
| 11300 | .policy = nl80211_policy, |
| 11301 | .flags = GENL_ADMIN_PERM, |
| 11302 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11303 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11304 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 11305 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11306 | .policy = nl80211_policy, |
| 11307 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11308 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11309 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11310 | }, |
| 11311 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11312 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 11313 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11314 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11315 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11317 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 11318 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 11319 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11320 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 11321 | .doit = nl80211_trigger_scan, |
| 11322 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11323 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11324 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11325 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11326 | }, |
| 11327 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11328 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 11329 | .doit = nl80211_abort_scan, |
| 11330 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11331 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 11332 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11333 | NL80211_FLAG_NEED_RTNL, |
| 11334 | }, |
| 11335 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11336 | .cmd = NL80211_CMD_GET_SCAN, |
| 11337 | .policy = nl80211_policy, |
| 11338 | .dumpit = nl80211_dump_scan, |
| 11339 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11340 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11341 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 11342 | .doit = nl80211_start_sched_scan, |
| 11343 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11344 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11345 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11346 | NL80211_FLAG_NEED_RTNL, |
| 11347 | }, |
| 11348 | { |
| 11349 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 11350 | .doit = nl80211_stop_sched_scan, |
| 11351 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11352 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11353 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11354 | NL80211_FLAG_NEED_RTNL, |
| 11355 | }, |
| 11356 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11357 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 11358 | .doit = nl80211_authenticate, |
| 11359 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11360 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11361 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11362 | NL80211_FLAG_NEED_RTNL | |
| 11363 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11364 | }, |
| 11365 | { |
| 11366 | .cmd = NL80211_CMD_ASSOCIATE, |
| 11367 | .doit = nl80211_associate, |
| 11368 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11369 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11370 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11371 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11372 | }, |
| 11373 | { |
| 11374 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 11375 | .doit = nl80211_deauthenticate, |
| 11376 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11377 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11379 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11380 | }, |
| 11381 | { |
| 11382 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 11383 | .doit = nl80211_disassociate, |
| 11384 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11385 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11386 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11387 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 11388 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11389 | { |
| 11390 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 11391 | .doit = nl80211_join_ibss, |
| 11392 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11393 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11394 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11396 | }, |
| 11397 | { |
| 11398 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 11399 | .doit = nl80211_leave_ibss, |
| 11400 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11401 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11403 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11404 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11405 | #ifdef CONFIG_NL80211_TESTMODE |
| 11406 | { |
| 11407 | .cmd = NL80211_CMD_TESTMODE, |
| 11408 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 11409 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11410 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11411 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11412 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11413 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11414 | }, |
| 11415 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11416 | { |
| 11417 | .cmd = NL80211_CMD_CONNECT, |
| 11418 | .doit = nl80211_connect, |
| 11419 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11420 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11422 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11423 | }, |
| 11424 | { |
| 11425 | .cmd = NL80211_CMD_DISCONNECT, |
| 11426 | .doit = nl80211_disconnect, |
| 11427 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11428 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11430 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11431 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11432 | { |
| 11433 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 11434 | .doit = nl80211_wiphy_netns, |
| 11435 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11436 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11437 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11438 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11439 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 11440 | { |
| 11441 | .cmd = NL80211_CMD_GET_SURVEY, |
| 11442 | .policy = nl80211_policy, |
| 11443 | .dumpit = nl80211_dump_survey, |
| 11444 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11445 | { |
| 11446 | .cmd = NL80211_CMD_SET_PMKSA, |
| 11447 | .doit = nl80211_setdel_pmksa, |
| 11448 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11449 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11451 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11452 | }, |
| 11453 | { |
| 11454 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 11455 | .doit = nl80211_setdel_pmksa, |
| 11456 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11457 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11459 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11460 | }, |
| 11461 | { |
| 11462 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 11463 | .doit = nl80211_flush_pmksa, |
| 11464 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11465 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11467 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11468 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11469 | { |
| 11470 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 11471 | .doit = nl80211_remain_on_channel, |
| 11472 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11473 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11474 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11475 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11476 | }, |
| 11477 | { |
| 11478 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 11479 | .doit = nl80211_cancel_remain_on_channel, |
| 11480 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11481 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11482 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11483 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11484 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11485 | { |
| 11486 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 11487 | .doit = nl80211_set_tx_bitrate_mask, |
| 11488 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11489 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11490 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11491 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11492 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11493 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11494 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 11495 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11496 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11497 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11498 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11499 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11500 | }, |
| 11501 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11502 | .cmd = NL80211_CMD_FRAME, |
| 11503 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11504 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11505 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11506 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11507 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11508 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11509 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11510 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 11511 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 11512 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11513 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11514 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11515 | NL80211_FLAG_NEED_RTNL, |
| 11516 | }, |
| 11517 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11518 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 11519 | .doit = nl80211_set_power_save, |
| 11520 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11521 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11522 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11523 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11524 | }, |
| 11525 | { |
| 11526 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 11527 | .doit = nl80211_get_power_save, |
| 11528 | .policy = nl80211_policy, |
| 11529 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11530 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11531 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11532 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11533 | { |
| 11534 | .cmd = NL80211_CMD_SET_CQM, |
| 11535 | .doit = nl80211_set_cqm, |
| 11536 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11537 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11538 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11539 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11540 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11541 | { |
| 11542 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 11543 | .doit = nl80211_set_channel, |
| 11544 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11545 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11546 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11547 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11548 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11549 | { |
| 11550 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 11551 | .doit = nl80211_set_wds_peer, |
| 11552 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11553 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 11554 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11555 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 11556 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11557 | { |
| 11558 | .cmd = NL80211_CMD_JOIN_MESH, |
| 11559 | .doit = nl80211_join_mesh, |
| 11560 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11561 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11562 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11563 | NL80211_FLAG_NEED_RTNL, |
| 11564 | }, |
| 11565 | { |
| 11566 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 11567 | .doit = nl80211_leave_mesh, |
| 11568 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11569 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11571 | NL80211_FLAG_NEED_RTNL, |
| 11572 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11573 | { |
| 11574 | .cmd = NL80211_CMD_JOIN_OCB, |
| 11575 | .doit = nl80211_join_ocb, |
| 11576 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11577 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11579 | NL80211_FLAG_NEED_RTNL, |
| 11580 | }, |
| 11581 | { |
| 11582 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 11583 | .doit = nl80211_leave_ocb, |
| 11584 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11585 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11587 | NL80211_FLAG_NEED_RTNL, |
| 11588 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11589 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11590 | { |
| 11591 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 11592 | .doit = nl80211_get_wowlan, |
| 11593 | .policy = nl80211_policy, |
| 11594 | /* can be retrieved by unprivileged users */ |
| 11595 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11596 | NL80211_FLAG_NEED_RTNL, |
| 11597 | }, |
| 11598 | { |
| 11599 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 11600 | .doit = nl80211_set_wowlan, |
| 11601 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11602 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11603 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11604 | NL80211_FLAG_NEED_RTNL, |
| 11605 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11606 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11607 | { |
| 11608 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 11609 | .doit = nl80211_set_rekey_data, |
| 11610 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11611 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11613 | NL80211_FLAG_NEED_RTNL | |
| 11614 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11615 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11616 | { |
| 11617 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 11618 | .doit = nl80211_tdls_mgmt, |
| 11619 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11620 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11622 | NL80211_FLAG_NEED_RTNL, |
| 11623 | }, |
| 11624 | { |
| 11625 | .cmd = NL80211_CMD_TDLS_OPER, |
| 11626 | .doit = nl80211_tdls_oper, |
| 11627 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11628 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11630 | NL80211_FLAG_NEED_RTNL, |
| 11631 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11632 | { |
| 11633 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 11634 | .doit = nl80211_register_unexpected_frame, |
| 11635 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11637 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11638 | NL80211_FLAG_NEED_RTNL, |
| 11639 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11640 | { |
| 11641 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 11642 | .doit = nl80211_probe_client, |
| 11643 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11644 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11646 | NL80211_FLAG_NEED_RTNL, |
| 11647 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11648 | { |
| 11649 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 11650 | .doit = nl80211_register_beacons, |
| 11651 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11652 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11653 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11654 | NL80211_FLAG_NEED_RTNL, |
| 11655 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11656 | { |
| 11657 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 11658 | .doit = nl80211_set_noack_map, |
| 11659 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11660 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 11661 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11662 | NL80211_FLAG_NEED_RTNL, |
| 11663 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11664 | { |
| 11665 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 11666 | .doit = nl80211_start_p2p_device, |
| 11667 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11668 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11669 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11670 | NL80211_FLAG_NEED_RTNL, |
| 11671 | }, |
| 11672 | { |
| 11673 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 11674 | .doit = nl80211_stop_p2p_device, |
| 11675 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11676 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11677 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11678 | NL80211_FLAG_NEED_RTNL, |
| 11679 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11680 | { |
| 11681 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 11682 | .doit = nl80211_set_mcast_rate, |
| 11683 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11684 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 11685 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11686 | NL80211_FLAG_NEED_RTNL, |
| 11687 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11688 | { |
| 11689 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 11690 | .doit = nl80211_set_mac_acl, |
| 11691 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11692 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 11693 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11694 | NL80211_FLAG_NEED_RTNL, |
| 11695 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11696 | { |
| 11697 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 11698 | .doit = nl80211_start_radar_detection, |
| 11699 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11700 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11701 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11702 | NL80211_FLAG_NEED_RTNL, |
| 11703 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11704 | { |
| 11705 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 11706 | .doit = nl80211_get_protocol_features, |
| 11707 | .policy = nl80211_policy, |
| 11708 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11709 | { |
| 11710 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 11711 | .doit = nl80211_update_ft_ies, |
| 11712 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11713 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11715 | NL80211_FLAG_NEED_RTNL, |
| 11716 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11717 | { |
| 11718 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 11719 | .doit = nl80211_crit_protocol_start, |
| 11720 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11721 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11722 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11723 | NL80211_FLAG_NEED_RTNL, |
| 11724 | }, |
| 11725 | { |
| 11726 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 11727 | .doit = nl80211_crit_protocol_stop, |
| 11728 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11729 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11730 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 11731 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11732 | }, |
| 11733 | { |
| 11734 | .cmd = NL80211_CMD_GET_COALESCE, |
| 11735 | .doit = nl80211_get_coalesce, |
| 11736 | .policy = nl80211_policy, |
| 11737 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11738 | NL80211_FLAG_NEED_RTNL, |
| 11739 | }, |
| 11740 | { |
| 11741 | .cmd = NL80211_CMD_SET_COALESCE, |
| 11742 | .doit = nl80211_set_coalesce, |
| 11743 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11744 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 11745 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11746 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11747 | }, |
| 11748 | { |
| 11749 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 11750 | .doit = nl80211_channel_switch, |
| 11751 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11752 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 11753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11754 | NL80211_FLAG_NEED_RTNL, |
| 11755 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11756 | { |
| 11757 | .cmd = NL80211_CMD_VENDOR, |
| 11758 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11759 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11760 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11761 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11762 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11763 | NL80211_FLAG_NEED_RTNL, |
| 11764 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11765 | { |
| 11766 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 11767 | .doit = nl80211_set_qos_map, |
| 11768 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11769 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11771 | NL80211_FLAG_NEED_RTNL, |
| 11772 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11773 | { |
| 11774 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 11775 | .doit = nl80211_add_tx_ts, |
| 11776 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11777 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11779 | NL80211_FLAG_NEED_RTNL, |
| 11780 | }, |
| 11781 | { |
| 11782 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 11783 | .doit = nl80211_del_tx_ts, |
| 11784 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11785 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11786 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11787 | NL80211_FLAG_NEED_RTNL, |
| 11788 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11789 | { |
| 11790 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 11791 | .doit = nl80211_tdls_channel_switch, |
| 11792 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11793 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11794 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11795 | NL80211_FLAG_NEED_RTNL, |
| 11796 | }, |
| 11797 | { |
| 11798 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 11799 | .doit = nl80211_tdls_cancel_channel_switch, |
| 11800 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11801 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 11803 | NL80211_FLAG_NEED_RTNL, |
| 11804 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11805 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11806 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11807 | /* notification functions */ |
| 11808 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11809 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 11810 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11811 | { |
| 11812 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11813 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11814 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11815 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 11816 | cmd != NL80211_CMD_DEL_WIPHY); |
| 11817 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11819 | if (!msg) |
| 11820 | return; |
| 11821 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 11822 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11823 | nlmsg_free(msg); |
| 11824 | return; |
| 11825 | } |
| 11826 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11827 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11828 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11829 | } |
| 11830 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 11831 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 11832 | struct wireless_dev *wdev, |
| 11833 | enum nl80211_commands cmd) |
| 11834 | { |
| 11835 | struct sk_buff *msg; |
| 11836 | |
| 11837 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 11838 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 11839 | |
| 11840 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11841 | if (!msg) |
| 11842 | return; |
| 11843 | |
| 11844 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 11845 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 11846 | nlmsg_free(msg); |
| 11847 | return; |
| 11848 | } |
| 11849 | |
| 11850 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 11851 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 11852 | } |
| 11853 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11854 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 11855 | struct cfg80211_registered_device *rdev) |
| 11856 | { |
| 11857 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 11858 | struct nlattr *nest; |
| 11859 | int i; |
| 11860 | |
| 11861 | if (WARN_ON(!req)) |
| 11862 | return 0; |
| 11863 | |
| 11864 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 11865 | if (!nest) |
| 11866 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11867 | for (i = 0; i < req->n_ssids; i++) { |
| 11868 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 11869 | goto nla_put_failure; |
| 11870 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11871 | nla_nest_end(msg, nest); |
| 11872 | |
| 11873 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 11874 | if (!nest) |
| 11875 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11876 | for (i = 0; i < req->n_channels; i++) { |
| 11877 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11878 | goto nla_put_failure; |
| 11879 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11880 | nla_nest_end(msg, nest); |
| 11881 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11882 | if (req->ie && |
| 11883 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 11884 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11885 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11886 | if (req->flags && |
| 11887 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 11888 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 11889 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 11890 | if (req->info.scan_start_tsf && |
| 11891 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 11892 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 11893 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 11894 | req->info.tsf_bssid))) |
| 11895 | goto nla_put_failure; |
| 11896 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11897 | return 0; |
| 11898 | nla_put_failure: |
| 11899 | return -ENOBUFS; |
| 11900 | } |
| 11901 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11902 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 11903 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11904 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11905 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11906 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11907 | { |
| 11908 | void *hdr; |
| 11909 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11910 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11911 | if (!hdr) |
| 11912 | return -1; |
| 11913 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11915 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11916 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11917 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11918 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11919 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11920 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 11921 | /* ignore errors and send incomplete event anyway */ |
| 11922 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11923 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11924 | genlmsg_end(msg, hdr); |
| 11925 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11926 | |
| 11927 | nla_put_failure: |
| 11928 | genlmsg_cancel(msg, hdr); |
| 11929 | return -EMSGSIZE; |
| 11930 | } |
| 11931 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11932 | static int |
| 11933 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 11934 | struct cfg80211_registered_device *rdev, |
| 11935 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11936 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11937 | { |
| 11938 | void *hdr; |
| 11939 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11940 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11941 | if (!hdr) |
| 11942 | return -1; |
| 11943 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11944 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11945 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11946 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11947 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 11948 | genlmsg_end(msg, hdr); |
| 11949 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11950 | |
| 11951 | nla_put_failure: |
| 11952 | genlmsg_cancel(msg, hdr); |
| 11953 | return -EMSGSIZE; |
| 11954 | } |
| 11955 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11956 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11957 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11958 | { |
| 11959 | struct sk_buff *msg; |
| 11960 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11961 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11962 | if (!msg) |
| 11963 | return; |
| 11964 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11965 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11966 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 11967 | nlmsg_free(msg); |
| 11968 | return; |
| 11969 | } |
| 11970 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11971 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11972 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 11973 | } |
| 11974 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11975 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 11976 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11977 | { |
| 11978 | struct sk_buff *msg; |
| 11979 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11981 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11982 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11983 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11984 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11985 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11986 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11987 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11988 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11989 | } |
| 11990 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11991 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11992 | } |
| 11993 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11994 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11995 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11996 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11997 | if (!msg) |
| 11998 | return; |
| 11999 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12000 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12001 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12002 | } |
| 12003 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12004 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 12005 | struct net_device *netdev) |
| 12006 | { |
| 12007 | struct sk_buff *msg; |
| 12008 | |
| 12009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12010 | if (!msg) |
| 12011 | return; |
| 12012 | |
| 12013 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 12014 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 12015 | nlmsg_free(msg); |
| 12016 | return; |
| 12017 | } |
| 12018 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12019 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12020 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12021 | } |
| 12022 | |
| 12023 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 12024 | struct net_device *netdev, u32 cmd) |
| 12025 | { |
| 12026 | struct sk_buff *msg; |
| 12027 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12028 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12029 | if (!msg) |
| 12030 | return; |
| 12031 | |
| 12032 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 12033 | nlmsg_free(msg); |
| 12034 | return; |
| 12035 | } |
| 12036 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12037 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12038 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12039 | } |
| 12040 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12041 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 12042 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12043 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12044 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12045 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 12046 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12047 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12048 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 12049 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12050 | NL80211_REGDOM_TYPE_WORLD)) |
| 12051 | goto nla_put_failure; |
| 12052 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 12053 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12054 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 12055 | goto nla_put_failure; |
| 12056 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 12057 | request->intersect) { |
| 12058 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12059 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 12060 | goto nla_put_failure; |
| 12061 | } else { |
| 12062 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12063 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 12064 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 12065 | request->alpha2)) |
| 12066 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12067 | } |
| 12068 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12069 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 12070 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 12071 | |
| 12072 | if (wiphy && |
| 12073 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 12074 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 12075 | |
| 12076 | if (wiphy && |
| 12077 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 12078 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 12079 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12080 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12081 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12082 | return true; |
| 12083 | |
| 12084 | nla_put_failure: |
| 12085 | return false; |
| 12086 | } |
| 12087 | |
| 12088 | /* |
| 12089 | * This can happen on global regulatory changes or device specific settings |
| 12090 | * based on custom regulatory domains. |
| 12091 | */ |
| 12092 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 12093 | struct regulatory_request *request) |
| 12094 | { |
| 12095 | struct sk_buff *msg; |
| 12096 | void *hdr; |
| 12097 | |
| 12098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12099 | if (!msg) |
| 12100 | return; |
| 12101 | |
| 12102 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 12103 | if (!hdr) { |
| 12104 | nlmsg_free(msg); |
| 12105 | return; |
| 12106 | } |
| 12107 | |
| 12108 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 12109 | goto nla_put_failure; |
| 12110 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12111 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12112 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12113 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12114 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12115 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12116 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12117 | |
| 12118 | return; |
| 12119 | |
| 12120 | nla_put_failure: |
| 12121 | genlmsg_cancel(msg, hdr); |
| 12122 | nlmsg_free(msg); |
| 12123 | } |
| 12124 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12125 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 12126 | struct net_device *netdev, |
| 12127 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12128 | enum nl80211_commands cmd, gfp_t gfp, |
| 12129 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12130 | { |
| 12131 | struct sk_buff *msg; |
| 12132 | void *hdr; |
| 12133 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12134 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12135 | if (!msg) |
| 12136 | return; |
| 12137 | |
| 12138 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12139 | if (!hdr) { |
| 12140 | nlmsg_free(msg); |
| 12141 | return; |
| 12142 | } |
| 12143 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12144 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12145 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12146 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 12147 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12148 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12149 | if (uapsd_queues >= 0) { |
| 12150 | struct nlattr *nla_wmm = |
| 12151 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 12152 | if (!nla_wmm) |
| 12153 | goto nla_put_failure; |
| 12154 | |
| 12155 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 12156 | uapsd_queues)) |
| 12157 | goto nla_put_failure; |
| 12158 | |
| 12159 | nla_nest_end(msg, nla_wmm); |
| 12160 | } |
| 12161 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12162 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12163 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12164 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12165 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12166 | return; |
| 12167 | |
| 12168 | nla_put_failure: |
| 12169 | genlmsg_cancel(msg, hdr); |
| 12170 | nlmsg_free(msg); |
| 12171 | } |
| 12172 | |
| 12173 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12174 | struct net_device *netdev, const u8 *buf, |
| 12175 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12176 | { |
| 12177 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12178 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12179 | } |
| 12180 | |
| 12181 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 12182 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12183 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12184 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12185 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12186 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12187 | } |
| 12188 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12189 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12190 | struct net_device *netdev, const u8 *buf, |
| 12191 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12192 | { |
| 12193 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12194 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12195 | } |
| 12196 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12197 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 12198 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12199 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12200 | { |
| 12201 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12202 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12203 | } |
| 12204 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12205 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 12206 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12207 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12208 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12209 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12210 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12211 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 12212 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12213 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12214 | if (WARN_ON(len < 2)) |
| 12215 | return; |
| 12216 | |
| 12217 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 12218 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 12219 | else |
| 12220 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 12221 | |
| 12222 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12223 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12224 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 12225 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 12226 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 12227 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 12228 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12229 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12230 | { |
| 12231 | struct sk_buff *msg; |
| 12232 | void *hdr; |
| 12233 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12235 | if (!msg) |
| 12236 | return; |
| 12237 | |
| 12238 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12239 | if (!hdr) { |
| 12240 | nlmsg_free(msg); |
| 12241 | return; |
| 12242 | } |
| 12243 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12244 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12245 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12246 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 12247 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12248 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12249 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12250 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12251 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12252 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12253 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12254 | return; |
| 12255 | |
| 12256 | nla_put_failure: |
| 12257 | genlmsg_cancel(msg, hdr); |
| 12258 | nlmsg_free(msg); |
| 12259 | } |
| 12260 | |
| 12261 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12262 | struct net_device *netdev, const u8 *addr, |
| 12263 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12264 | { |
| 12265 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12266 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12267 | } |
| 12268 | |
| 12269 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12270 | struct net_device *netdev, const u8 *addr, |
| 12271 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12272 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12273 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 12274 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 12275 | } |
| 12276 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12277 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 12278 | struct net_device *netdev, const u8 *bssid, |
| 12279 | const u8 *req_ie, size_t req_ie_len, |
| 12280 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12281 | int status, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12282 | { |
| 12283 | struct sk_buff *msg; |
| 12284 | void *hdr; |
| 12285 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12286 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12287 | if (!msg) |
| 12288 | return; |
| 12289 | |
| 12290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 12291 | if (!hdr) { |
| 12292 | nlmsg_free(msg); |
| 12293 | return; |
| 12294 | } |
| 12295 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12296 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12297 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12298 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 12299 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 12300 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 12301 | status) || |
| 12302 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12303 | (req_ie && |
| 12304 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12305 | (resp_ie && |
| 12306 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12307 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12308 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12309 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12310 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12311 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12312 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12313 | return; |
| 12314 | |
| 12315 | nla_put_failure: |
| 12316 | genlmsg_cancel(msg, hdr); |
| 12317 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12318 | } |
| 12319 | |
| 12320 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 12321 | struct net_device *netdev, const u8 *bssid, |
| 12322 | const u8 *req_ie, size_t req_ie_len, |
| 12323 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 12324 | { |
| 12325 | struct sk_buff *msg; |
| 12326 | void *hdr; |
| 12327 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12328 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12329 | if (!msg) |
| 12330 | return; |
| 12331 | |
| 12332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 12333 | if (!hdr) { |
| 12334 | nlmsg_free(msg); |
| 12335 | return; |
| 12336 | } |
| 12337 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12339 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12340 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 12341 | (req_ie && |
| 12342 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 12343 | (resp_ie && |
| 12344 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 12345 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12346 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12347 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12348 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12349 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12350 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12351 | return; |
| 12352 | |
| 12353 | nla_put_failure: |
| 12354 | genlmsg_cancel(msg, hdr); |
| 12355 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12356 | } |
| 12357 | |
| 12358 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 12359 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 12360 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12361 | { |
| 12362 | struct sk_buff *msg; |
| 12363 | void *hdr; |
| 12364 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12366 | if (!msg) |
| 12367 | return; |
| 12368 | |
| 12369 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 12370 | if (!hdr) { |
| 12371 | nlmsg_free(msg); |
| 12372 | return; |
| 12373 | } |
| 12374 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12375 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12376 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12377 | (from_ap && reason && |
| 12378 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 12379 | (from_ap && |
| 12380 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 12381 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 12382 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12383 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12384 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12385 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12386 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12387 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12388 | return; |
| 12389 | |
| 12390 | nla_put_failure: |
| 12391 | genlmsg_cancel(msg, hdr); |
| 12392 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12393 | } |
| 12394 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12395 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 12396 | struct net_device *netdev, const u8 *bssid, |
| 12397 | gfp_t gfp) |
| 12398 | { |
| 12399 | struct sk_buff *msg; |
| 12400 | void *hdr; |
| 12401 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12402 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12403 | if (!msg) |
| 12404 | return; |
| 12405 | |
| 12406 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 12407 | if (!hdr) { |
| 12408 | nlmsg_free(msg); |
| 12409 | return; |
| 12410 | } |
| 12411 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12412 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12413 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12414 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12415 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12416 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12417 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12418 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12419 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12420 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12421 | return; |
| 12422 | |
| 12423 | nla_put_failure: |
| 12424 | genlmsg_cancel(msg, hdr); |
| 12425 | nlmsg_free(msg); |
| 12426 | } |
| 12427 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12428 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 12429 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12430 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12431 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12432 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12433 | struct sk_buff *msg; |
| 12434 | void *hdr; |
| 12435 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12436 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 12437 | return; |
| 12438 | |
| 12439 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 12440 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12441 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12442 | if (!msg) |
| 12443 | return; |
| 12444 | |
| 12445 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 12446 | if (!hdr) { |
| 12447 | nlmsg_free(msg); |
| 12448 | return; |
| 12449 | } |
| 12450 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12451 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12452 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12453 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12454 | (ie_len && ie && |
| 12455 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 12456 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12457 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12458 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12459 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12460 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12461 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12462 | return; |
| 12463 | |
| 12464 | nla_put_failure: |
| 12465 | genlmsg_cancel(msg, hdr); |
| 12466 | nlmsg_free(msg); |
| 12467 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12468 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 12469 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12470 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 12471 | struct net_device *netdev, const u8 *addr, |
| 12472 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12473 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12474 | { |
| 12475 | struct sk_buff *msg; |
| 12476 | void *hdr; |
| 12477 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12479 | if (!msg) |
| 12480 | return; |
| 12481 | |
| 12482 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 12483 | if (!hdr) { |
| 12484 | nlmsg_free(msg); |
| 12485 | return; |
| 12486 | } |
| 12487 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12489 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12490 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 12491 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 12492 | (key_id != -1 && |
| 12493 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 12494 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 12495 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12496 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12497 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12498 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12499 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12500 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 12501 | return; |
| 12502 | |
| 12503 | nla_put_failure: |
| 12504 | genlmsg_cancel(msg, hdr); |
| 12505 | nlmsg_free(msg); |
| 12506 | } |
| 12507 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12508 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 12509 | struct ieee80211_channel *channel_before, |
| 12510 | struct ieee80211_channel *channel_after) |
| 12511 | { |
| 12512 | struct sk_buff *msg; |
| 12513 | void *hdr; |
| 12514 | struct nlattr *nl_freq; |
| 12515 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12516 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12517 | if (!msg) |
| 12518 | return; |
| 12519 | |
| 12520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 12521 | if (!hdr) { |
| 12522 | nlmsg_free(msg); |
| 12523 | return; |
| 12524 | } |
| 12525 | |
| 12526 | /* |
| 12527 | * Since we are applying the beacon hint to a wiphy we know its |
| 12528 | * wiphy_idx is valid |
| 12529 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12530 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 12531 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12532 | |
| 12533 | /* Before */ |
| 12534 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 12535 | if (!nl_freq) |
| 12536 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12537 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12538 | goto nla_put_failure; |
| 12539 | nla_nest_end(msg, nl_freq); |
| 12540 | |
| 12541 | /* After */ |
| 12542 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 12543 | if (!nl_freq) |
| 12544 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 12545 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12546 | goto nla_put_failure; |
| 12547 | nla_nest_end(msg, nl_freq); |
| 12548 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12549 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12550 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12551 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12552 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12553 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12554 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 12555 | |
| 12556 | return; |
| 12557 | |
| 12558 | nla_put_failure: |
| 12559 | genlmsg_cancel(msg, hdr); |
| 12560 | nlmsg_free(msg); |
| 12561 | } |
| 12562 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12563 | static void nl80211_send_remain_on_chan_event( |
| 12564 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12565 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12566 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12567 | unsigned int duration, gfp_t gfp) |
| 12568 | { |
| 12569 | struct sk_buff *msg; |
| 12570 | void *hdr; |
| 12571 | |
| 12572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12573 | if (!msg) |
| 12574 | return; |
| 12575 | |
| 12576 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12577 | if (!hdr) { |
| 12578 | nlmsg_free(msg); |
| 12579 | return; |
| 12580 | } |
| 12581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12583 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12584 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12585 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12586 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12587 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12588 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 12589 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12590 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12591 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12592 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12593 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12594 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 12595 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 12596 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12597 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12598 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12599 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12600 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12601 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12602 | return; |
| 12603 | |
| 12604 | nla_put_failure: |
| 12605 | genlmsg_cancel(msg, hdr); |
| 12606 | nlmsg_free(msg); |
| 12607 | } |
| 12608 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12609 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 12610 | struct ieee80211_channel *chan, |
| 12611 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12612 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12613 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12614 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12615 | |
| 12616 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12617 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12618 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12619 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12620 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12621 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12622 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12623 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 12624 | struct ieee80211_channel *chan, |
| 12625 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12626 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12627 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12628 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12629 | |
| 12630 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12631 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 12632 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12633 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12634 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12635 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12636 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 12637 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12638 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12639 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12640 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12641 | struct sk_buff *msg; |
| 12642 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12643 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 12644 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12646 | if (!msg) |
| 12647 | return; |
| 12648 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12649 | 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] | 12650 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12651 | nlmsg_free(msg); |
| 12652 | return; |
| 12653 | } |
| 12654 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12655 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12656 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12657 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12658 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 12659 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12660 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 12661 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12662 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12663 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12664 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12665 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12666 | struct station_info empty_sinfo = {}; |
| 12667 | |
| 12668 | if (!sinfo) |
| 12669 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12670 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12671 | trace_cfg80211_del_sta(dev, mac_addr); |
| 12672 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12674 | if (!msg) |
| 12675 | return; |
| 12676 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12677 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 12678 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12679 | nlmsg_free(msg); |
| 12680 | return; |
| 12681 | } |
| 12682 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12683 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12684 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12685 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 12686 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 12687 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12688 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 12689 | enum nl80211_connect_failed_reason reason, |
| 12690 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12691 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12692 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12693 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12694 | struct sk_buff *msg; |
| 12695 | void *hdr; |
| 12696 | |
| 12697 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 12698 | if (!msg) |
| 12699 | return; |
| 12700 | |
| 12701 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 12702 | if (!hdr) { |
| 12703 | nlmsg_free(msg); |
| 12704 | return; |
| 12705 | } |
| 12706 | |
| 12707 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12708 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 12709 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 12710 | goto nla_put_failure; |
| 12711 | |
| 12712 | genlmsg_end(msg, hdr); |
| 12713 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12714 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12715 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12716 | return; |
| 12717 | |
| 12718 | nla_put_failure: |
| 12719 | genlmsg_cancel(msg, hdr); |
| 12720 | nlmsg_free(msg); |
| 12721 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12722 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 12723 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12724 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 12725 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12726 | { |
| 12727 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12728 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12729 | struct sk_buff *msg; |
| 12730 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12731 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12732 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12733 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12734 | return false; |
| 12735 | |
| 12736 | msg = nlmsg_new(100, gfp); |
| 12737 | if (!msg) |
| 12738 | return true; |
| 12739 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12740 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12741 | if (!hdr) { |
| 12742 | nlmsg_free(msg); |
| 12743 | return true; |
| 12744 | } |
| 12745 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12746 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12747 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12748 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 12749 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12750 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12751 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12752 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12753 | return true; |
| 12754 | |
| 12755 | nla_put_failure: |
| 12756 | genlmsg_cancel(msg, hdr); |
| 12757 | nlmsg_free(msg); |
| 12758 | return true; |
| 12759 | } |
| 12760 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12761 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 12762 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12763 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12764 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12765 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12766 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12767 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 12768 | |
| 12769 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12770 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 12771 | trace_cfg80211_return_bool(false); |
| 12772 | return false; |
| 12773 | } |
| 12774 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 12775 | addr, gfp); |
| 12776 | trace_cfg80211_return_bool(ret); |
| 12777 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12778 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12779 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 12780 | |
| 12781 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 12782 | const u8 *addr, gfp_t gfp) |
| 12783 | { |
| 12784 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12785 | bool ret; |
| 12786 | |
| 12787 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 12788 | |
| 12789 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 12790 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 12791 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 12792 | trace_cfg80211_return_bool(false); |
| 12793 | return false; |
| 12794 | } |
| 12795 | ret = __nl80211_unexpected_frame(dev, |
| 12796 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 12797 | addr, gfp); |
| 12798 | trace_cfg80211_return_bool(ret); |
| 12799 | return ret; |
| 12800 | } |
| 12801 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 12802 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12803 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12804 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 12805 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12806 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12807 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12808 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12809 | struct sk_buff *msg; |
| 12810 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12811 | |
| 12812 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12813 | if (!msg) |
| 12814 | return -ENOMEM; |
| 12815 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12816 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12817 | if (!hdr) { |
| 12818 | nlmsg_free(msg); |
| 12819 | return -ENOMEM; |
| 12820 | } |
| 12821 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12822 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12823 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12824 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12825 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12826 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12827 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 12828 | (sig_dbm && |
| 12829 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 12830 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 12831 | (flags && |
| 12832 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12833 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12834 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12835 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12836 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12837 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12838 | |
| 12839 | nla_put_failure: |
| 12840 | genlmsg_cancel(msg, hdr); |
| 12841 | nlmsg_free(msg); |
| 12842 | return -ENOBUFS; |
| 12843 | } |
| 12844 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12845 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 12846 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12847 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12848 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12849 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12850 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12851 | struct sk_buff *msg; |
| 12852 | void *hdr; |
| 12853 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12854 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 12855 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12857 | if (!msg) |
| 12858 | return; |
| 12859 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12861 | if (!hdr) { |
| 12862 | nlmsg_free(msg); |
| 12863 | return; |
| 12864 | } |
| 12865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12867 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12868 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12869 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12870 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12871 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12872 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12873 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12874 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12875 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12876 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12877 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12878 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12879 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12880 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12881 | return; |
| 12882 | |
| 12883 | nla_put_failure: |
| 12884 | genlmsg_cancel(msg, hdr); |
| 12885 | nlmsg_free(msg); |
| 12886 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12887 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12888 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12889 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 12890 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12891 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12892 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12893 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 12894 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12895 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12896 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12897 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12898 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12899 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12900 | cb = (void **)msg->cb; |
| 12901 | |
| 12902 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 12903 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12904 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12905 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12906 | } |
| 12907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12909 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12910 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12911 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12912 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12913 | goto nla_put_failure; |
| 12914 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12915 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 12916 | if (!cb[1]) |
| 12917 | goto nla_put_failure; |
| 12918 | |
| 12919 | cb[2] = rdev; |
| 12920 | |
| 12921 | return msg; |
| 12922 | nla_put_failure: |
| 12923 | nlmsg_free(msg); |
| 12924 | return NULL; |
| 12925 | } |
| 12926 | |
| 12927 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 12928 | { |
| 12929 | void **cb = (void **)msg->cb; |
| 12930 | struct cfg80211_registered_device *rdev = cb[2]; |
| 12931 | |
| 12932 | nla_nest_end(msg, cb[1]); |
| 12933 | genlmsg_end(msg, cb[0]); |
| 12934 | |
| 12935 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 12936 | |
| 12937 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12938 | NL80211_MCGRP_MLME, gfp); |
| 12939 | } |
| 12940 | |
| 12941 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 12942 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 12943 | gfp_t gfp) |
| 12944 | { |
| 12945 | struct sk_buff *msg; |
| 12946 | |
| 12947 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 12948 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12949 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 12950 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 12951 | return; |
| 12952 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12953 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12954 | if (!msg) |
| 12955 | return; |
| 12956 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12957 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 12958 | rssi_event)) |
| 12959 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12960 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12961 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12962 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12963 | return; |
| 12964 | |
| 12965 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12966 | nlmsg_free(msg); |
| 12967 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12968 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12969 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 12970 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 12971 | const u8 *peer, u32 num_packets, |
| 12972 | u32 rate, u32 intvl, gfp_t gfp) |
| 12973 | { |
| 12974 | struct sk_buff *msg; |
| 12975 | |
| 12976 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12977 | if (!msg) |
| 12978 | return; |
| 12979 | |
| 12980 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12981 | goto nla_put_failure; |
| 12982 | |
| 12983 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12984 | goto nla_put_failure; |
| 12985 | |
| 12986 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12987 | goto nla_put_failure; |
| 12988 | |
| 12989 | cfg80211_send_cqm(msg, gfp); |
| 12990 | return; |
| 12991 | |
| 12992 | nla_put_failure: |
| 12993 | nlmsg_free(msg); |
| 12994 | } |
| 12995 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12996 | |
| 12997 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12998 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12999 | { |
| 13000 | struct sk_buff *msg; |
| 13001 | |
| 13002 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 13003 | |
| 13004 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13005 | if (!msg) |
| 13006 | return; |
| 13007 | |
| 13008 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 13009 | goto nla_put_failure; |
| 13010 | |
| 13011 | cfg80211_send_cqm(msg, gfp); |
| 13012 | return; |
| 13013 | |
| 13014 | nla_put_failure: |
| 13015 | nlmsg_free(msg); |
| 13016 | } |
| 13017 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 13018 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13019 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 13020 | { |
| 13021 | struct sk_buff *msg; |
| 13022 | |
| 13023 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13024 | if (!msg) |
| 13025 | return; |
| 13026 | |
| 13027 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 13028 | goto nla_put_failure; |
| 13029 | |
| 13030 | cfg80211_send_cqm(msg, gfp); |
| 13031 | return; |
| 13032 | |
| 13033 | nla_put_failure: |
| 13034 | nlmsg_free(msg); |
| 13035 | } |
| 13036 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 13037 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13038 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 13039 | struct net_device *netdev, const u8 *bssid, |
| 13040 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13041 | { |
| 13042 | struct sk_buff *msg; |
| 13043 | struct nlattr *rekey_attr; |
| 13044 | void *hdr; |
| 13045 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13047 | if (!msg) |
| 13048 | return; |
| 13049 | |
| 13050 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 13051 | if (!hdr) { |
| 13052 | nlmsg_free(msg); |
| 13053 | return; |
| 13054 | } |
| 13055 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13056 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13057 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13058 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13059 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13060 | |
| 13061 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 13062 | if (!rekey_attr) |
| 13063 | goto nla_put_failure; |
| 13064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13065 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 13066 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 13067 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13068 | |
| 13069 | nla_nest_end(msg, rekey_attr); |
| 13070 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13071 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13072 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13073 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13074 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13075 | return; |
| 13076 | |
| 13077 | nla_put_failure: |
| 13078 | genlmsg_cancel(msg, hdr); |
| 13079 | nlmsg_free(msg); |
| 13080 | } |
| 13081 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13082 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 13083 | const u8 *replay_ctr, gfp_t gfp) |
| 13084 | { |
| 13085 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13086 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13087 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13088 | |
| 13089 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 13090 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 13091 | } |
| 13092 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 13093 | |
| 13094 | static void |
| 13095 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 13096 | struct net_device *netdev, int index, |
| 13097 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13098 | { |
| 13099 | struct sk_buff *msg; |
| 13100 | struct nlattr *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); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13104 | if (!msg) |
| 13105 | return; |
| 13106 | |
| 13107 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 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 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13116 | |
| 13117 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 13118 | if (!attr) |
| 13119 | goto nla_put_failure; |
| 13120 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13121 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 13122 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 13123 | (preauth && |
| 13124 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 13125 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13126 | |
| 13127 | nla_nest_end(msg, attr); |
| 13128 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13129 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13130 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13131 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13132 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13133 | return; |
| 13134 | |
| 13135 | nla_put_failure: |
| 13136 | genlmsg_cancel(msg, hdr); |
| 13137 | nlmsg_free(msg); |
| 13138 | } |
| 13139 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13140 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 13141 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 13142 | { |
| 13143 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13144 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13145 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13146 | |
| 13147 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 13148 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 13149 | } |
| 13150 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 13151 | |
| 13152 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 13153 | struct net_device *netdev, |
| 13154 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13155 | gfp_t gfp, |
| 13156 | enum nl80211_commands notif, |
| 13157 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13158 | { |
| 13159 | struct sk_buff *msg; |
| 13160 | void *hdr; |
| 13161 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13162 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13163 | if (!msg) |
| 13164 | return; |
| 13165 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13166 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13167 | if (!hdr) { |
| 13168 | nlmsg_free(msg); |
| 13169 | return; |
| 13170 | } |
| 13171 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 13172 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13173 | goto nla_put_failure; |
| 13174 | |
| 13175 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 13176 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13177 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13178 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 13179 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 13180 | goto nla_put_failure; |
| 13181 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13182 | genlmsg_end(msg, hdr); |
| 13183 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13184 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13185 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13186 | return; |
| 13187 | |
| 13188 | nla_put_failure: |
| 13189 | genlmsg_cancel(msg, hdr); |
| 13190 | nlmsg_free(msg); |
| 13191 | } |
| 13192 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13193 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 13194 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13195 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13196 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13197 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13198 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13199 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13200 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13201 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 13202 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13203 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 13204 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 13205 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13206 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13207 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13208 | } |
| 13209 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 13210 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13211 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 13212 | struct cfg80211_chan_def *chandef, |
| 13213 | u8 count) |
| 13214 | { |
| 13215 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13216 | struct wiphy *wiphy = wdev->wiphy; |
| 13217 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13218 | |
| 13219 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 13220 | |
| 13221 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 13222 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 13223 | } |
| 13224 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 13225 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 13226 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13227 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 13228 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13229 | enum nl80211_radar_event event, |
| 13230 | struct net_device *netdev, gfp_t gfp) |
| 13231 | { |
| 13232 | struct sk_buff *msg; |
| 13233 | void *hdr; |
| 13234 | |
| 13235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13236 | if (!msg) |
| 13237 | return; |
| 13238 | |
| 13239 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 13240 | if (!hdr) { |
| 13241 | nlmsg_free(msg); |
| 13242 | return; |
| 13243 | } |
| 13244 | |
| 13245 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 13246 | goto nla_put_failure; |
| 13247 | |
| 13248 | /* NOP and radar events don't need a netdev parameter */ |
| 13249 | if (netdev) { |
| 13250 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 13251 | |
| 13252 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13253 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13254 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13255 | goto nla_put_failure; |
| 13256 | } |
| 13257 | |
| 13258 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 13259 | goto nla_put_failure; |
| 13260 | |
| 13261 | if (nl80211_send_chandef(msg, chandef)) |
| 13262 | goto nla_put_failure; |
| 13263 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13264 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13265 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13266 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13267 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 13268 | return; |
| 13269 | |
| 13270 | nla_put_failure: |
| 13271 | genlmsg_cancel(msg, hdr); |
| 13272 | nlmsg_free(msg); |
| 13273 | } |
| 13274 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13275 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 13276 | u64 cookie, bool acked, gfp_t gfp) |
| 13277 | { |
| 13278 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13279 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13280 | struct sk_buff *msg; |
| 13281 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13282 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13283 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 13284 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13286 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13287 | if (!msg) |
| 13288 | return; |
| 13289 | |
| 13290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 13291 | if (!hdr) { |
| 13292 | nlmsg_free(msg); |
| 13293 | return; |
| 13294 | } |
| 13295 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13296 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13297 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13298 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13299 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13300 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13301 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 13302 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13303 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13304 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13305 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13307 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13308 | return; |
| 13309 | |
| 13310 | nla_put_failure: |
| 13311 | genlmsg_cancel(msg, hdr); |
| 13312 | nlmsg_free(msg); |
| 13313 | } |
| 13314 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 13315 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13316 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 13317 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13318 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13319 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13321 | struct sk_buff *msg; |
| 13322 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13323 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13324 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 13325 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 13326 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13327 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13328 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 13329 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 13330 | if (!msg) { |
| 13331 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13332 | return; |
| 13333 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13334 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 13336 | if (!hdr) |
| 13337 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13338 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13339 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13340 | (freq && |
| 13341 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 13342 | (sig_dbm && |
| 13343 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 13344 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 13345 | goto nla_put_failure; |
| 13346 | |
| 13347 | genlmsg_end(msg, hdr); |
| 13348 | |
| 13349 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13350 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13351 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13352 | return; |
| 13353 | |
| 13354 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13355 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13356 | if (hdr) |
| 13357 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13358 | nlmsg_free(msg); |
| 13359 | } |
| 13360 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 13361 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13362 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13363 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 13364 | struct cfg80211_wowlan_wakeup *wakeup) |
| 13365 | { |
| 13366 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 13367 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 13368 | int i, j; |
| 13369 | |
| 13370 | nl_results = nla_nest_start( |
| 13371 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 13372 | if (!nl_results) |
| 13373 | return -EMSGSIZE; |
| 13374 | |
| 13375 | for (i = 0; i < nd->n_matches; i++) { |
| 13376 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 13377 | |
| 13378 | nl_match = nla_nest_start(msg, i); |
| 13379 | if (!nl_match) |
| 13380 | break; |
| 13381 | |
| 13382 | /* The SSID attribute is optional in nl80211, but for |
| 13383 | * simplicity reasons it's always present in the |
| 13384 | * cfg80211 structure. If a driver can't pass the |
| 13385 | * SSID, that needs to be changed. A zero length SSID |
| 13386 | * is still a valid SSID (wildcard), so it cannot be |
| 13387 | * used for this purpose. |
| 13388 | */ |
| 13389 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 13390 | match->ssid.ssid)) { |
| 13391 | nla_nest_cancel(msg, nl_match); |
| 13392 | goto out; |
| 13393 | } |
| 13394 | |
| 13395 | if (match->n_channels) { |
| 13396 | nl_freqs = nla_nest_start( |
| 13397 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13398 | if (!nl_freqs) { |
| 13399 | nla_nest_cancel(msg, nl_match); |
| 13400 | goto out; |
| 13401 | } |
| 13402 | |
| 13403 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 13404 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13405 | nla_nest_cancel(msg, nl_freqs); |
| 13406 | nla_nest_cancel(msg, nl_match); |
| 13407 | goto out; |
| 13408 | } |
| 13409 | } |
| 13410 | |
| 13411 | nla_nest_end(msg, nl_freqs); |
| 13412 | } |
| 13413 | |
| 13414 | nla_nest_end(msg, nl_match); |
| 13415 | } |
| 13416 | |
| 13417 | out: |
| 13418 | nla_nest_end(msg, nl_results); |
| 13419 | return 0; |
| 13420 | } |
| 13421 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13422 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 13423 | struct cfg80211_wowlan_wakeup *wakeup, |
| 13424 | gfp_t gfp) |
| 13425 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13426 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13427 | struct sk_buff *msg; |
| 13428 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13429 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13430 | |
| 13431 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 13432 | |
| 13433 | if (wakeup) |
| 13434 | size += wakeup->packet_present_len; |
| 13435 | |
| 13436 | msg = nlmsg_new(size, gfp); |
| 13437 | if (!msg) |
| 13438 | return; |
| 13439 | |
| 13440 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 13441 | if (!hdr) |
| 13442 | goto free_msg; |
| 13443 | |
| 13444 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13445 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13446 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13447 | goto free_msg; |
| 13448 | |
| 13449 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13450 | wdev->netdev->ifindex)) |
| 13451 | goto free_msg; |
| 13452 | |
| 13453 | if (wakeup) { |
| 13454 | struct nlattr *reasons; |
| 13455 | |
| 13456 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 13457 | if (!reasons) |
| 13458 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13459 | |
| 13460 | if (wakeup->disconnect && |
| 13461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 13462 | goto free_msg; |
| 13463 | if (wakeup->magic_pkt && |
| 13464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 13465 | goto free_msg; |
| 13466 | if (wakeup->gtk_rekey_failure && |
| 13467 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 13468 | goto free_msg; |
| 13469 | if (wakeup->eap_identity_req && |
| 13470 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 13471 | goto free_msg; |
| 13472 | if (wakeup->four_way_handshake && |
| 13473 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 13474 | goto free_msg; |
| 13475 | if (wakeup->rfkill_release && |
| 13476 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 13477 | goto free_msg; |
| 13478 | |
| 13479 | if (wakeup->pattern_idx >= 0 && |
| 13480 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 13481 | wakeup->pattern_idx)) |
| 13482 | goto free_msg; |
| 13483 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13484 | if (wakeup->tcp_match && |
| 13485 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 13486 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13487 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13488 | if (wakeup->tcp_connlost && |
| 13489 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 13490 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13491 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13492 | if (wakeup->tcp_nomoretokens && |
| 13493 | nla_put_flag(msg, |
| 13494 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 13495 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 13496 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13497 | if (wakeup->packet) { |
| 13498 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 13499 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 13500 | |
| 13501 | if (!wakeup->packet_80211) { |
| 13502 | pkt_attr = |
| 13503 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 13504 | len_attr = |
| 13505 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 13506 | } |
| 13507 | |
| 13508 | if (wakeup->packet_len && |
| 13509 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 13510 | goto free_msg; |
| 13511 | |
| 13512 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 13513 | wakeup->packet)) |
| 13514 | goto free_msg; |
| 13515 | } |
| 13516 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 13517 | if (wakeup->net_detect && |
| 13518 | cfg80211_net_detect_results(msg, wakeup)) |
| 13519 | goto free_msg; |
| 13520 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13521 | nla_nest_end(msg, reasons); |
| 13522 | } |
| 13523 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13524 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13525 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13526 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13527 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 13528 | return; |
| 13529 | |
| 13530 | free_msg: |
| 13531 | nlmsg_free(msg); |
| 13532 | } |
| 13533 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 13534 | #endif |
| 13535 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13536 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 13537 | enum nl80211_tdls_operation oper, |
| 13538 | u16 reason_code, gfp_t gfp) |
| 13539 | { |
| 13540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13541 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13542 | struct sk_buff *msg; |
| 13543 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13544 | |
| 13545 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 13546 | reason_code); |
| 13547 | |
| 13548 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13549 | if (!msg) |
| 13550 | return; |
| 13551 | |
| 13552 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 13553 | if (!hdr) { |
| 13554 | nlmsg_free(msg); |
| 13555 | return; |
| 13556 | } |
| 13557 | |
| 13558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13559 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13560 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 13561 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 13562 | (reason_code > 0 && |
| 13563 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 13564 | goto nla_put_failure; |
| 13565 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13566 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13567 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13568 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13569 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 13570 | return; |
| 13571 | |
| 13572 | nla_put_failure: |
| 13573 | genlmsg_cancel(msg, hdr); |
| 13574 | nlmsg_free(msg); |
| 13575 | } |
| 13576 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 13577 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13578 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 13579 | unsigned long state, |
| 13580 | void *_notify) |
| 13581 | { |
| 13582 | struct netlink_notify *notify = _notify; |
| 13583 | struct cfg80211_registered_device *rdev; |
| 13584 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13585 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13586 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 13587 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13588 | return NOTIFY_DONE; |
| 13589 | |
| 13590 | rcu_read_lock(); |
| 13591 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13592 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13593 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13594 | bool schedule_scan_stop = false; |
| 13595 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 13596 | rcu_dereference(rdev->sched_scan_req); |
| 13597 | |
| 13598 | if (sched_scan_req && notify->portid && |
| 13599 | sched_scan_req->owner_nlportid == notify->portid) |
| 13600 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13601 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13602 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13603 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13604 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13605 | if (wdev->owner_nlportid == notify->portid) |
| 13606 | schedule_destroy_work = true; |
| 13607 | } |
| 13608 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13609 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13610 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 13611 | list) { |
| 13612 | if (reg->nlportid == notify->portid) { |
| 13613 | list_del(®->list); |
| 13614 | kfree(reg); |
| 13615 | break; |
| 13616 | } |
| 13617 | } |
| 13618 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13619 | |
| 13620 | if (schedule_destroy_work) { |
| 13621 | struct cfg80211_iface_destroy *destroy; |
| 13622 | |
| 13623 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 13624 | if (destroy) { |
| 13625 | destroy->nlportid = notify->portid; |
| 13626 | spin_lock(&rdev->destroy_list_lock); |
| 13627 | list_add(&destroy->list, &rdev->destroy_list); |
| 13628 | spin_unlock(&rdev->destroy_list_lock); |
| 13629 | schedule_work(&rdev->destroy_work); |
| 13630 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 13631 | } else if (schedule_scan_stop) { |
| 13632 | sched_scan_req->owner_nlportid = 0; |
| 13633 | |
| 13634 | if (rdev->ops->sched_scan_stop && |
| 13635 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 13636 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 13637 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13638 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13639 | |
| 13640 | rcu_read_unlock(); |
| 13641 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 13642 | /* |
| 13643 | * It is possible that the user space process that is controlling the |
| 13644 | * indoor setting disappeared, so notify the regulatory core. |
| 13645 | */ |
| 13646 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 13647 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13648 | } |
| 13649 | |
| 13650 | static struct notifier_block nl80211_netlink_notifier = { |
| 13651 | .notifier_call = nl80211_netlink_notify, |
| 13652 | }; |
| 13653 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13654 | void cfg80211_ft_event(struct net_device *netdev, |
| 13655 | struct cfg80211_ft_event_params *ft_event) |
| 13656 | { |
| 13657 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13658 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13659 | struct sk_buff *msg; |
| 13660 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13661 | |
| 13662 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 13663 | |
| 13664 | if (!ft_event->target_ap) |
| 13665 | return; |
| 13666 | |
| 13667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13668 | if (!msg) |
| 13669 | return; |
| 13670 | |
| 13671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13672 | if (!hdr) |
| 13673 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13674 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13675 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13676 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13677 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 13678 | goto out; |
| 13679 | |
| 13680 | if (ft_event->ies && |
| 13681 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 13682 | goto out; |
| 13683 | if (ft_event->ric_ies && |
| 13684 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 13685 | ft_event->ric_ies)) |
| 13686 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13687 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13688 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13689 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13690 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13691 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13692 | return; |
| 13693 | out: |
| 13694 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13695 | } |
| 13696 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 13697 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13698 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 13699 | { |
| 13700 | struct cfg80211_registered_device *rdev; |
| 13701 | struct sk_buff *msg; |
| 13702 | void *hdr; |
| 13703 | u32 nlportid; |
| 13704 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13705 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13706 | if (!rdev->crit_proto_nlportid) |
| 13707 | return; |
| 13708 | |
| 13709 | nlportid = rdev->crit_proto_nlportid; |
| 13710 | rdev->crit_proto_nlportid = 0; |
| 13711 | |
| 13712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13713 | if (!msg) |
| 13714 | return; |
| 13715 | |
| 13716 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 13717 | if (!hdr) |
| 13718 | goto nla_put_failure; |
| 13719 | |
| 13720 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13721 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13722 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13723 | goto nla_put_failure; |
| 13724 | |
| 13725 | genlmsg_end(msg, hdr); |
| 13726 | |
| 13727 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 13728 | return; |
| 13729 | |
| 13730 | nla_put_failure: |
| 13731 | if (hdr) |
| 13732 | genlmsg_cancel(msg, hdr); |
| 13733 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13734 | } |
| 13735 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 13736 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13737 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 13738 | { |
| 13739 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13740 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13741 | struct sk_buff *msg; |
| 13742 | void *hdr; |
| 13743 | |
| 13744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13745 | if (!msg) |
| 13746 | return; |
| 13747 | |
| 13748 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 13749 | if (!hdr) |
| 13750 | goto out; |
| 13751 | |
| 13752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13754 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13755 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 13756 | goto out; |
| 13757 | |
| 13758 | genlmsg_end(msg, hdr); |
| 13759 | |
| 13760 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 13761 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 13762 | return; |
| 13763 | out: |
| 13764 | nlmsg_free(msg); |
| 13765 | } |
| 13766 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13767 | /* initialisation/exit functions */ |
| 13768 | |
| 13769 | int nl80211_init(void) |
| 13770 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 13771 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13772 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13773 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 13774 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13775 | if (err) |
| 13776 | return err; |
| 13777 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13778 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 13779 | if (err) |
| 13780 | goto err_out; |
| 13781 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13782 | return 0; |
| 13783 | err_out: |
| 13784 | genl_unregister_family(&nl80211_fam); |
| 13785 | return err; |
| 13786 | } |
| 13787 | |
| 13788 | void nl80211_exit(void) |
| 13789 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13790 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13791 | genl_unregister_family(&nl80211_fam); |
| 13792 | } |