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, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 59 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 60 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 61 | }; |
| 62 | |
| 63 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 64 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 65 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 66 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 67 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 68 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 69 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 70 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 71 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 72 | #endif |
| 73 | }; |
| 74 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | /* returns ERR_PTR values */ |
| 76 | static struct wireless_dev * |
| 77 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 78 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 79 | struct cfg80211_registered_device *rdev; |
| 80 | struct wireless_dev *result = NULL; |
| 81 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 82 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 83 | u64 wdev_id; |
| 84 | int wiphy_idx = -1; |
| 85 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 87 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | if (!have_ifidx && !have_wdev_id) |
| 90 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 91 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 92 | if (have_ifidx) |
| 93 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 94 | if (have_wdev_id) { |
| 95 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 96 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 99 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 100 | struct wireless_dev *wdev; |
| 101 | |
| 102 | if (wiphy_net(&rdev->wiphy) != netns) |
| 103 | continue; |
| 104 | |
| 105 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 106 | continue; |
| 107 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 108 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 109 | if (have_ifidx && wdev->netdev && |
| 110 | wdev->netdev->ifindex == ifidx) { |
| 111 | result = wdev; |
| 112 | break; |
| 113 | } |
| 114 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 115 | result = wdev; |
| 116 | break; |
| 117 | } |
| 118 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 119 | |
| 120 | if (result) |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | if (result) |
| 125 | return result; |
| 126 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 129 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 130 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 132 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 133 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 134 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 135 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 136 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 137 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 138 | !attrs[NL80211_ATTR_IFINDEX] && |
| 139 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 140 | return ERR_PTR(-EINVAL); |
| 141 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 142 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 143 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 144 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 145 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 146 | if (attrs[NL80211_ATTR_WDEV]) { |
| 147 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 148 | struct wireless_dev *wdev; |
| 149 | bool found = false; |
| 150 | |
| 151 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 152 | if (tmp) { |
| 153 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 154 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 155 | if (wdev->identifier != (u32)wdev_id) |
| 156 | continue; |
| 157 | found = true; |
| 158 | break; |
| 159 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 160 | |
| 161 | if (!found) |
| 162 | tmp = NULL; |
| 163 | |
| 164 | if (rdev && tmp != rdev) |
| 165 | return ERR_PTR(-EINVAL); |
| 166 | rdev = tmp; |
| 167 | } |
| 168 | } |
| 169 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 170 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 171 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 172 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 173 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 174 | if (netdev) { |
| 175 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 176 | tmp = wiphy_to_rdev( |
| 177 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 178 | else |
| 179 | tmp = NULL; |
| 180 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 181 | /* not wireless device -- return error */ |
| 182 | if (!tmp) |
| 183 | return ERR_PTR(-EINVAL); |
| 184 | |
| 185 | /* mismatch -- return error */ |
| 186 | if (rdev && tmp != rdev) |
| 187 | return ERR_PTR(-EINVAL); |
| 188 | |
| 189 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 193 | if (!rdev) |
| 194 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 196 | if (netns != wiphy_net(&rdev->wiphy)) |
| 197 | return ERR_PTR(-ENODEV); |
| 198 | |
| 199 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* |
| 203 | * This function returns a pointer to the driver |
| 204 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 205 | * |
| 206 | * The result of this can be a PTR_ERR and hence must |
| 207 | * be checked with IS_ERR() for errors. |
| 208 | */ |
| 209 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 210 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 211 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 212 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 215 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 216 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 217 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 218 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 219 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 220 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 221 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 222 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 223 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 224 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 225 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 226 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 227 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 229 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 230 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 231 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 233 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 234 | |
| 235 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 236 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 237 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 238 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 240 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 241 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 242 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 243 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 244 | .len = WLAN_MAX_KEY_LEN }, |
| 245 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 246 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 247 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 248 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 249 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 250 | |
| 251 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 252 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 253 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 254 | .len = IEEE80211_MAX_DATA_LEN }, |
| 255 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 256 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 258 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 259 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 260 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 261 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 264 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 265 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 266 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 268 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 269 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 270 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 271 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 273 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 274 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 275 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 276 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 277 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 278 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 279 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 280 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 281 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 283 | |
| 284 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 285 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 286 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 287 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 288 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 289 | |
| 290 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 291 | .len = IEEE80211_MAX_SSID_LEN }, |
| 292 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 293 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_STA_FLAGS2] = { |
| 298 | .len = sizeof(struct nl80211_sta_flag_update), |
| 299 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 300 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 301 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 302 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 304 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 305 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 307 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 308 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 309 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 310 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 311 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 314 | .len = IEEE80211_MAX_DATA_LEN }, |
| 315 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 316 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 318 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 319 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 320 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 321 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 323 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 324 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 325 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 326 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 327 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 329 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 331 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 333 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
| 336 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 337 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 338 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 339 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 340 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 341 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 342 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 343 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 344 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 347 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 349 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 350 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 351 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 352 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 353 | .len = NL80211_HT_CAPABILITY_LEN |
| 354 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 355 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 356 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 357 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 358 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 359 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 360 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 361 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 362 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 363 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 364 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 365 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 366 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 367 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 368 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 369 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 370 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 371 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 372 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 373 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 375 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 376 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 377 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 379 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 380 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 381 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 382 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 383 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 384 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 385 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 386 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 387 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 388 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 389 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 390 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 391 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 392 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 393 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 394 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 395 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 396 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 398 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 399 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 400 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 401 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 402 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 403 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 404 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 405 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 406 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 407 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 408 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 409 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 410 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 411 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 412 | }, |
| 413 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 414 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
| 415 | [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 416 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Vamsi Krishna | 4581639 | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 417 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 418 | }; |
| 419 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 420 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 421 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 422 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 423 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 424 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 425 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 426 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 427 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 428 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 429 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 430 | }; |
| 431 | |
| 432 | /* policy for the key default flags */ |
| 433 | static const struct nla_policy |
| 434 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 435 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 436 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 437 | }; |
| 438 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 439 | /* policy for WoWLAN attributes */ |
| 440 | static const struct nla_policy |
| 441 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 442 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 443 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 444 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 445 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 446 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 447 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 448 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 449 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 450 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 451 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | static const struct nla_policy |
| 455 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 456 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 457 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 458 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 459 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 460 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 461 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 462 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 463 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 464 | }, |
| 465 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 466 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 467 | }, |
| 468 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 469 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 470 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 471 | }; |
| 472 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 473 | /* policy for coalesce rule attributes */ |
| 474 | static const struct nla_policy |
| 475 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 476 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 477 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 478 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 479 | }; |
| 480 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 481 | /* policy for GTK rekey offload attributes */ |
| 482 | static const struct nla_policy |
| 483 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 484 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 485 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 486 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 487 | }; |
| 488 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 489 | static const struct nla_policy |
| 490 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 491 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 492 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 493 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 494 | }; |
| 495 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 496 | static const struct nla_policy |
| 497 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 498 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 499 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 500 | }; |
| 501 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 502 | static const struct nla_policy |
| 503 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 504 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 505 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 506 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 507 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 508 | }, |
| 509 | }; |
| 510 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 511 | /* policy for NAN function attributes */ |
| 512 | static const struct nla_policy |
| 513 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 514 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
| 515 | [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY, |
| 516 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 517 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 518 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 519 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 520 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 521 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 522 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 523 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 524 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 525 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 526 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 527 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 528 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 529 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 530 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 531 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 532 | }; |
| 533 | |
| 534 | /* policy for Service Response Filter attributes */ |
| 535 | static const struct nla_policy |
| 536 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 537 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 538 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 539 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 540 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 541 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 542 | }; |
| 543 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 544 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 545 | struct netlink_callback *cb, |
| 546 | struct cfg80211_registered_device **rdev, |
| 547 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 548 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 549 | int err; |
| 550 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 551 | if (!cb->args[0]) { |
| 552 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 553 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 554 | nl80211_policy); |
| 555 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 556 | return err; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 557 | |
| 558 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 559 | nl80211_fam.attrbuf); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 560 | if (IS_ERR(*wdev)) |
| 561 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 562 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 563 | /* 0 is the first index - add 1 to parse only once */ |
| 564 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 565 | cb->args[1] = (*wdev)->identifier; |
| 566 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 567 | /* subtract the 1 again here */ |
| 568 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 569 | struct wireless_dev *tmp; |
| 570 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 571 | if (!wiphy) |
| 572 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 573 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 574 | *wdev = NULL; |
| 575 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 576 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 577 | if (tmp->identifier == cb->args[1]) { |
| 578 | *wdev = tmp; |
| 579 | break; |
| 580 | } |
| 581 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 582 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 583 | if (!*wdev) |
| 584 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 587 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 590 | /* IE validation */ |
| 591 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 592 | { |
| 593 | const u8 *pos; |
| 594 | int len; |
| 595 | |
| 596 | if (!attr) |
| 597 | return true; |
| 598 | |
| 599 | pos = nla_data(attr); |
| 600 | len = nla_len(attr); |
| 601 | |
| 602 | while (len) { |
| 603 | u8 elemlen; |
| 604 | |
| 605 | if (len < 2) |
| 606 | return false; |
| 607 | len -= 2; |
| 608 | |
| 609 | elemlen = pos[1]; |
| 610 | if (elemlen > len) |
| 611 | return false; |
| 612 | |
| 613 | len -= elemlen; |
| 614 | pos += 2 + elemlen; |
| 615 | } |
| 616 | |
| 617 | return true; |
| 618 | } |
| 619 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 620 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 621 | 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] | 622 | int flags, u8 cmd) |
| 623 | { |
| 624 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 625 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 626 | } |
| 627 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 628 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 629 | struct ieee80211_channel *chan, |
| 630 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 631 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 632 | /* Some channels must be completely excluded from the |
| 633 | * list to protect old user-space tools from breaking |
| 634 | */ |
| 635 | if (!large && chan->flags & |
| 636 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 637 | return 0; |
| 638 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 639 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 640 | chan->center_freq)) |
| 641 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 642 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 643 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 644 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 645 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 646 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 647 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 648 | goto nla_put_failure; |
| 649 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 650 | goto nla_put_failure; |
| 651 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 652 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 653 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 654 | goto nla_put_failure; |
| 655 | if (large) { |
| 656 | u32 time; |
| 657 | |
| 658 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 659 | |
| 660 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 661 | chan->dfs_state)) |
| 662 | goto nla_put_failure; |
| 663 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 664 | time)) |
| 665 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 666 | if (nla_put_u32(msg, |
| 667 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 668 | chan->dfs_cac_ms)) |
| 669 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 670 | } |
| 671 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 672 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 673 | if (large) { |
| 674 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 675 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 676 | goto nla_put_failure; |
| 677 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 678 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 679 | goto nla_put_failure; |
| 680 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 681 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 682 | goto nla_put_failure; |
| 683 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 684 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 685 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 686 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 687 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 688 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 689 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 690 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 691 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 692 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 693 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 694 | goto nla_put_failure; |
| 695 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 696 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 697 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 698 | } |
| 699 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 700 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 701 | DBM_TO_MBM(chan->max_power))) |
| 702 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 703 | |
| 704 | return 0; |
| 705 | |
| 706 | nla_put_failure: |
| 707 | return -ENOBUFS; |
| 708 | } |
| 709 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 710 | /* netlink command implementations */ |
| 711 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 712 | struct key_parse { |
| 713 | struct key_params p; |
| 714 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 715 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 716 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 717 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 718 | }; |
| 719 | |
| 720 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 721 | { |
| 722 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 723 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 724 | nl80211_key_policy); |
| 725 | if (err) |
| 726 | return err; |
| 727 | |
| 728 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 729 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 730 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 731 | if (k->def) { |
| 732 | k->def_uni = true; |
| 733 | k->def_multi = true; |
| 734 | } |
| 735 | if (k->defmgmt) |
| 736 | k->def_multi = true; |
| 737 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 738 | if (tb[NL80211_KEY_IDX]) |
| 739 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 740 | |
| 741 | if (tb[NL80211_KEY_DATA]) { |
| 742 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 743 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 744 | } |
| 745 | |
| 746 | if (tb[NL80211_KEY_SEQ]) { |
| 747 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 748 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 749 | } |
| 750 | |
| 751 | if (tb[NL80211_KEY_CIPHER]) |
| 752 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 753 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 754 | if (tb[NL80211_KEY_TYPE]) { |
| 755 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 756 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 760 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 761 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 762 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 763 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 764 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 765 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 766 | if (err) |
| 767 | return err; |
| 768 | |
| 769 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 770 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 771 | } |
| 772 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 777 | { |
| 778 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 779 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 780 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 781 | } |
| 782 | |
| 783 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 784 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 785 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 786 | } |
| 787 | |
| 788 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 789 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 790 | |
| 791 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 792 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 793 | |
| 794 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 795 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 796 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 797 | if (k->def) { |
| 798 | k->def_uni = true; |
| 799 | k->def_multi = true; |
| 800 | } |
| 801 | if (k->defmgmt) |
| 802 | k->def_multi = true; |
| 803 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 804 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 805 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 806 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 810 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 811 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 812 | int err = nla_parse_nested( |
| 813 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 814 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 815 | nl80211_key_default_policy); |
| 816 | if (err) |
| 817 | return err; |
| 818 | |
| 819 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 820 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 821 | } |
| 822 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | |
| 826 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 827 | { |
| 828 | int err; |
| 829 | |
| 830 | memset(k, 0, sizeof(*k)); |
| 831 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 832 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 833 | |
| 834 | if (info->attrs[NL80211_ATTR_KEY]) |
| 835 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 836 | else |
| 837 | err = nl80211_parse_key_old(info, k); |
| 838 | |
| 839 | if (err) |
| 840 | return err; |
| 841 | |
| 842 | if (k->def && k->defmgmt) |
| 843 | return -EINVAL; |
| 844 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 845 | if (k->defmgmt) { |
| 846 | if (k->def_uni || !k->def_multi) |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 850 | if (k->idx != -1) { |
| 851 | if (k->defmgmt) { |
| 852 | if (k->idx < 4 || k->idx > 5) |
| 853 | return -EINVAL; |
| 854 | } else if (k->def) { |
| 855 | if (k->idx < 0 || k->idx > 3) |
| 856 | return -EINVAL; |
| 857 | } else { |
| 858 | if (k->idx < 0 || k->idx > 5) |
| 859 | return -EINVAL; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 866 | static struct cfg80211_cached_keys * |
| 867 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 868 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 869 | { |
| 870 | struct key_parse parse; |
| 871 | struct nlattr *key; |
| 872 | struct cfg80211_cached_keys *result; |
| 873 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 874 | bool have_key = false; |
| 875 | |
| 876 | nla_for_each_nested(key, keys, rem) { |
| 877 | have_key = true; |
| 878 | break; |
| 879 | } |
| 880 | |
| 881 | if (!have_key) |
| 882 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 883 | |
| 884 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 885 | if (!result) |
| 886 | return ERR_PTR(-ENOMEM); |
| 887 | |
| 888 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 889 | |
| 890 | nla_for_each_nested(key, keys, rem) { |
| 891 | memset(&parse, 0, sizeof(parse)); |
| 892 | parse.idx = -1; |
| 893 | |
| 894 | err = nl80211_parse_key_new(key, &parse); |
| 895 | if (err) |
| 896 | goto error; |
| 897 | err = -EINVAL; |
| 898 | if (!parse.p.key) |
| 899 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 900 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 901 | goto error; |
| 902 | if (parse.def) { |
| 903 | if (def) |
| 904 | goto error; |
| 905 | def = 1; |
| 906 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 907 | if (!parse.def_uni || !parse.def_multi) |
| 908 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 909 | } else if (parse.defmgmt) |
| 910 | goto error; |
| 911 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 912 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 913 | if (err) |
| 914 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 915 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 916 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 917 | err = -EINVAL; |
| 918 | goto error; |
| 919 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 920 | result->params[parse.idx].cipher = parse.p.cipher; |
| 921 | result->params[parse.idx].key_len = parse.p.key_len; |
| 922 | result->params[parse.idx].key = result->data[parse.idx]; |
| 923 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 924 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 925 | /* must be WEP key if we got here */ |
| 926 | if (no_ht) |
| 927 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 930 | if (result->def < 0) { |
| 931 | err = -EINVAL; |
| 932 | goto error; |
| 933 | } |
| 934 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 935 | return result; |
| 936 | error: |
| 937 | kfree(result); |
| 938 | return ERR_PTR(err); |
| 939 | } |
| 940 | |
| 941 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 942 | { |
| 943 | ASSERT_WDEV_LOCK(wdev); |
| 944 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 945 | switch (wdev->iftype) { |
| 946 | case NL80211_IFTYPE_AP: |
| 947 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 948 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 949 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 950 | break; |
| 951 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 952 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 953 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 954 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 955 | return -ENOLINK; |
| 956 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 957 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 958 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 959 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 960 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 961 | case NL80211_IFTYPE_P2P_DEVICE: |
| 962 | case NL80211_IFTYPE_WDS: |
| 963 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 964 | return -EINVAL; |
| 965 | } |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 970 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 971 | struct nlattr *tb) |
| 972 | { |
| 973 | struct ieee80211_channel *chan; |
| 974 | |
| 975 | if (tb == NULL) |
| 976 | return NULL; |
| 977 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 978 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 979 | return NULL; |
| 980 | return chan; |
| 981 | } |
| 982 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 983 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 984 | { |
| 985 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 986 | int i; |
| 987 | |
| 988 | if (!nl_modes) |
| 989 | goto nla_put_failure; |
| 990 | |
| 991 | i = 0; |
| 992 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 993 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 994 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 995 | ifmodes >>= 1; |
| 996 | i++; |
| 997 | } |
| 998 | |
| 999 | nla_nest_end(msg, nl_modes); |
| 1000 | return 0; |
| 1001 | |
| 1002 | nla_put_failure: |
| 1003 | return -ENOBUFS; |
| 1004 | } |
| 1005 | |
| 1006 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1007 | struct sk_buff *msg, |
| 1008 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1009 | { |
| 1010 | struct nlattr *nl_combis; |
| 1011 | int i, j; |
| 1012 | |
| 1013 | nl_combis = nla_nest_start(msg, |
| 1014 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1015 | if (!nl_combis) |
| 1016 | goto nla_put_failure; |
| 1017 | |
| 1018 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1019 | const struct ieee80211_iface_combination *c; |
| 1020 | struct nlattr *nl_combi, *nl_limits; |
| 1021 | |
| 1022 | c = &wiphy->iface_combinations[i]; |
| 1023 | |
| 1024 | nl_combi = nla_nest_start(msg, i + 1); |
| 1025 | if (!nl_combi) |
| 1026 | goto nla_put_failure; |
| 1027 | |
| 1028 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1029 | if (!nl_limits) |
| 1030 | goto nla_put_failure; |
| 1031 | |
| 1032 | for (j = 0; j < c->n_limits; j++) { |
| 1033 | struct nlattr *nl_limit; |
| 1034 | |
| 1035 | nl_limit = nla_nest_start(msg, j + 1); |
| 1036 | if (!nl_limit) |
| 1037 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1038 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1039 | c->limits[j].max)) |
| 1040 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1041 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1042 | c->limits[j].types)) |
| 1043 | goto nla_put_failure; |
| 1044 | nla_nest_end(msg, nl_limit); |
| 1045 | } |
| 1046 | |
| 1047 | nla_nest_end(msg, nl_limits); |
| 1048 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1049 | if (c->beacon_int_infra_match && |
| 1050 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1051 | goto nla_put_failure; |
| 1052 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1053 | c->num_different_channels) || |
| 1054 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1055 | c->max_interfaces)) |
| 1056 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1057 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1058 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1059 | c->radar_detect_widths) || |
| 1060 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1061 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1062 | goto nla_put_failure; |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1063 | if (c->beacon_int_min_gcd && |
| 1064 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1065 | c->beacon_int_min_gcd)) |
| 1066 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1067 | |
| 1068 | nla_nest_end(msg, nl_combi); |
| 1069 | } |
| 1070 | |
| 1071 | nla_nest_end(msg, nl_combis); |
| 1072 | |
| 1073 | return 0; |
| 1074 | nla_put_failure: |
| 1075 | return -ENOBUFS; |
| 1076 | } |
| 1077 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1078 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1079 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1080 | struct sk_buff *msg) |
| 1081 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1082 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1083 | struct nlattr *nl_tcp; |
| 1084 | |
| 1085 | if (!tcp) |
| 1086 | return 0; |
| 1087 | |
| 1088 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1089 | if (!nl_tcp) |
| 1090 | return -ENOBUFS; |
| 1091 | |
| 1092 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1093 | tcp->data_payload_max)) |
| 1094 | return -ENOBUFS; |
| 1095 | |
| 1096 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1097 | tcp->data_payload_max)) |
| 1098 | return -ENOBUFS; |
| 1099 | |
| 1100 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1101 | return -ENOBUFS; |
| 1102 | |
| 1103 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1104 | sizeof(*tcp->tok), tcp->tok)) |
| 1105 | return -ENOBUFS; |
| 1106 | |
| 1107 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1108 | tcp->data_interval_max)) |
| 1109 | return -ENOBUFS; |
| 1110 | |
| 1111 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1112 | tcp->wake_payload_max)) |
| 1113 | return -ENOBUFS; |
| 1114 | |
| 1115 | nla_nest_end(msg, nl_tcp); |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1119 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1120 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1121 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1122 | { |
| 1123 | struct nlattr *nl_wowlan; |
| 1124 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1125 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1126 | return 0; |
| 1127 | |
| 1128 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1129 | if (!nl_wowlan) |
| 1130 | return -ENOBUFS; |
| 1131 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1132 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1133 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1134 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1135 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1136 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1137 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1138 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1139 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1140 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1141 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1142 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1143 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1144 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1145 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1146 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1147 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1148 | return -ENOBUFS; |
| 1149 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1150 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1151 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1152 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1153 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1154 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1155 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1156 | }; |
| 1157 | |
| 1158 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1159 | sizeof(pat), &pat)) |
| 1160 | return -ENOBUFS; |
| 1161 | } |
| 1162 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1163 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1164 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1165 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1166 | return -ENOBUFS; |
| 1167 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1168 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1169 | return -ENOBUFS; |
| 1170 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1171 | nla_nest_end(msg, nl_wowlan); |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | #endif |
| 1176 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1177 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1178 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1179 | { |
| 1180 | struct nl80211_coalesce_rule_support rule; |
| 1181 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1182 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1183 | return 0; |
| 1184 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1185 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1186 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1187 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1188 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1189 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1190 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1191 | |
| 1192 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1193 | return -ENOBUFS; |
| 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1198 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1199 | struct ieee80211_supported_band *sband) |
| 1200 | { |
| 1201 | struct nlattr *nl_rates, *nl_rate; |
| 1202 | struct ieee80211_rate *rate; |
| 1203 | int i; |
| 1204 | |
| 1205 | /* add HT info */ |
| 1206 | if (sband->ht_cap.ht_supported && |
| 1207 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1208 | sizeof(sband->ht_cap.mcs), |
| 1209 | &sband->ht_cap.mcs) || |
| 1210 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1211 | sband->ht_cap.cap) || |
| 1212 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1213 | sband->ht_cap.ampdu_factor) || |
| 1214 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1215 | sband->ht_cap.ampdu_density))) |
| 1216 | return -ENOBUFS; |
| 1217 | |
| 1218 | /* add VHT info */ |
| 1219 | if (sband->vht_cap.vht_supported && |
| 1220 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1221 | sizeof(sband->vht_cap.vht_mcs), |
| 1222 | &sband->vht_cap.vht_mcs) || |
| 1223 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1224 | sband->vht_cap.cap))) |
| 1225 | return -ENOBUFS; |
| 1226 | |
| 1227 | /* add bitrates */ |
| 1228 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1229 | if (!nl_rates) |
| 1230 | return -ENOBUFS; |
| 1231 | |
| 1232 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1233 | nl_rate = nla_nest_start(msg, i); |
| 1234 | if (!nl_rate) |
| 1235 | return -ENOBUFS; |
| 1236 | |
| 1237 | rate = &sband->bitrates[i]; |
| 1238 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1239 | rate->bitrate)) |
| 1240 | return -ENOBUFS; |
| 1241 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1242 | nla_put_flag(msg, |
| 1243 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1244 | return -ENOBUFS; |
| 1245 | |
| 1246 | nla_nest_end(msg, nl_rate); |
| 1247 | } |
| 1248 | |
| 1249 | nla_nest_end(msg, nl_rates); |
| 1250 | |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | static int |
| 1255 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1256 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1257 | { |
| 1258 | u16 stypes; |
| 1259 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1260 | enum nl80211_iftype ift; |
| 1261 | int i; |
| 1262 | |
| 1263 | if (!mgmt_stypes) |
| 1264 | return 0; |
| 1265 | |
| 1266 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1267 | if (!nl_ifs) |
| 1268 | return -ENOBUFS; |
| 1269 | |
| 1270 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1271 | nl_ftypes = nla_nest_start(msg, ift); |
| 1272 | if (!nl_ftypes) |
| 1273 | return -ENOBUFS; |
| 1274 | i = 0; |
| 1275 | stypes = mgmt_stypes[ift].tx; |
| 1276 | while (stypes) { |
| 1277 | if ((stypes & 1) && |
| 1278 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1279 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1280 | return -ENOBUFS; |
| 1281 | stypes >>= 1; |
| 1282 | i++; |
| 1283 | } |
| 1284 | nla_nest_end(msg, nl_ftypes); |
| 1285 | } |
| 1286 | |
| 1287 | nla_nest_end(msg, nl_ifs); |
| 1288 | |
| 1289 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1290 | if (!nl_ifs) |
| 1291 | return -ENOBUFS; |
| 1292 | |
| 1293 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1294 | nl_ftypes = nla_nest_start(msg, ift); |
| 1295 | if (!nl_ftypes) |
| 1296 | return -ENOBUFS; |
| 1297 | i = 0; |
| 1298 | stypes = mgmt_stypes[ift].rx; |
| 1299 | while (stypes) { |
| 1300 | if ((stypes & 1) && |
| 1301 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1302 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1303 | return -ENOBUFS; |
| 1304 | stypes >>= 1; |
| 1305 | i++; |
| 1306 | } |
| 1307 | nla_nest_end(msg, nl_ftypes); |
| 1308 | } |
| 1309 | nla_nest_end(msg, nl_ifs); |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1314 | struct nl80211_dump_wiphy_state { |
| 1315 | s64 filter_wiphy; |
| 1316 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1317 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1318 | bool split; |
| 1319 | }; |
| 1320 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1322 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1324 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1325 | { |
| 1326 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1327 | struct nlattr *nl_bands, *nl_band; |
| 1328 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1329 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1330 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1331 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1332 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1333 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1335 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1336 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1337 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1338 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | return -ENOBUFS; |
| 1340 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1341 | if (WARN_ON(!state)) |
| 1342 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1343 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1347 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1348 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1349 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1350 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1351 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1352 | goto finish; |
| 1353 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1354 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | case 0: |
| 1356 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1357 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1359 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1361 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1363 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1365 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1366 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1367 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1369 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1373 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1375 | rdev->wiphy.max_match_sets) || |
| 1376 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1377 | rdev->wiphy.max_sched_scan_plans) || |
| 1378 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1379 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1380 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1381 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1382 | goto nla_put_failure; |
| 1383 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1384 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1385 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1386 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1387 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1388 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1389 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1390 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1391 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1392 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1393 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1394 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1395 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1396 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1397 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1398 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1399 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1400 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1401 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1402 | state->split_start++; |
| 1403 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1404 | break; |
| 1405 | case 1: |
| 1406 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1407 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1408 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1409 | goto nla_put_failure; |
| 1410 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1411 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1412 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1413 | goto nla_put_failure; |
| 1414 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1415 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1416 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1417 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1418 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1420 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1422 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1423 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1424 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1425 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1427 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1429 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1430 | if ((rdev->wiphy.available_antennas_tx || |
| 1431 | rdev->wiphy.available_antennas_rx) && |
| 1432 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | u32 tx_ant = 0, rx_ant = 0; |
| 1434 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1435 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1436 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | if (!res) { |
| 1438 | if (nla_put_u32(msg, |
| 1439 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1440 | tx_ant) || |
| 1441 | nla_put_u32(msg, |
| 1442 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1443 | rx_ant)) |
| 1444 | goto nla_put_failure; |
| 1445 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1448 | state->split_start++; |
| 1449 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | break; |
| 1451 | case 2: |
| 1452 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1453 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1454 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1455 | state->split_start++; |
| 1456 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | break; |
| 1458 | case 3: |
| 1459 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1460 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1461 | goto nla_put_failure; |
| 1462 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1463 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1464 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1465 | struct ieee80211_supported_band *sband; |
| 1466 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1467 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | |
| 1469 | if (!sband) |
| 1470 | continue; |
| 1471 | |
| 1472 | nl_band = nla_nest_start(msg, band); |
| 1473 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1474 | goto nla_put_failure; |
| 1475 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1476 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | case 0: |
| 1478 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1479 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1480 | state->chan_start++; |
| 1481 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | break; |
| 1483 | default: |
| 1484 | /* add frequencies */ |
| 1485 | nl_freqs = nla_nest_start( |
| 1486 | msg, NL80211_BAND_ATTR_FREQS); |
| 1487 | if (!nl_freqs) |
| 1488 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1489 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1490 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | i < sband->n_channels; |
| 1492 | i++) { |
| 1493 | nl_freq = nla_nest_start(msg, i); |
| 1494 | if (!nl_freq) |
| 1495 | goto nla_put_failure; |
| 1496 | |
| 1497 | chan = &sband->channels[i]; |
| 1498 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1499 | if (nl80211_msg_put_channel( |
| 1500 | msg, chan, |
| 1501 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | goto nla_put_failure; |
| 1503 | |
| 1504 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1505 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1509 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1511 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | nla_nest_end(msg, nl_freqs); |
| 1513 | } |
| 1514 | |
| 1515 | nla_nest_end(msg, nl_band); |
| 1516 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1517 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1519 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1520 | band--; |
| 1521 | break; |
| 1522 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1523 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1525 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1526 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1527 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1529 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1530 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1532 | if (state->band_start == 0 && state->chan_start == 0) |
| 1533 | state->split_start++; |
| 1534 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | break; |
| 1536 | case 4: |
| 1537 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1538 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1539 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1540 | |
| 1541 | i = 0; |
| 1542 | #define CMD(op, n) \ |
| 1543 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1544 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | i++; \ |
| 1546 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1547 | goto nla_put_failure; \ |
| 1548 | } \ |
| 1549 | } while (0) |
| 1550 | |
| 1551 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1552 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1553 | CMD(add_key, NEW_KEY); |
| 1554 | CMD(start_ap, START_AP); |
| 1555 | CMD(add_station, NEW_STATION); |
| 1556 | CMD(add_mpath, NEW_MPATH); |
| 1557 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1558 | CMD(change_bss, SET_BSS); |
| 1559 | CMD(auth, AUTHENTICATE); |
| 1560 | CMD(assoc, ASSOCIATE); |
| 1561 | CMD(deauth, DEAUTHENTICATE); |
| 1562 | CMD(disassoc, DISASSOCIATE); |
| 1563 | CMD(join_ibss, JOIN_IBSS); |
| 1564 | CMD(join_mesh, JOIN_MESH); |
| 1565 | CMD(set_pmksa, SET_PMKSA); |
| 1566 | CMD(del_pmksa, DEL_PMKSA); |
| 1567 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1568 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1570 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1571 | CMD(mgmt_tx, FRAME); |
| 1572 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1573 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1574 | i++; |
| 1575 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1576 | goto nla_put_failure; |
| 1577 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1579 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | i++; |
| 1581 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1582 | goto nla_put_failure; |
| 1583 | } |
| 1584 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1586 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1587 | CMD(tdls_oper, TDLS_OPER); |
| 1588 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1591 | CMD(probe_client, PROBE_CLIENT); |
| 1592 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | i++; |
| 1595 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1596 | goto nla_put_failure; |
| 1597 | } |
| 1598 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1599 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1600 | #ifdef CONFIG_NL80211_TESTMODE |
| 1601 | CMD(testmode_cmd, TESTMODE); |
| 1602 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1603 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1604 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1605 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1606 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1607 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1608 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1609 | if (rdev->wiphy.features & |
| 1610 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1611 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1612 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1613 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1614 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1615 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1616 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1617 | i++; |
| 1618 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1619 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1622 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | i++; |
| 1624 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1625 | goto nla_put_failure; |
| 1626 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1627 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1628 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1629 | state->split_start++; |
| 1630 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1631 | break; |
| 1632 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | if (rdev->ops->remain_on_channel && |
| 1634 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1635 | nla_put_u32(msg, |
| 1636 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1637 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1638 | goto nla_put_failure; |
| 1639 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1640 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1641 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1642 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1643 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1644 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1645 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1646 | state->split_start++; |
| 1647 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1648 | break; |
| 1649 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1650 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1651 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1653 | state->split_start++; |
| 1654 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1655 | break; |
| 1656 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1657 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | #endif |
| 1659 | case 7: |
| 1660 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1661 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1662 | goto nla_put_failure; |
| 1663 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1664 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1665 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1667 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1668 | state->split_start++; |
| 1669 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1670 | break; |
| 1671 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1672 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1673 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1674 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1675 | goto nla_put_failure; |
| 1676 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1677 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1678 | /* |
| 1679 | * We can only add the per-channel limit information if the |
| 1680 | * dump is split, otherwise it makes it too big. Therefore |
| 1681 | * only advertise it in that case. |
| 1682 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1683 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1684 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1685 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1686 | goto nla_put_failure; |
| 1687 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1688 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1689 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1691 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1692 | goto nla_put_failure; |
| 1693 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1694 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1695 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1696 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1697 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1698 | goto nla_put_failure; |
| 1699 | |
| 1700 | /* |
| 1701 | * Any information below this point is only available to |
| 1702 | * applications that can deal with it being split. This |
| 1703 | * helps ensure that newly added capabilities don't break |
| 1704 | * older tools by overrunning their buffers. |
| 1705 | * |
| 1706 | * We still increment split_start so that in the split |
| 1707 | * case we'll continue with more data in the next round, |
| 1708 | * but break unconditionally so unsplit data stops here. |
| 1709 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1710 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1711 | break; |
| 1712 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1713 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1714 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1715 | rdev->wiphy.extended_capabilities_len, |
| 1716 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1717 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1718 | rdev->wiphy.extended_capabilities_len, |
| 1719 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1720 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1721 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1722 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1723 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1724 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1725 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1726 | goto nla_put_failure; |
| 1727 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1728 | state->split_start++; |
| 1729 | break; |
| 1730 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1731 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1732 | goto nla_put_failure; |
| 1733 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1734 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1735 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1736 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1737 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1738 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1739 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1740 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1741 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1742 | goto nla_put_failure; |
| 1743 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1744 | state->split_start++; |
| 1745 | break; |
| 1746 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1747 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1748 | const struct nl80211_vendor_cmd_info *info; |
| 1749 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1750 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1751 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1752 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1753 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1754 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1755 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1756 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1757 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1758 | goto nla_put_failure; |
| 1759 | } |
| 1760 | nla_nest_end(msg, nested); |
| 1761 | } |
| 1762 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1763 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1764 | const struct nl80211_vendor_cmd_info *info; |
| 1765 | struct nlattr *nested; |
| 1766 | |
| 1767 | nested = nla_nest_start(msg, |
| 1768 | NL80211_ATTR_VENDOR_EVENTS); |
| 1769 | if (!nested) |
| 1770 | goto nla_put_failure; |
| 1771 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1772 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1773 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1774 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1775 | goto nla_put_failure; |
| 1776 | } |
| 1777 | nla_nest_end(msg, nested); |
| 1778 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1779 | state->split_start++; |
| 1780 | break; |
| 1781 | case 12: |
| 1782 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1783 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1784 | rdev->wiphy.max_num_csa_counters)) |
| 1785 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1786 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1787 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1788 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1789 | goto nla_put_failure; |
| 1790 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1791 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1792 | sizeof(rdev->wiphy.ext_features), |
| 1793 | rdev->wiphy.ext_features)) |
| 1794 | goto nla_put_failure; |
| 1795 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1796 | if (rdev->wiphy.bss_select_support) { |
| 1797 | struct nlattr *nested; |
| 1798 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1799 | |
| 1800 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1801 | if (!nested) |
| 1802 | goto nla_put_failure; |
| 1803 | |
| 1804 | i = 0; |
| 1805 | while (bss_select_support) { |
| 1806 | if ((bss_select_support & 1) && |
| 1807 | nla_put_flag(msg, i)) |
| 1808 | goto nla_put_failure; |
| 1809 | i++; |
| 1810 | bss_select_support >>= 1; |
| 1811 | } |
| 1812 | nla_nest_end(msg, nested); |
| 1813 | } |
| 1814 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1815 | state->split_start++; |
| 1816 | break; |
| 1817 | case 13: |
| 1818 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1819 | rdev->wiphy.iftype_ext_capab) { |
| 1820 | struct nlattr *nested_ext_capab, *nested; |
| 1821 | |
| 1822 | nested = nla_nest_start(msg, |
| 1823 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1824 | if (!nested) |
| 1825 | goto nla_put_failure; |
| 1826 | |
| 1827 | for (i = state->capa_start; |
| 1828 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1829 | const struct wiphy_iftype_ext_capab *capab; |
| 1830 | |
| 1831 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1832 | |
| 1833 | nested_ext_capab = nla_nest_start(msg, i); |
| 1834 | if (!nested_ext_capab || |
| 1835 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1836 | capab->iftype) || |
| 1837 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1838 | capab->extended_capabilities_len, |
| 1839 | capab->extended_capabilities) || |
| 1840 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1841 | capab->extended_capabilities_len, |
| 1842 | capab->extended_capabilities_mask)) |
| 1843 | goto nla_put_failure; |
| 1844 | |
| 1845 | nla_nest_end(msg, nested_ext_capab); |
| 1846 | if (state->split) |
| 1847 | break; |
| 1848 | } |
| 1849 | nla_nest_end(msg, nested); |
| 1850 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1851 | state->capa_start = i + 1; |
| 1852 | break; |
| 1853 | } |
| 1854 | } |
| 1855 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1856 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1857 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1858 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1859 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1860 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1861 | genlmsg_end(msg, hdr); |
| 1862 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | |
| 1864 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1865 | genlmsg_cancel(msg, hdr); |
| 1866 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1867 | } |
| 1868 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1869 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1870 | struct netlink_callback *cb, |
| 1871 | struct nl80211_dump_wiphy_state *state) |
| 1872 | { |
| 1873 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1874 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1875 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1876 | /* ignore parse errors for backward compatibility */ |
| 1877 | if (ret) |
| 1878 | return 0; |
| 1879 | |
| 1880 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1881 | if (tb[NL80211_ATTR_WIPHY]) |
| 1882 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1883 | if (tb[NL80211_ATTR_WDEV]) |
| 1884 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1885 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1886 | struct net_device *netdev; |
| 1887 | struct cfg80211_registered_device *rdev; |
| 1888 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1889 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1890 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1891 | if (!netdev) |
| 1892 | return -ENODEV; |
| 1893 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1894 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1895 | netdev->ieee80211_ptr->wiphy); |
| 1896 | state->filter_wiphy = rdev->wiphy_idx; |
| 1897 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | return 0; |
| 1901 | } |
| 1902 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1903 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1904 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1905 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1906 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1907 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1908 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1909 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1910 | if (!state) { |
| 1911 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1912 | if (!state) { |
| 1913 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1914 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1915 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1916 | state->filter_wiphy = -1; |
| 1917 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1918 | if (ret) { |
| 1919 | kfree(state); |
| 1920 | rtnl_unlock(); |
| 1921 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1922 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1923 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1924 | } |
| 1925 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1926 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1927 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1928 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1929 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1930 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1931 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1932 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1933 | continue; |
| 1934 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1935 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1936 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1937 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1938 | NETLINK_CB(cb->skb).portid, |
| 1939 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1940 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1941 | if (ret < 0) { |
| 1942 | /* |
| 1943 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1944 | * or EMSGSIZE returned), this SKB is still |
| 1945 | * empty (so it's not too big because another |
| 1946 | * wiphy dataset is already in the skb) and |
| 1947 | * we've not tried to adjust the dump allocation |
| 1948 | * yet ... then adjust the alloc size to be |
| 1949 | * bigger, and return 1 but with the empty skb. |
| 1950 | * This results in an empty message being RX'ed |
| 1951 | * in userspace, but that is ignored. |
| 1952 | * |
| 1953 | * We can then retry with the larger buffer. |
| 1954 | */ |
| 1955 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1956 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1957 | cb->min_dump_alloc < 4096) { |
| 1958 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1959 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1960 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1961 | return 1; |
| 1962 | } |
| 1963 | idx--; |
| 1964 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1965 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1966 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1967 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1968 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1969 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1970 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1971 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1972 | |
| 1973 | return skb->len; |
| 1974 | } |
| 1975 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1976 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1977 | { |
| 1978 | kfree((void *)cb->args[0]); |
| 1979 | return 0; |
| 1980 | } |
| 1981 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1982 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1983 | { |
| 1984 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1986 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1987 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1988 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1989 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1990 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1991 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1992 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1993 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1994 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1995 | nlmsg_free(msg); |
| 1996 | return -ENOBUFS; |
| 1997 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1998 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1999 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2002 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2003 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2004 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2005 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2006 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2007 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2008 | }; |
| 2009 | |
| 2010 | static int parse_txq_params(struct nlattr *tb[], |
| 2011 | struct ieee80211_txq_params *txq_params) |
| 2012 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2013 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2014 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2015 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2016 | return -EINVAL; |
| 2017 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2018 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2019 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2020 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2021 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2022 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2023 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2024 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 2025 | return -EINVAL; |
| 2026 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2027 | return 0; |
| 2028 | } |
| 2029 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2030 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2031 | { |
| 2032 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2033 | * You can only set the channel explicitly for WDS interfaces, |
| 2034 | * all others have their channel managed via their respective |
| 2035 | * "establish a connection" command (connect, join, ...) |
| 2036 | * |
| 2037 | * For AP/GO and mesh mode, the channel can be set with the |
| 2038 | * channel userspace API, but is only stored and passed to the |
| 2039 | * low-level driver when the AP starts or the mesh is joined. |
| 2040 | * This is for backward compatibility, userspace can also give |
| 2041 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2042 | * |
| 2043 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2044 | * whatever else is going on, so they have their own special |
| 2045 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2046 | */ |
| 2047 | return !wdev || |
| 2048 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2049 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2050 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2051 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2052 | } |
| 2053 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2054 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2055 | struct genl_info *info, |
| 2056 | struct cfg80211_chan_def *chandef) |
| 2057 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2058 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2059 | |
| 2060 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2061 | return -EINVAL; |
| 2062 | |
| 2063 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2064 | |
| 2065 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2066 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2067 | chandef->center_freq1 = control_freq; |
| 2068 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2069 | |
| 2070 | /* Primary channel not allowed */ |
| 2071 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2072 | return -EINVAL; |
| 2073 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2074 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2075 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2076 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2077 | chantype = nla_get_u32( |
| 2078 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2079 | |
| 2080 | switch (chantype) { |
| 2081 | case NL80211_CHAN_NO_HT: |
| 2082 | case NL80211_CHAN_HT20: |
| 2083 | case NL80211_CHAN_HT40PLUS: |
| 2084 | case NL80211_CHAN_HT40MINUS: |
| 2085 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2086 | chantype); |
| 2087 | break; |
| 2088 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2089 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2090 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2091 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2092 | chandef->width = |
| 2093 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2094 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2095 | chandef->center_freq1 = |
| 2096 | nla_get_u32( |
| 2097 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2098 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2099 | chandef->center_freq2 = |
| 2100 | nla_get_u32( |
| 2101 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2102 | } |
| 2103 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2104 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2105 | return -EINVAL; |
| 2106 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2107 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2108 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2109 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2110 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2111 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2112 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2113 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2114 | return -EINVAL; |
| 2115 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2116 | return 0; |
| 2117 | } |
| 2118 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2119 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2120 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2121 | struct genl_info *info) |
| 2122 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2123 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2124 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2125 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2126 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2127 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2128 | if (dev) |
| 2129 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2130 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2131 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2132 | if (wdev) |
| 2133 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2134 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2135 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2136 | if (result) |
| 2137 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2138 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2139 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2140 | case NL80211_IFTYPE_AP: |
| 2141 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2142 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2143 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2144 | result = -EINVAL; |
| 2145 | break; |
| 2146 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2147 | if (wdev->beacon_interval) { |
| 2148 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2149 | !(rdev->wiphy.features & |
| 2150 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2151 | result = -EBUSY; |
| 2152 | break; |
| 2153 | } |
| 2154 | |
| 2155 | /* Only allow dynamic channel width changes */ |
| 2156 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2157 | result = -EBUSY; |
| 2158 | break; |
| 2159 | } |
| 2160 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2161 | if (result) |
| 2162 | break; |
| 2163 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2164 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2165 | result = 0; |
| 2166 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2167 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2168 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2169 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2170 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2171 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2172 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2173 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2174 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2175 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2176 | |
| 2177 | return result; |
| 2178 | } |
| 2179 | |
| 2180 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2183 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2184 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2185 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2188 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2189 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2191 | struct net_device *dev = info->user_ptr[1]; |
| 2192 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2193 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2194 | |
| 2195 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2196 | return -EINVAL; |
| 2197 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2198 | if (netif_running(dev)) |
| 2199 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2200 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2201 | if (!rdev->ops->set_wds_peer) |
| 2202 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2203 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2204 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2205 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2206 | |
| 2207 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2208 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2209 | } |
| 2210 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2211 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2212 | { |
| 2213 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2214 | struct net_device *netdev = NULL; |
| 2215 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2216 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2217 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2218 | u32 changed; |
| 2219 | u8 retry_short = 0, retry_long = 0; |
| 2220 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2221 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2223 | ASSERT_RTNL(); |
| 2224 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2225 | /* |
| 2226 | * Try to find the wiphy and netdev. Normally this |
| 2227 | * function shouldn't need the netdev, but this is |
| 2228 | * done for backward compatibility -- previously |
| 2229 | * setting the channel was done per wiphy, but now |
| 2230 | * it is per netdev. Previous userland like hostapd |
| 2231 | * also passed a netdev to set_wiphy, so that it is |
| 2232 | * possible to let that go to the right netdev! |
| 2233 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2234 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2235 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2236 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2237 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2238 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2239 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2240 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2241 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2242 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2243 | } |
| 2244 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2245 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2246 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2247 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2248 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2249 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2250 | wdev = NULL; |
| 2251 | netdev = NULL; |
| 2252 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2253 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2254 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2255 | |
| 2256 | /* |
| 2257 | * end workaround code, by now the rdev is available |
| 2258 | * and locked, and wdev may or may not be NULL. |
| 2259 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2260 | |
| 2261 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2262 | result = cfg80211_dev_rename( |
| 2263 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2264 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2265 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2266 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2267 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2268 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2269 | struct ieee80211_txq_params txq_params; |
| 2270 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2271 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2272 | if (!rdev->ops->set_txq_params) |
| 2273 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2274 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2275 | if (!netdev) |
| 2276 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2277 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2278 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2279 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2280 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2281 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2282 | if (!netif_running(netdev)) |
| 2283 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2284 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2285 | nla_for_each_nested(nl_txq_params, |
| 2286 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2287 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2288 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2289 | nla_data(nl_txq_params), |
| 2290 | nla_len(nl_txq_params), |
| 2291 | txq_params_policy); |
| 2292 | if (result) |
| 2293 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2294 | result = parse_txq_params(tb, &txq_params); |
| 2295 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2296 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2297 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2298 | result = rdev_set_txq_params(rdev, netdev, |
| 2299 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2300 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2301 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2302 | } |
| 2303 | } |
| 2304 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2305 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2306 | result = __nl80211_set_channel( |
| 2307 | rdev, |
| 2308 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2309 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2310 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2311 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2312 | } |
| 2313 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2314 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2315 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2316 | enum nl80211_tx_power_setting type; |
| 2317 | int idx, mbm = 0; |
| 2318 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2319 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2320 | txp_wdev = NULL; |
| 2321 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2322 | if (!rdev->ops->set_tx_power) |
| 2323 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2324 | |
| 2325 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2326 | type = nla_get_u32(info->attrs[idx]); |
| 2327 | |
| 2328 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2329 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2330 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2331 | |
| 2332 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2333 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2334 | mbm = nla_get_u32(info->attrs[idx]); |
| 2335 | } |
| 2336 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2337 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2338 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2339 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2340 | } |
| 2341 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2342 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2343 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2344 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2345 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2346 | if ((!rdev->wiphy.available_antennas_tx && |
| 2347 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2348 | !rdev->ops->set_antenna) |
| 2349 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2350 | |
| 2351 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2352 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2353 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2354 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2355 | * available antenna masks, except for the "all" mask */ |
| 2356 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2357 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2358 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2359 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2360 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2361 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2362 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2363 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2364 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2365 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2366 | } |
| 2367 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2368 | changed = 0; |
| 2369 | |
| 2370 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2371 | retry_short = nla_get_u8( |
| 2372 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2373 | if (retry_short == 0) |
| 2374 | return -EINVAL; |
| 2375 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2376 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2377 | } |
| 2378 | |
| 2379 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2380 | retry_long = nla_get_u8( |
| 2381 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2382 | if (retry_long == 0) |
| 2383 | return -EINVAL; |
| 2384 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2385 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2386 | } |
| 2387 | |
| 2388 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2389 | frag_threshold = nla_get_u32( |
| 2390 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2391 | if (frag_threshold < 256) |
| 2392 | return -EINVAL; |
| 2393 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2394 | if (frag_threshold != (u32) -1) { |
| 2395 | /* |
| 2396 | * Fragments (apart from the last one) are required to |
| 2397 | * have even length. Make the fragmentation code |
| 2398 | * simpler by stripping LSB should someone try to use |
| 2399 | * odd threshold value. |
| 2400 | */ |
| 2401 | frag_threshold &= ~0x1; |
| 2402 | } |
| 2403 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2404 | } |
| 2405 | |
| 2406 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2407 | rts_threshold = nla_get_u32( |
| 2408 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2409 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2410 | } |
| 2411 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2412 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2413 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2414 | return -EINVAL; |
| 2415 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2416 | coverage_class = nla_get_u8( |
| 2417 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2418 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2419 | } |
| 2420 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2421 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2422 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2423 | return -EOPNOTSUPP; |
| 2424 | |
| 2425 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2426 | } |
| 2427 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2428 | if (changed) { |
| 2429 | u8 old_retry_short, old_retry_long; |
| 2430 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2431 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2432 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2433 | if (!rdev->ops->set_wiphy_params) |
| 2434 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2435 | |
| 2436 | old_retry_short = rdev->wiphy.retry_short; |
| 2437 | old_retry_long = rdev->wiphy.retry_long; |
| 2438 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2439 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2440 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2441 | |
| 2442 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2443 | rdev->wiphy.retry_short = retry_short; |
| 2444 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2445 | rdev->wiphy.retry_long = retry_long; |
| 2446 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2447 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2448 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2449 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2450 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2451 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2452 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2453 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2454 | if (result) { |
| 2455 | rdev->wiphy.retry_short = old_retry_short; |
| 2456 | rdev->wiphy.retry_long = old_retry_long; |
| 2457 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2458 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2459 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2460 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2461 | } |
| 2462 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2463 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2464 | } |
| 2465 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2466 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2467 | { |
| 2468 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2469 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2470 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2471 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2472 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2473 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2474 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2475 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2476 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2477 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2478 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2479 | chandef->chan->center_freq)) |
| 2480 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2481 | switch (chandef->width) { |
| 2482 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2483 | case NL80211_CHAN_WIDTH_20: |
| 2484 | case NL80211_CHAN_WIDTH_40: |
| 2485 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2486 | cfg80211_get_chandef_type(chandef))) |
| 2487 | return -ENOBUFS; |
| 2488 | break; |
| 2489 | default: |
| 2490 | break; |
| 2491 | } |
| 2492 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2493 | return -ENOBUFS; |
| 2494 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2495 | return -ENOBUFS; |
| 2496 | if (chandef->center_freq2 && |
| 2497 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2498 | return -ENOBUFS; |
| 2499 | return 0; |
| 2500 | } |
| 2501 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2502 | 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] | 2503 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2504 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2505 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2506 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2507 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2508 | void *hdr; |
| 2509 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2510 | if (removal) |
| 2511 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2512 | |
| 2513 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2514 | if (!hdr) |
| 2515 | return -1; |
| 2516 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2517 | if (dev && |
| 2518 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2519 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2520 | goto nla_put_failure; |
| 2521 | |
| 2522 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2523 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2524 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2525 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2526 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2527 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2528 | rdev->devlist_generation ^ |
| 2529 | (cfg80211_rdev_list_generation << 2))) |
| 2530 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2531 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2532 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2533 | int ret; |
| 2534 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2535 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2536 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2537 | if (ret == 0) { |
| 2538 | if (nl80211_send_chandef(msg, &chandef)) |
| 2539 | goto nla_put_failure; |
| 2540 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2541 | } |
| 2542 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2543 | if (rdev->ops->get_tx_power) { |
| 2544 | int dbm, ret; |
| 2545 | |
| 2546 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2547 | if (ret == 0 && |
| 2548 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2549 | DBM_TO_MBM(dbm))) |
| 2550 | goto nla_put_failure; |
| 2551 | } |
| 2552 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2553 | if (wdev->ssid_len) { |
| 2554 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2555 | goto nla_put_failure; |
| 2556 | } |
| 2557 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2558 | genlmsg_end(msg, hdr); |
| 2559 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2560 | |
| 2561 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2562 | genlmsg_cancel(msg, hdr); |
| 2563 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2567 | { |
| 2568 | int wp_idx = 0; |
| 2569 | int if_idx = 0; |
| 2570 | int wp_start = cb->args[0]; |
| 2571 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2572 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2573 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2574 | struct wireless_dev *wdev; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2575 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2576 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2577 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2578 | if (!cb->args[2]) { |
| 2579 | struct nl80211_dump_wiphy_state state = { |
| 2580 | .filter_wiphy = -1, |
| 2581 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2582 | |
| 2583 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2584 | if (ret) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2585 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2586 | |
| 2587 | filter_wiphy = state.filter_wiphy; |
| 2588 | |
| 2589 | /* |
| 2590 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2591 | * value needed to determine that parsing is necessary. |
| 2592 | */ |
| 2593 | if (filter_wiphy >= 0) |
| 2594 | cb->args[2] = filter_wiphy + 1; |
| 2595 | else |
| 2596 | cb->args[2] = -1; |
| 2597 | } else if (cb->args[2] > 0) { |
| 2598 | filter_wiphy = cb->args[2] - 1; |
| 2599 | } |
| 2600 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2601 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2602 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2603 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2604 | if (wp_idx < wp_start) { |
| 2605 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2606 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2607 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2608 | |
| 2609 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2610 | continue; |
| 2611 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2612 | if_idx = 0; |
| 2613 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2614 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2615 | if (if_idx < if_start) { |
| 2616 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2617 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2618 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2619 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2620 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2621 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2622 | goto out; |
| 2623 | } |
| 2624 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2625 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2626 | |
| 2627 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2628 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2629 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2630 | cb->args[0] = wp_idx; |
| 2631 | cb->args[1] = if_idx; |
| 2632 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 2633 | ret = skb->len; |
| 2634 | out_unlock: |
| 2635 | rtnl_unlock(); |
| 2636 | |
| 2637 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2641 | { |
| 2642 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2643 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2644 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2645 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2646 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2647 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2648 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2649 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2650 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2651 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2652 | nlmsg_free(msg); |
| 2653 | return -ENOBUFS; |
| 2654 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2655 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2656 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2657 | } |
| 2658 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2659 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2660 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2661 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2662 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2663 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2664 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2665 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2666 | }; |
| 2667 | |
| 2668 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2669 | { |
| 2670 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2671 | int flag; |
| 2672 | |
| 2673 | *mntrflags = 0; |
| 2674 | |
| 2675 | if (!nla) |
| 2676 | return -EINVAL; |
| 2677 | |
| 2678 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2679 | nla, mntr_flags_policy)) |
| 2680 | return -EINVAL; |
| 2681 | |
| 2682 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2683 | if (flags[flag]) |
| 2684 | *mntrflags |= (1<<flag); |
| 2685 | |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2689 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2690 | struct net_device *netdev, u8 use_4addr, |
| 2691 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2692 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2693 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2694 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2695 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2696 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2697 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2698 | |
| 2699 | switch (iftype) { |
| 2700 | case NL80211_IFTYPE_AP_VLAN: |
| 2701 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2702 | return 0; |
| 2703 | break; |
| 2704 | case NL80211_IFTYPE_STATION: |
| 2705 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2706 | return 0; |
| 2707 | break; |
| 2708 | default: |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | return -EOPNOTSUPP; |
| 2713 | } |
| 2714 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2715 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2716 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2717 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2718 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2719 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2720 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2721 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2722 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2723 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2724 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2725 | memset(¶ms, 0, sizeof(params)); |
| 2726 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2727 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2728 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2729 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2730 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2731 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2732 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | if (ntype > NL80211_IFTYPE_MAX) |
| 2734 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2735 | } |
| 2736 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2737 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2738 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2739 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2740 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2741 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2742 | if (netif_running(dev)) |
| 2743 | return -EBUSY; |
| 2744 | |
| 2745 | wdev_lock(wdev); |
| 2746 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2747 | IEEE80211_MAX_MESH_ID_LEN); |
| 2748 | wdev->mesh_id_up_len = |
| 2749 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2750 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2751 | wdev->mesh_id_up_len); |
| 2752 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2753 | } |
| 2754 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2755 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2756 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2757 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2758 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2759 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2760 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2761 | } else { |
| 2762 | params.use_4addr = -1; |
| 2763 | } |
| 2764 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2765 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2766 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2767 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2768 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2769 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2770 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2771 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2772 | |
| 2773 | flags = &_flags; |
| 2774 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2775 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2776 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2777 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2778 | const u8 *mumimo_groups; |
| 2779 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2780 | |
| 2781 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2782 | return -EOPNOTSUPP; |
| 2783 | |
| 2784 | mumimo_groups = |
| 2785 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2786 | |
| 2787 | /* bits 0 and 63 are reserved and must be zero */ |
| 2788 | if ((mumimo_groups[0] & BIT(7)) || |
| 2789 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2790 | return -EINVAL; |
| 2791 | |
| 2792 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2793 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2794 | change = true; |
| 2795 | } |
| 2796 | |
| 2797 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2798 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2799 | |
| 2800 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2801 | return -EOPNOTSUPP; |
| 2802 | |
| 2803 | nla_memcpy(params.macaddr, |
| 2804 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2805 | ETH_ALEN); |
| 2806 | change = true; |
| 2807 | } |
| 2808 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2809 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2810 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2811 | return -EOPNOTSUPP; |
| 2812 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2813 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2814 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2815 | else |
| 2816 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2817 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2818 | if (!err && params.use_4addr != -1) |
| 2819 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2820 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2821 | return err; |
| 2822 | } |
| 2823 | |
| 2824 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2827 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2828 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2829 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2830 | int err; |
| 2831 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2832 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2833 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2834 | /* to avoid failing a new interface creation due to pending removal */ |
| 2835 | cfg80211_destroy_ifaces(rdev); |
| 2836 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2837 | memset(¶ms, 0, sizeof(params)); |
| 2838 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2839 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2840 | return -EINVAL; |
| 2841 | |
| 2842 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2843 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2844 | if (type > NL80211_IFTYPE_MAX) |
| 2845 | return -EINVAL; |
| 2846 | } |
| 2847 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2848 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2849 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2850 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2851 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2852 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2853 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2854 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2855 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2856 | ETH_ALEN); |
| 2857 | if (!is_valid_ether_addr(params.macaddr)) |
| 2858 | return -EADDRNOTAVAIL; |
| 2859 | } |
| 2860 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2861 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2862 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2863 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2864 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2865 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2866 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2867 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2868 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2869 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2870 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2871 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2872 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2873 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2874 | return -EOPNOTSUPP; |
| 2875 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2876 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2877 | if (!msg) |
| 2878 | return -ENOMEM; |
| 2879 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2880 | wdev = rdev_add_virtual_intf(rdev, |
| 2881 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2882 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2883 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2884 | if (WARN_ON(!wdev)) { |
| 2885 | nlmsg_free(msg); |
| 2886 | return -EPROTO; |
| 2887 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2888 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2889 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2890 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2891 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2892 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2893 | wdev->owner_nlportid = info->snd_portid; |
| 2894 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2895 | switch (type) { |
| 2896 | case NL80211_IFTYPE_MESH_POINT: |
| 2897 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2898 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2899 | wdev_lock(wdev); |
| 2900 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2901 | IEEE80211_MAX_MESH_ID_LEN); |
| 2902 | wdev->mesh_id_up_len = |
| 2903 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2904 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2905 | wdev->mesh_id_up_len); |
| 2906 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2907 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2908 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2909 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2910 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2911 | * P2P Device and NAN do not have a netdev, so don't go |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2912 | * through the netdev notifier and must be added here |
| 2913 | */ |
| 2914 | mutex_init(&wdev->mtx); |
| 2915 | INIT_LIST_HEAD(&wdev->event_list); |
| 2916 | spin_lock_init(&wdev->event_lock); |
| 2917 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2918 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2919 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2920 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2921 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2922 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2923 | break; |
| 2924 | default: |
| 2925 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2928 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2929 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2930 | nlmsg_free(msg); |
| 2931 | return -ENOBUFS; |
| 2932 | } |
| 2933 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2934 | /* |
| 2935 | * For wdevs which have no associated netdev object (e.g. of type |
| 2936 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2937 | * For all other types, the event will be generated from the |
| 2938 | * netdev notifier |
| 2939 | */ |
| 2940 | if (!wdev->netdev) |
| 2941 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2942 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2943 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2947 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2949 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2950 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2951 | if (!rdev->ops->del_virtual_intf) |
| 2952 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2953 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2954 | /* |
| 2955 | * If we remove a wireless device without a netdev then clear |
| 2956 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2957 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2958 | * since the wdev has been freed, unlike with a netdev where |
| 2959 | * we need the dev_put() for the netdev to really be freed. |
| 2960 | */ |
| 2961 | if (!wdev->netdev) |
| 2962 | info->user_ptr[1] = NULL; |
| 2963 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 2964 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2965 | } |
| 2966 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2967 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2968 | { |
| 2969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2970 | struct net_device *dev = info->user_ptr[1]; |
| 2971 | u16 noack_map; |
| 2972 | |
| 2973 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2974 | return -EINVAL; |
| 2975 | |
| 2976 | if (!rdev->ops->set_noack_map) |
| 2977 | return -EOPNOTSUPP; |
| 2978 | |
| 2979 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2980 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2981 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2982 | } |
| 2983 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2984 | struct get_key_cookie { |
| 2985 | struct sk_buff *msg; |
| 2986 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2987 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2988 | }; |
| 2989 | |
| 2990 | static void get_key_callback(void *c, struct key_params *params) |
| 2991 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2992 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2993 | struct get_key_cookie *cookie = c; |
| 2994 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2995 | if ((params->key && |
| 2996 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2997 | params->key_len, params->key)) || |
| 2998 | (params->seq && |
| 2999 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3000 | params->seq_len, params->seq)) || |
| 3001 | (params->cipher && |
| 3002 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3003 | params->cipher))) |
| 3004 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3005 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3006 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3007 | if (!key) |
| 3008 | goto nla_put_failure; |
| 3009 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3010 | if ((params->key && |
| 3011 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3012 | params->key_len, params->key)) || |
| 3013 | (params->seq && |
| 3014 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3015 | params->seq_len, params->seq)) || |
| 3016 | (params->cipher && |
| 3017 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3018 | params->cipher))) |
| 3019 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3021 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3022 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3023 | |
| 3024 | nla_nest_end(cookie->msg, key); |
| 3025 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3026 | return; |
| 3027 | nla_put_failure: |
| 3028 | cookie->error = 1; |
| 3029 | } |
| 3030 | |
| 3031 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3032 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3034 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3035 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3036 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3037 | const u8 *mac_addr = NULL; |
| 3038 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3039 | struct get_key_cookie cookie = { |
| 3040 | .error = 0, |
| 3041 | }; |
| 3042 | void *hdr; |
| 3043 | struct sk_buff *msg; |
| 3044 | |
| 3045 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3046 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3047 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3048 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3049 | return -EINVAL; |
| 3050 | |
| 3051 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3052 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3053 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3054 | pairwise = !!mac_addr; |
| 3055 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3056 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3057 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3058 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3059 | return -EINVAL; |
| 3060 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3061 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3062 | return -EINVAL; |
| 3063 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3064 | } |
| 3065 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3066 | if (!rdev->ops->get_key) |
| 3067 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3068 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3069 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3070 | return -ENOENT; |
| 3071 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3072 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3073 | if (!msg) |
| 3074 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3075 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3076 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3077 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3078 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3079 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3080 | |
| 3081 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3082 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3083 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3084 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3085 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3086 | goto nla_put_failure; |
| 3087 | if (mac_addr && |
| 3088 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3089 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3090 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3091 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3092 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3093 | |
| 3094 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3095 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3096 | |
| 3097 | if (cookie.error) |
| 3098 | goto nla_put_failure; |
| 3099 | |
| 3100 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3101 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3102 | |
| 3103 | nla_put_failure: |
| 3104 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3105 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3106 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3107 | return err; |
| 3108 | } |
| 3109 | |
| 3110 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3113 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3114 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3115 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3116 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3117 | err = nl80211_parse_key(info, &key); |
| 3118 | if (err) |
| 3119 | return err; |
| 3120 | |
| 3121 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3122 | return -EINVAL; |
| 3123 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3124 | /* only support setting default key */ |
| 3125 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3126 | return -EINVAL; |
| 3127 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3128 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3129 | |
| 3130 | if (key.def) { |
| 3131 | if (!rdev->ops->set_default_key) { |
| 3132 | err = -EOPNOTSUPP; |
| 3133 | goto out; |
| 3134 | } |
| 3135 | |
| 3136 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3137 | if (err) |
| 3138 | goto out; |
| 3139 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3140 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3141 | key.def_uni, key.def_multi); |
| 3142 | |
| 3143 | if (err) |
| 3144 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3145 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3146 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3147 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3148 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3149 | } else { |
| 3150 | if (key.def_uni || !key.def_multi) { |
| 3151 | err = -EINVAL; |
| 3152 | goto out; |
| 3153 | } |
| 3154 | |
| 3155 | if (!rdev->ops->set_default_mgmt_key) { |
| 3156 | err = -EOPNOTSUPP; |
| 3157 | goto out; |
| 3158 | } |
| 3159 | |
| 3160 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3161 | if (err) |
| 3162 | goto out; |
| 3163 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3164 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3165 | if (err) |
| 3166 | goto out; |
| 3167 | |
| 3168 | #ifdef CONFIG_CFG80211_WEXT |
| 3169 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3170 | #endif |
| 3171 | } |
| 3172 | |
| 3173 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3174 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3175 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3176 | return err; |
| 3177 | } |
| 3178 | |
| 3179 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3180 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3182 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3183 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3184 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3185 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3186 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3187 | err = nl80211_parse_key(info, &key); |
| 3188 | if (err) |
| 3189 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3190 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3191 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3192 | return -EINVAL; |
| 3193 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3194 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3195 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3196 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3197 | if (key.type == -1) { |
| 3198 | if (mac_addr) |
| 3199 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3200 | else |
| 3201 | key.type = NL80211_KEYTYPE_GROUP; |
| 3202 | } |
| 3203 | |
| 3204 | /* for now */ |
| 3205 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3206 | key.type != NL80211_KEYTYPE_GROUP) |
| 3207 | return -EINVAL; |
| 3208 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3209 | if (!rdev->ops->add_key) |
| 3210 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3211 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3212 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3213 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3214 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3215 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3216 | |
| 3217 | wdev_lock(dev->ieee80211_ptr); |
| 3218 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3219 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3220 | err = rdev_add_key(rdev, dev, key.idx, |
| 3221 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3222 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3223 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3224 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3225 | return err; |
| 3226 | } |
| 3227 | |
| 3228 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3231 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3232 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3233 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3234 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3235 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3236 | err = nl80211_parse_key(info, &key); |
| 3237 | if (err) |
| 3238 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3239 | |
| 3240 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3241 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3242 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3243 | if (key.type == -1) { |
| 3244 | if (mac_addr) |
| 3245 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3246 | else |
| 3247 | key.type = NL80211_KEYTYPE_GROUP; |
| 3248 | } |
| 3249 | |
| 3250 | /* for now */ |
| 3251 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3252 | key.type != NL80211_KEYTYPE_GROUP) |
| 3253 | return -EINVAL; |
| 3254 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3255 | if (!rdev->ops->del_key) |
| 3256 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3257 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3258 | wdev_lock(dev->ieee80211_ptr); |
| 3259 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3260 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3261 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3262 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3263 | err = -ENOENT; |
| 3264 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3265 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3266 | err = rdev_del_key(rdev, dev, key.idx, |
| 3267 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3268 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3269 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3270 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3271 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3272 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3273 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3274 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3275 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3276 | } |
| 3277 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3278 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3279 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3280 | return err; |
| 3281 | } |
| 3282 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3283 | /* This function returns an error or the number of nested attributes */ |
| 3284 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3285 | { |
| 3286 | struct nlattr *attr; |
| 3287 | int n_entries = 0, tmp; |
| 3288 | |
| 3289 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3290 | if (nla_len(attr) != ETH_ALEN) |
| 3291 | return -EINVAL; |
| 3292 | |
| 3293 | n_entries++; |
| 3294 | } |
| 3295 | |
| 3296 | return n_entries; |
| 3297 | } |
| 3298 | |
| 3299 | /* |
| 3300 | * This function parses ACL information and allocates memory for ACL data. |
| 3301 | * On successful return, the calling function is responsible to free the |
| 3302 | * ACL buffer returned by this function. |
| 3303 | */ |
| 3304 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3305 | struct genl_info *info) |
| 3306 | { |
| 3307 | enum nl80211_acl_policy acl_policy; |
| 3308 | struct nlattr *attr; |
| 3309 | struct cfg80211_acl_data *acl; |
| 3310 | int i = 0, n_entries, tmp; |
| 3311 | |
| 3312 | if (!wiphy->max_acl_mac_addrs) |
| 3313 | return ERR_PTR(-EOPNOTSUPP); |
| 3314 | |
| 3315 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3316 | return ERR_PTR(-EINVAL); |
| 3317 | |
| 3318 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3319 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3320 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3321 | return ERR_PTR(-EINVAL); |
| 3322 | |
| 3323 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3324 | return ERR_PTR(-EINVAL); |
| 3325 | |
| 3326 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3327 | if (n_entries < 0) |
| 3328 | return ERR_PTR(n_entries); |
| 3329 | |
| 3330 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3331 | return ERR_PTR(-ENOTSUPP); |
| 3332 | |
| 3333 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3334 | GFP_KERNEL); |
| 3335 | if (!acl) |
| 3336 | return ERR_PTR(-ENOMEM); |
| 3337 | |
| 3338 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3339 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3340 | i++; |
| 3341 | } |
| 3342 | |
| 3343 | acl->n_acl_entries = n_entries; |
| 3344 | acl->acl_policy = acl_policy; |
| 3345 | |
| 3346 | return acl; |
| 3347 | } |
| 3348 | |
| 3349 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3350 | { |
| 3351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3352 | struct net_device *dev = info->user_ptr[1]; |
| 3353 | struct cfg80211_acl_data *acl; |
| 3354 | int err; |
| 3355 | |
| 3356 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3357 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3358 | return -EOPNOTSUPP; |
| 3359 | |
| 3360 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3361 | return -EINVAL; |
| 3362 | |
| 3363 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3364 | if (IS_ERR(acl)) |
| 3365 | return PTR_ERR(acl); |
| 3366 | |
| 3367 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3368 | |
| 3369 | kfree(acl); |
| 3370 | |
| 3371 | return err; |
| 3372 | } |
| 3373 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3374 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3375 | u8 *rates, u8 rates_len) |
| 3376 | { |
| 3377 | u8 i; |
| 3378 | u32 mask = 0; |
| 3379 | |
| 3380 | for (i = 0; i < rates_len; i++) { |
| 3381 | int rate = (rates[i] & 0x7f) * 5; |
| 3382 | int ridx; |
| 3383 | |
| 3384 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3385 | struct ieee80211_rate *srate = |
| 3386 | &sband->bitrates[ridx]; |
| 3387 | if (rate == srate->bitrate) { |
| 3388 | mask |= 1 << ridx; |
| 3389 | break; |
| 3390 | } |
| 3391 | } |
| 3392 | if (ridx == sband->n_bitrates) |
| 3393 | return 0; /* rate not found */ |
| 3394 | } |
| 3395 | |
| 3396 | return mask; |
| 3397 | } |
| 3398 | |
| 3399 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3400 | u8 *rates, u8 rates_len, |
| 3401 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3402 | { |
| 3403 | u8 i; |
| 3404 | |
| 3405 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3406 | |
| 3407 | for (i = 0; i < rates_len; i++) { |
| 3408 | int ridx, rbit; |
| 3409 | |
| 3410 | ridx = rates[i] / 8; |
| 3411 | rbit = BIT(rates[i] % 8); |
| 3412 | |
| 3413 | /* check validity */ |
| 3414 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3415 | return false; |
| 3416 | |
| 3417 | /* check availability */ |
| 3418 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3419 | mcs[ridx] |= rbit; |
| 3420 | else |
| 3421 | return false; |
| 3422 | } |
| 3423 | |
| 3424 | return true; |
| 3425 | } |
| 3426 | |
| 3427 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3428 | { |
| 3429 | u16 mcs_mask = 0; |
| 3430 | |
| 3431 | switch (vht_mcs_map) { |
| 3432 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3433 | break; |
| 3434 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3435 | mcs_mask = 0x00FF; |
| 3436 | break; |
| 3437 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3438 | mcs_mask = 0x01FF; |
| 3439 | break; |
| 3440 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3441 | mcs_mask = 0x03FF; |
| 3442 | break; |
| 3443 | default: |
| 3444 | break; |
| 3445 | } |
| 3446 | |
| 3447 | return mcs_mask; |
| 3448 | } |
| 3449 | |
| 3450 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3451 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3452 | { |
| 3453 | u8 nss; |
| 3454 | |
| 3455 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3456 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3457 | vht_mcs_map >>= 2; |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3462 | struct nl80211_txrate_vht *txrate, |
| 3463 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3464 | { |
| 3465 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3466 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3467 | u8 i; |
| 3468 | |
| 3469 | if (!sband->vht_cap.vht_supported) |
| 3470 | return false; |
| 3471 | |
| 3472 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3473 | |
| 3474 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3475 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3476 | |
| 3477 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3478 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3479 | mcs[i] = txrate->mcs[i]; |
| 3480 | else |
| 3481 | return false; |
| 3482 | } |
| 3483 | |
| 3484 | return true; |
| 3485 | } |
| 3486 | |
| 3487 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3488 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3489 | .len = NL80211_MAX_SUPP_RATES }, |
| 3490 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3491 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3492 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3493 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3494 | }; |
| 3495 | |
| 3496 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3497 | struct cfg80211_bitrate_mask *mask) |
| 3498 | { |
| 3499 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3501 | int rem, i; |
| 3502 | struct nlattr *tx_rates; |
| 3503 | struct ieee80211_supported_band *sband; |
| 3504 | u16 vht_tx_mcs_map; |
| 3505 | |
| 3506 | memset(mask, 0, sizeof(*mask)); |
| 3507 | /* Default to all rates enabled */ |
| 3508 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3509 | sband = rdev->wiphy.bands[i]; |
| 3510 | |
| 3511 | if (!sband) |
| 3512 | continue; |
| 3513 | |
| 3514 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3515 | memcpy(mask->control[i].ht_mcs, |
| 3516 | sband->ht_cap.mcs.rx_mask, |
| 3517 | sizeof(mask->control[i].ht_mcs)); |
| 3518 | |
| 3519 | if (!sband->vht_cap.vht_supported) |
| 3520 | continue; |
| 3521 | |
| 3522 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3523 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3524 | } |
| 3525 | |
| 3526 | /* if no rates are given set it back to the defaults */ |
| 3527 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3528 | goto out; |
| 3529 | |
| 3530 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3531 | * directly to the enum nl80211_band values used in cfg80211. |
| 3532 | */ |
| 3533 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3534 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3535 | enum nl80211_band band = nla_type(tx_rates); |
| 3536 | int err; |
| 3537 | |
| 3538 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3539 | return -EINVAL; |
| 3540 | sband = rdev->wiphy.bands[band]; |
| 3541 | if (sband == NULL) |
| 3542 | return -EINVAL; |
| 3543 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 3544 | nla_len(tx_rates), nl80211_txattr_policy); |
| 3545 | if (err) |
| 3546 | return err; |
| 3547 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3548 | mask->control[band].legacy = rateset_to_mask( |
| 3549 | sband, |
| 3550 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3551 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3552 | if ((mask->control[band].legacy == 0) && |
| 3553 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3554 | return -EINVAL; |
| 3555 | } |
| 3556 | if (tb[NL80211_TXRATE_HT]) { |
| 3557 | if (!ht_rateset_to_mask( |
| 3558 | sband, |
| 3559 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3560 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3561 | mask->control[band].ht_mcs)) |
| 3562 | return -EINVAL; |
| 3563 | } |
| 3564 | if (tb[NL80211_TXRATE_VHT]) { |
| 3565 | if (!vht_set_mcs_mask( |
| 3566 | sband, |
| 3567 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3568 | mask->control[band].vht_mcs)) |
| 3569 | return -EINVAL; |
| 3570 | } |
| 3571 | if (tb[NL80211_TXRATE_GI]) { |
| 3572 | mask->control[band].gi = |
| 3573 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3574 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3575 | return -EINVAL; |
| 3576 | } |
| 3577 | |
| 3578 | if (mask->control[band].legacy == 0) { |
| 3579 | /* don't allow empty legacy rates if HT or VHT |
| 3580 | * are not even supported. |
| 3581 | */ |
| 3582 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3583 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3584 | return -EINVAL; |
| 3585 | |
| 3586 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3587 | if (mask->control[band].ht_mcs[i]) |
| 3588 | goto out; |
| 3589 | |
| 3590 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3591 | if (mask->control[band].vht_mcs[i]) |
| 3592 | goto out; |
| 3593 | |
| 3594 | /* legacy and mcs rates may not be both empty */ |
| 3595 | return -EINVAL; |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | out: |
| 3600 | return 0; |
| 3601 | } |
| 3602 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3603 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3604 | enum nl80211_band band, |
| 3605 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3606 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3607 | u32 count_ht, count_vht, i; |
| 3608 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3609 | |
| 3610 | /* Allow only one rate */ |
| 3611 | if (hweight32(rate) > 1) |
| 3612 | return -EINVAL; |
| 3613 | |
| 3614 | count_ht = 0; |
| 3615 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3616 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3617 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3618 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3619 | count_ht++; |
| 3620 | if (count_ht > 1) |
| 3621 | return -EINVAL; |
| 3622 | } |
| 3623 | if (count_ht && rate) |
| 3624 | return -EINVAL; |
| 3625 | } |
| 3626 | |
| 3627 | count_vht = 0; |
| 3628 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3629 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3630 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3631 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3632 | count_vht++; |
| 3633 | if (count_vht > 1) |
| 3634 | return -EINVAL; |
| 3635 | } |
| 3636 | if (count_vht && rate) |
| 3637 | return -EINVAL; |
| 3638 | } |
| 3639 | |
| 3640 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3641 | return -EINVAL; |
| 3642 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3643 | if (rate && |
| 3644 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3645 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3646 | return -EINVAL; |
| 3647 | if (count_ht && |
| 3648 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3649 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3650 | return -EINVAL; |
| 3651 | if (count_vht && |
| 3652 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3653 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3654 | return -EINVAL; |
| 3655 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3656 | return 0; |
| 3657 | } |
| 3658 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3659 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3660 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3661 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3662 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3663 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3664 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3665 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3666 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3667 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3668 | return -EINVAL; |
| 3669 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3670 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3671 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3672 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3673 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3674 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3675 | if (!bcn->head_len) |
| 3676 | return -EINVAL; |
| 3677 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3678 | } |
| 3679 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3680 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3681 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3682 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3683 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3684 | } |
| 3685 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3686 | if (!haveinfo) |
| 3687 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3688 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3689 | if (attrs[NL80211_ATTR_IE]) { |
| 3690 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3691 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3692 | } |
| 3693 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3694 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3695 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3696 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3697 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3698 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3699 | } |
| 3700 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3701 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3702 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3703 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3704 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3705 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3706 | } |
| 3707 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3708 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3709 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3710 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3711 | } |
| 3712 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3713 | return 0; |
| 3714 | } |
| 3715 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3716 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3717 | struct cfg80211_ap_settings *params) |
| 3718 | { |
| 3719 | struct wireless_dev *wdev; |
| 3720 | bool ret = false; |
| 3721 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3722 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3723 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3724 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3725 | continue; |
| 3726 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3727 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3728 | continue; |
| 3729 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3730 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3731 | ret = true; |
| 3732 | break; |
| 3733 | } |
| 3734 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3735 | return ret; |
| 3736 | } |
| 3737 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3738 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3739 | enum nl80211_auth_type auth_type, |
| 3740 | enum nl80211_commands cmd) |
| 3741 | { |
| 3742 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3743 | return false; |
| 3744 | |
| 3745 | switch (cmd) { |
| 3746 | case NL80211_CMD_AUTHENTICATE: |
| 3747 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3748 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3749 | return false; |
| 3750 | return true; |
| 3751 | case NL80211_CMD_CONNECT: |
| 3752 | case NL80211_CMD_START_AP: |
| 3753 | /* SAE not supported yet */ |
| 3754 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3755 | return false; |
| 3756 | return true; |
| 3757 | default: |
| 3758 | return false; |
| 3759 | } |
| 3760 | } |
| 3761 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3762 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3763 | { |
| 3764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3765 | struct net_device *dev = info->user_ptr[1]; |
| 3766 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3767 | struct cfg80211_ap_settings params; |
| 3768 | int err; |
| 3769 | |
| 3770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3772 | return -EOPNOTSUPP; |
| 3773 | |
| 3774 | if (!rdev->ops->start_ap) |
| 3775 | return -EOPNOTSUPP; |
| 3776 | |
| 3777 | if (wdev->beacon_interval) |
| 3778 | return -EALREADY; |
| 3779 | |
| 3780 | memset(¶ms, 0, sizeof(params)); |
| 3781 | |
| 3782 | /* these are required for START_AP */ |
| 3783 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3784 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3785 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3786 | return -EINVAL; |
| 3787 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3788 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3789 | if (err) |
| 3790 | return err; |
| 3791 | |
| 3792 | params.beacon_interval = |
| 3793 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3794 | params.dtim_period = |
| 3795 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3796 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3797 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3798 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3799 | if (err) |
| 3800 | return err; |
| 3801 | |
| 3802 | /* |
| 3803 | * In theory, some of these attributes should be required here |
| 3804 | * but since they were not used when the command was originally |
| 3805 | * added, keep them optional for old user space programs to let |
| 3806 | * them continue to work with drivers that do not need the |
| 3807 | * additional information -- drivers must check! |
| 3808 | */ |
| 3809 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3810 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3811 | params.ssid_len = |
| 3812 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3813 | if (params.ssid_len == 0 || |
| 3814 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3815 | return -EINVAL; |
| 3816 | } |
| 3817 | |
| 3818 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3819 | params.hidden_ssid = nla_get_u32( |
| 3820 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3821 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3822 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3823 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3824 | return -EINVAL; |
| 3825 | } |
| 3826 | |
| 3827 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3828 | |
| 3829 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3830 | params.auth_type = nla_get_u32( |
| 3831 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3832 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3833 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3834 | return -EINVAL; |
| 3835 | } else |
| 3836 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3837 | |
| 3838 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3839 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3840 | if (err) |
| 3841 | return err; |
| 3842 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3843 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3844 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3845 | return -EOPNOTSUPP; |
| 3846 | params.inactivity_timeout = nla_get_u16( |
| 3847 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3848 | } |
| 3849 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3850 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3851 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3852 | return -EINVAL; |
| 3853 | params.p2p_ctwindow = |
| 3854 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3855 | if (params.p2p_ctwindow > 127) |
| 3856 | return -EINVAL; |
| 3857 | if (params.p2p_ctwindow != 0 && |
| 3858 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3859 | return -EINVAL; |
| 3860 | } |
| 3861 | |
| 3862 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3863 | u8 tmp; |
| 3864 | |
| 3865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3866 | return -EINVAL; |
| 3867 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3868 | if (tmp > 1) |
| 3869 | return -EINVAL; |
| 3870 | params.p2p_opp_ps = tmp; |
| 3871 | if (params.p2p_opp_ps != 0 && |
| 3872 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3873 | return -EINVAL; |
| 3874 | } |
| 3875 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3876 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3877 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3878 | if (err) |
| 3879 | return err; |
| 3880 | } else if (wdev->preset_chandef.chan) { |
| 3881 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3882 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3883 | return -EINVAL; |
| 3884 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3885 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3886 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3887 | return -EINVAL; |
| 3888 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3889 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 3890 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 3891 | if (err) |
| 3892 | return err; |
| 3893 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3894 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 3895 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3896 | if (err) |
| 3897 | return err; |
| 3898 | } |
| 3899 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3900 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3901 | params.smps_mode = |
| 3902 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3903 | switch (params.smps_mode) { |
| 3904 | case NL80211_SMPS_OFF: |
| 3905 | break; |
| 3906 | case NL80211_SMPS_STATIC: |
| 3907 | if (!(rdev->wiphy.features & |
| 3908 | NL80211_FEATURE_STATIC_SMPS)) |
| 3909 | return -EINVAL; |
| 3910 | break; |
| 3911 | case NL80211_SMPS_DYNAMIC: |
| 3912 | if (!(rdev->wiphy.features & |
| 3913 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3914 | return -EINVAL; |
| 3915 | break; |
| 3916 | default: |
| 3917 | return -EINVAL; |
| 3918 | } |
| 3919 | } else { |
| 3920 | params.smps_mode = NL80211_SMPS_OFF; |
| 3921 | } |
| 3922 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3923 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3924 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3925 | return -EOPNOTSUPP; |
| 3926 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3927 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3928 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3929 | if (IS_ERR(params.acl)) |
| 3930 | return PTR_ERR(params.acl); |
| 3931 | } |
| 3932 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3933 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3934 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3935 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3936 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3937 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3938 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3939 | wdev->ssid_len = params.ssid_len; |
| 3940 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3941 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3942 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3943 | |
| 3944 | kfree(params.acl); |
| 3945 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3946 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3947 | } |
| 3948 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3949 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3950 | { |
| 3951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3952 | struct net_device *dev = info->user_ptr[1]; |
| 3953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3954 | struct cfg80211_beacon_data params; |
| 3955 | int err; |
| 3956 | |
| 3957 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3958 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3959 | return -EOPNOTSUPP; |
| 3960 | |
| 3961 | if (!rdev->ops->change_beacon) |
| 3962 | return -EOPNOTSUPP; |
| 3963 | |
| 3964 | if (!wdev->beacon_interval) |
| 3965 | return -EINVAL; |
| 3966 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3967 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3968 | if (err) |
| 3969 | return err; |
| 3970 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3971 | wdev_lock(wdev); |
| 3972 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3973 | wdev_unlock(wdev); |
| 3974 | |
| 3975 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | 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] | 3979 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3981 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3982 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3983 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3984 | } |
| 3985 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3986 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3987 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3988 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3989 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3990 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3991 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3992 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3993 | }; |
| 3994 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3995 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3996 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3997 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3998 | { |
| 3999 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4000 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4001 | int flag; |
| 4002 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4003 | /* |
| 4004 | * Try parsing the new attribute first so userspace |
| 4005 | * can specify both for older kernels. |
| 4006 | */ |
| 4007 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4008 | if (nla) { |
| 4009 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4010 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4011 | sta_flags = nla_data(nla); |
| 4012 | params->sta_flags_mask = sta_flags->mask; |
| 4013 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4014 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4015 | if ((params->sta_flags_mask | |
| 4016 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4017 | return -EINVAL; |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
| 4021 | /* if present, parse the old attribute */ |
| 4022 | |
| 4023 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4024 | if (!nla) |
| 4025 | return 0; |
| 4026 | |
| 4027 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 4028 | nla, sta_flags_policy)) |
| 4029 | return -EINVAL; |
| 4030 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4031 | /* |
| 4032 | * Only allow certain flags for interface types so that |
| 4033 | * other attributes are silently ignored. Remember that |
| 4034 | * this is backward compatibility code with old userspace |
| 4035 | * and shouldn't be hit in other cases anyway. |
| 4036 | */ |
| 4037 | switch (iftype) { |
| 4038 | case NL80211_IFTYPE_AP: |
| 4039 | case NL80211_IFTYPE_AP_VLAN: |
| 4040 | case NL80211_IFTYPE_P2P_GO: |
| 4041 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4042 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4043 | BIT(NL80211_STA_FLAG_WME) | |
| 4044 | BIT(NL80211_STA_FLAG_MFP); |
| 4045 | break; |
| 4046 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4047 | case NL80211_IFTYPE_STATION: |
| 4048 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4049 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4050 | break; |
| 4051 | case NL80211_IFTYPE_MESH_POINT: |
| 4052 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4053 | BIT(NL80211_STA_FLAG_MFP) | |
| 4054 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4055 | default: |
| 4056 | return -EINVAL; |
| 4057 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4058 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4059 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4060 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4061 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4062 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4063 | /* no longer support new API additions in old API */ |
| 4064 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4065 | return -EINVAL; |
| 4066 | } |
| 4067 | } |
| 4068 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4069 | return 0; |
| 4070 | } |
| 4071 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4072 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4073 | int attr) |
| 4074 | { |
| 4075 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4076 | u32 bitrate; |
| 4077 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4078 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4079 | |
| 4080 | rate = nla_nest_start(msg, attr); |
| 4081 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4082 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4083 | |
| 4084 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4085 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4086 | /* report 16-bit bitrate only if we can */ |
| 4087 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4088 | if (bitrate > 0 && |
| 4089 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4090 | return false; |
| 4091 | if (bitrate_compat > 0 && |
| 4092 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4093 | return false; |
| 4094 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4095 | switch (info->bw) { |
| 4096 | case RATE_INFO_BW_5: |
| 4097 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4098 | break; |
| 4099 | case RATE_INFO_BW_10: |
| 4100 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4101 | break; |
| 4102 | default: |
| 4103 | WARN_ON(1); |
| 4104 | /* fall through */ |
| 4105 | case RATE_INFO_BW_20: |
| 4106 | rate_flg = 0; |
| 4107 | break; |
| 4108 | case RATE_INFO_BW_40: |
| 4109 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4110 | break; |
| 4111 | case RATE_INFO_BW_80: |
| 4112 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4113 | break; |
| 4114 | case RATE_INFO_BW_160: |
| 4115 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4116 | break; |
| 4117 | } |
| 4118 | |
| 4119 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4120 | return false; |
| 4121 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4122 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4123 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4124 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4125 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4126 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4127 | return false; |
| 4128 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4129 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4130 | return false; |
| 4131 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4132 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4133 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4134 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4135 | return false; |
| 4136 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4137 | |
| 4138 | nla_nest_end(msg, rate); |
| 4139 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4142 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4143 | int id) |
| 4144 | { |
| 4145 | void *attr; |
| 4146 | int i = 0; |
| 4147 | |
| 4148 | if (!mask) |
| 4149 | return true; |
| 4150 | |
| 4151 | attr = nla_nest_start(msg, id); |
| 4152 | if (!attr) |
| 4153 | return false; |
| 4154 | |
| 4155 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4156 | if (!(mask & BIT(i))) |
| 4157 | continue; |
| 4158 | |
| 4159 | if (nla_put_u8(msg, i, signal[i])) |
| 4160 | return false; |
| 4161 | } |
| 4162 | |
| 4163 | nla_nest_end(msg, attr); |
| 4164 | |
| 4165 | return true; |
| 4166 | } |
| 4167 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4168 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4169 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4170 | struct cfg80211_registered_device *rdev, |
| 4171 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4172 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4173 | { |
| 4174 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4175 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4176 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4177 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4178 | if (!hdr) |
| 4179 | return -1; |
| 4180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4181 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4182 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4183 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4184 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4185 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4186 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4187 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4188 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4189 | |
| 4190 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4191 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4192 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4193 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4194 | sinfo->memb)) \ |
| 4195 | goto nla_put_failure; \ |
| 4196 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4197 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4198 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4199 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4200 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4201 | goto nla_put_failure; \ |
| 4202 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4203 | |
| 4204 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4205 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4206 | |
| 4207 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4208 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4209 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4210 | (u32)sinfo->rx_bytes)) |
| 4211 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4212 | |
| 4213 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4214 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4215 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4216 | (u32)sinfo->tx_bytes)) |
| 4217 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4218 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4219 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4220 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4221 | PUT_SINFO(LLID, llid, u16); |
| 4222 | PUT_SINFO(PLID, plid, u16); |
| 4223 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4224 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4225 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4226 | switch (rdev->wiphy.signal_type) { |
| 4227 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4228 | PUT_SINFO(SIGNAL, signal, u8); |
| 4229 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4230 | break; |
| 4231 | default: |
| 4232 | break; |
| 4233 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4234 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4235 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4236 | sinfo->chain_signal, |
| 4237 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4238 | goto nla_put_failure; |
| 4239 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4240 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4241 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4242 | sinfo->chain_signal_avg, |
| 4243 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4244 | goto nla_put_failure; |
| 4245 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4246 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4247 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4248 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4249 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4250 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4251 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4252 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4253 | NL80211_STA_INFO_RX_BITRATE)) |
| 4254 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4255 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4256 | |
| 4257 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4258 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4259 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4260 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4261 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4262 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4263 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4264 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4265 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4266 | |
| 4267 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4268 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4269 | if (!bss_param) |
| 4270 | goto nla_put_failure; |
| 4271 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4272 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4273 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4274 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4275 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4276 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4277 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4278 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4279 | sinfo->bss_param.dtim_period) || |
| 4280 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4281 | sinfo->bss_param.beacon_interval)) |
| 4282 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4283 | |
| 4284 | nla_nest_end(msg, bss_param); |
| 4285 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4286 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4287 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4288 | sizeof(struct nl80211_sta_flag_update), |
| 4289 | &sinfo->sta_flags)) |
| 4290 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4291 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4292 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4293 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4294 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4295 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4296 | |
| 4297 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4298 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4299 | |
| 4300 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4301 | struct nlattr *tidsattr; |
| 4302 | int tid; |
| 4303 | |
| 4304 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4305 | if (!tidsattr) |
| 4306 | goto nla_put_failure; |
| 4307 | |
| 4308 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4309 | struct cfg80211_tid_stats *tidstats; |
| 4310 | struct nlattr *tidattr; |
| 4311 | |
| 4312 | tidstats = &sinfo->pertid[tid]; |
| 4313 | |
| 4314 | if (!tidstats->filled) |
| 4315 | continue; |
| 4316 | |
| 4317 | tidattr = nla_nest_start(msg, tid + 1); |
| 4318 | if (!tidattr) |
| 4319 | goto nla_put_failure; |
| 4320 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4321 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4322 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4323 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4324 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4325 | goto nla_put_failure; \ |
| 4326 | } while (0) |
| 4327 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4328 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4329 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4330 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4331 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4332 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4333 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4334 | nla_nest_end(msg, tidattr); |
| 4335 | } |
| 4336 | |
| 4337 | nla_nest_end(msg, tidsattr); |
| 4338 | } |
| 4339 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4340 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4341 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4342 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4343 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4344 | sinfo->assoc_req_ies)) |
| 4345 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4346 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4347 | genlmsg_end(msg, hdr); |
| 4348 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4349 | |
| 4350 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4351 | genlmsg_cancel(msg, hdr); |
| 4352 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4353 | } |
| 4354 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4355 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4356 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4357 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4358 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4359 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4360 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4361 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4362 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4363 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4364 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4365 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4366 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4367 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4368 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4369 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4370 | if (!wdev->netdev) { |
| 4371 | err = -EINVAL; |
| 4372 | goto out_err; |
| 4373 | } |
| 4374 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4375 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4376 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4377 | goto out_err; |
| 4378 | } |
| 4379 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4380 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4381 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4382 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4383 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4384 | if (err == -ENOENT) |
| 4385 | break; |
| 4386 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4387 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4388 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4389 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4390 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4391 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4392 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4393 | &sinfo) < 0) |
| 4394 | goto out; |
| 4395 | |
| 4396 | sta_idx++; |
| 4397 | } |
| 4398 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4399 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4400 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4401 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4402 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 4403 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4404 | |
| 4405 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4406 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4407 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4408 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4409 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4411 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4412 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4413 | struct sk_buff *msg; |
| 4414 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4415 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4416 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4417 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4418 | |
| 4419 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4420 | return -EINVAL; |
| 4421 | |
| 4422 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4424 | if (!rdev->ops->get_station) |
| 4425 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4426 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4427 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4428 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4429 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4430 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4431 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4432 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4433 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4434 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4435 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4436 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4437 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4438 | nlmsg_free(msg); |
| 4439 | return -ENOBUFS; |
| 4440 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4441 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4442 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4443 | } |
| 4444 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4445 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4446 | struct station_parameters *params, |
| 4447 | enum cfg80211_station_type statype) |
| 4448 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4449 | if (params->listen_interval != -1 && |
| 4450 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4451 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4452 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4453 | if (params->support_p2p_ps != -1 && |
| 4454 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4455 | return -EINVAL; |
| 4456 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4457 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4458 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4459 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4460 | return -EINVAL; |
| 4461 | |
| 4462 | /* When you run into this, adjust the code below for the new flag */ |
| 4463 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4464 | |
| 4465 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4466 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4467 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4468 | /* |
| 4469 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4470 | * code doesn't have the bug of including TDLS in the |
| 4471 | * mask everywhere. |
| 4472 | */ |
| 4473 | if (params->sta_flags_mask & |
| 4474 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4475 | BIT(NL80211_STA_FLAG_MFP) | |
| 4476 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4477 | return -EINVAL; |
| 4478 | break; |
| 4479 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4480 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4481 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4482 | return -EINVAL; |
| 4483 | /* ignore since it can't change */ |
| 4484 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4485 | break; |
| 4486 | default: |
| 4487 | /* disallow mesh-specific things */ |
| 4488 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4489 | return -EINVAL; |
| 4490 | if (params->local_pm) |
| 4491 | return -EINVAL; |
| 4492 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4493 | return -EINVAL; |
| 4494 | } |
| 4495 | |
| 4496 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4497 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4498 | /* TDLS can't be set, ... */ |
| 4499 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4500 | return -EINVAL; |
| 4501 | /* |
| 4502 | * ... but don't bother the driver with it. This works around |
| 4503 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4504 | * TLDS_PEER flag in the mask even for AP mode. |
| 4505 | */ |
| 4506 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4507 | } |
| 4508 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4509 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4510 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4511 | /* reject other things that can't change */ |
| 4512 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4513 | return -EINVAL; |
| 4514 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4515 | return -EINVAL; |
| 4516 | if (params->supported_rates) |
| 4517 | return -EINVAL; |
| 4518 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4519 | return -EINVAL; |
| 4520 | } |
| 4521 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4522 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4523 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4524 | if (params->vlan) |
| 4525 | return -EINVAL; |
| 4526 | } |
| 4527 | |
| 4528 | switch (statype) { |
| 4529 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4530 | /* Use this only for authorizing/unauthorizing a station */ |
| 4531 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4532 | return -EOPNOTSUPP; |
| 4533 | break; |
| 4534 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4535 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4536 | /* accept only the listed bits */ |
| 4537 | if (params->sta_flags_mask & |
| 4538 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4539 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4540 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4541 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4542 | BIT(NL80211_STA_FLAG_WME) | |
| 4543 | BIT(NL80211_STA_FLAG_MFP))) |
| 4544 | return -EINVAL; |
| 4545 | |
| 4546 | /* but authenticated/associated only if driver handles it */ |
| 4547 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4548 | params->sta_flags_mask & |
| 4549 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4550 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4551 | return -EINVAL; |
| 4552 | break; |
| 4553 | case CFG80211_STA_IBSS: |
| 4554 | case CFG80211_STA_AP_STA: |
| 4555 | /* reject any changes other than AUTHORIZED */ |
| 4556 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4557 | return -EINVAL; |
| 4558 | break; |
| 4559 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4560 | /* reject any changes other than AUTHORIZED or WME */ |
| 4561 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4562 | BIT(NL80211_STA_FLAG_WME))) |
| 4563 | return -EINVAL; |
| 4564 | /* force (at least) rates when authorizing */ |
| 4565 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4566 | !params->supported_rates) |
| 4567 | return -EINVAL; |
| 4568 | break; |
| 4569 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4570 | /* reject any changes */ |
| 4571 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4572 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4573 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4574 | return -EINVAL; |
| 4575 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4576 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4577 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4578 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4579 | return -EINVAL; |
| 4580 | break; |
| 4581 | } |
| 4582 | |
| 4583 | return 0; |
| 4584 | } |
| 4585 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4586 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4587 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4588 | * 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] | 4589 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4590 | static struct net_device *get_vlan(struct genl_info *info, |
| 4591 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4592 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4593 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4594 | struct net_device *v; |
| 4595 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4596 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4597 | if (!vlanattr) |
| 4598 | return NULL; |
| 4599 | |
| 4600 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4601 | if (!v) |
| 4602 | return ERR_PTR(-ENODEV); |
| 4603 | |
| 4604 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4605 | ret = -EINVAL; |
| 4606 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4607 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4608 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4609 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4610 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4611 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4612 | ret = -EINVAL; |
| 4613 | goto error; |
| 4614 | } |
| 4615 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4616 | if (!netif_running(v)) { |
| 4617 | ret = -ENETDOWN; |
| 4618 | goto error; |
| 4619 | } |
| 4620 | |
| 4621 | return v; |
| 4622 | error: |
| 4623 | dev_put(v); |
| 4624 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4627 | static const struct nla_policy |
| 4628 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4629 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4630 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4631 | }; |
| 4632 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4633 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4634 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4635 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4636 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4637 | struct nlattr *nla; |
| 4638 | int err; |
| 4639 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4640 | /* parse WME attributes if present */ |
| 4641 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4642 | return 0; |
| 4643 | |
| 4644 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4645 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4646 | nl80211_sta_wme_policy); |
| 4647 | if (err) |
| 4648 | return err; |
| 4649 | |
| 4650 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4651 | params->uapsd_queues = nla_get_u8( |
| 4652 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4653 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4654 | return -EINVAL; |
| 4655 | |
| 4656 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4657 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4658 | |
| 4659 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4660 | return -EINVAL; |
| 4661 | |
| 4662 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4663 | |
| 4664 | return 0; |
| 4665 | } |
| 4666 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4667 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4668 | struct station_parameters *params) |
| 4669 | { |
| 4670 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4671 | params->supported_channels = |
| 4672 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4673 | params->supported_channels_len = |
| 4674 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4675 | /* |
| 4676 | * Need to include at least one (first channel, number of |
| 4677 | * channels) tuple for each subband, and must have proper |
| 4678 | * tuples for the rest of the data as well. |
| 4679 | */ |
| 4680 | if (params->supported_channels_len < 2) |
| 4681 | return -EINVAL; |
| 4682 | if (params->supported_channels_len % 2) |
| 4683 | return -EINVAL; |
| 4684 | } |
| 4685 | |
| 4686 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4687 | params->supported_oper_classes = |
| 4688 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4689 | params->supported_oper_classes_len = |
| 4690 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4691 | /* |
| 4692 | * The value of the Length field of the Supported Operating |
| 4693 | * Classes element is between 2 and 253. |
| 4694 | */ |
| 4695 | if (params->supported_oper_classes_len < 2 || |
| 4696 | params->supported_oper_classes_len > 253) |
| 4697 | return -EINVAL; |
| 4698 | } |
| 4699 | return 0; |
| 4700 | } |
| 4701 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4702 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4703 | struct station_parameters *params) |
| 4704 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4705 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4706 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4707 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4708 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4709 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4710 | params->ht_capa = |
| 4711 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4712 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4713 | params->vht_capa = |
| 4714 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4715 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4716 | err = nl80211_parse_sta_channel_info(info, params); |
| 4717 | if (err) |
| 4718 | return err; |
| 4719 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4720 | return nl80211_parse_sta_wme(info, params); |
| 4721 | } |
| 4722 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4723 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4724 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4726 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4727 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4728 | u8 *mac_addr; |
| 4729 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4730 | |
| 4731 | memset(¶ms, 0, sizeof(params)); |
| 4732 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4733 | if (!rdev->ops->change_station) |
| 4734 | return -EOPNOTSUPP; |
| 4735 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4736 | /* |
| 4737 | * AID and listen_interval properties can be set only for unassociated |
| 4738 | * station. Include these parameters here and will check them in |
| 4739 | * cfg80211_check_station_change(). |
| 4740 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4741 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4742 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4743 | |
| 4744 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4745 | params.listen_interval = |
| 4746 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4747 | else |
| 4748 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4749 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4750 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4751 | u8 tmp; |
| 4752 | |
| 4753 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4754 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4755 | return -EINVAL; |
| 4756 | |
| 4757 | params.support_p2p_ps = tmp; |
| 4758 | } else { |
| 4759 | params.support_p2p_ps = -1; |
| 4760 | } |
| 4761 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4762 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4763 | return -EINVAL; |
| 4764 | |
| 4765 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4766 | |
| 4767 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4768 | params.supported_rates = |
| 4769 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4770 | params.supported_rates_len = |
| 4771 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4772 | } |
| 4773 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4774 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4775 | params.capability = |
| 4776 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4777 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4778 | } |
| 4779 | |
| 4780 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4781 | params.ext_capab = |
| 4782 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4783 | params.ext_capab_len = |
| 4784 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4785 | } |
| 4786 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4787 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4788 | return -EINVAL; |
| 4789 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4790 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4791 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4792 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4793 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4794 | return -EINVAL; |
| 4795 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4796 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4797 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4798 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4799 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4800 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4801 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4802 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4803 | params.peer_aid = nla_get_u16( |
| 4804 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4805 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4806 | return -EINVAL; |
| 4807 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4808 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4809 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4810 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4811 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4812 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4813 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4814 | |
| 4815 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4816 | pm > NL80211_MESH_POWER_MAX) |
| 4817 | return -EINVAL; |
| 4818 | |
| 4819 | params.local_pm = pm; |
| 4820 | } |
| 4821 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4822 | /* Include parameters for TDLS peer (will check later) */ |
| 4823 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4824 | if (err) |
| 4825 | return err; |
| 4826 | |
| 4827 | params.vlan = get_vlan(info, rdev); |
| 4828 | if (IS_ERR(params.vlan)) |
| 4829 | return PTR_ERR(params.vlan); |
| 4830 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4831 | switch (dev->ieee80211_ptr->iftype) { |
| 4832 | case NL80211_IFTYPE_AP: |
| 4833 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4834 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4835 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4836 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4837 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4838 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4839 | break; |
| 4840 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4841 | err = -EOPNOTSUPP; |
| 4842 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4843 | } |
| 4844 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4845 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4846 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4847 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4848 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4849 | if (params.vlan) |
| 4850 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4851 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4852 | return err; |
| 4853 | } |
| 4854 | |
| 4855 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4856 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4857 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4858 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4860 | struct station_parameters params; |
| 4861 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4862 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4863 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4864 | |
| 4865 | memset(¶ms, 0, sizeof(params)); |
| 4866 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4867 | if (!rdev->ops->add_station) |
| 4868 | return -EOPNOTSUPP; |
| 4869 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4870 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4871 | return -EINVAL; |
| 4872 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4873 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4874 | return -EINVAL; |
| 4875 | |
| 4876 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4877 | return -EINVAL; |
| 4878 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4879 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4880 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4881 | return -EINVAL; |
| 4882 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4883 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4884 | params.supported_rates = |
| 4885 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4886 | params.supported_rates_len = |
| 4887 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4888 | params.listen_interval = |
| 4889 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4890 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4891 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4892 | u8 tmp; |
| 4893 | |
| 4894 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4895 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4896 | return -EINVAL; |
| 4897 | |
| 4898 | params.support_p2p_ps = tmp; |
| 4899 | } else { |
| 4900 | /* |
| 4901 | * if not specified, assume it's supported for P2P GO interface, |
| 4902 | * and is NOT supported for AP interface |
| 4903 | */ |
| 4904 | params.support_p2p_ps = |
| 4905 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4906 | } |
| 4907 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4908 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4909 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4910 | else |
| 4911 | 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] | 4912 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4913 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4914 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4915 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4916 | params.capability = |
| 4917 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4918 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4919 | } |
| 4920 | |
| 4921 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4922 | params.ext_capab = |
| 4923 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4924 | params.ext_capab_len = |
| 4925 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4926 | } |
| 4927 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4928 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4929 | params.ht_capa = |
| 4930 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4931 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4932 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4933 | params.vht_capa = |
| 4934 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4935 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4936 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4937 | params.opmode_notif_used = true; |
| 4938 | params.opmode_notif = |
| 4939 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4940 | } |
| 4941 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4942 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4943 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4944 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4945 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4946 | return -EINVAL; |
| 4947 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4948 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4949 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4950 | if (err) |
| 4951 | return err; |
| 4952 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4953 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4954 | if (err) |
| 4955 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4956 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4957 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4958 | return -EINVAL; |
| 4959 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4960 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4961 | * as userspace might just pass through the capabilities from the IEs |
| 4962 | * directly, rather than enforcing this restriction and returning an |
| 4963 | * error in this case. |
| 4964 | */ |
| 4965 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 4966 | params.ht_capa = NULL; |
| 4967 | params.vht_capa = NULL; |
| 4968 | } |
| 4969 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4970 | /* When you run into this, adjust the code below for the new flag */ |
| 4971 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4972 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4973 | switch (dev->ieee80211_ptr->iftype) { |
| 4974 | case NL80211_IFTYPE_AP: |
| 4975 | case NL80211_IFTYPE_AP_VLAN: |
| 4976 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4977 | /* ignore WME attributes if iface/sta is not capable */ |
| 4978 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4979 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4980 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4981 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4982 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4983 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4984 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4985 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4986 | /* but don't bother the driver with it */ |
| 4987 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4988 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4989 | /* allow authenticated/associated only if driver handles it */ |
| 4990 | if (!(rdev->wiphy.features & |
| 4991 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4992 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4993 | return -EINVAL; |
| 4994 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4995 | /* Older userspace, or userspace wanting to be compatible with |
| 4996 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 4997 | * and assoc flags in the mask, but assumes the station will be |
| 4998 | * added as associated anyway since this was the required driver |
| 4999 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5000 | * introduced. |
| 5001 | * In order to not bother drivers with this quirk in the API |
| 5002 | * set the flags in both the mask and set for new stations in |
| 5003 | * this case. |
| 5004 | */ |
| 5005 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5006 | params.sta_flags_mask |= auth_assoc; |
| 5007 | params.sta_flags_set |= auth_assoc; |
| 5008 | } |
| 5009 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5010 | /* must be last in here for error handling */ |
| 5011 | params.vlan = get_vlan(info, rdev); |
| 5012 | if (IS_ERR(params.vlan)) |
| 5013 | return PTR_ERR(params.vlan); |
| 5014 | break; |
| 5015 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5016 | /* ignore uAPSD data */ |
| 5017 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5018 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5019 | /* associated is disallowed */ |
| 5020 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5021 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5022 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5023 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5024 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5025 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5026 | break; |
| 5027 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5028 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5029 | /* ignore uAPSD data */ |
| 5030 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5031 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5032 | /* these are disallowed */ |
| 5033 | if (params.sta_flags_mask & |
| 5034 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5035 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5036 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5037 | /* Only TDLS peers can be added */ |
| 5038 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5039 | return -EINVAL; |
| 5040 | /* Can only add if TDLS ... */ |
| 5041 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5042 | return -EOPNOTSUPP; |
| 5043 | /* ... with external setup is supported */ |
| 5044 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5045 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5046 | /* |
| 5047 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5048 | * as authorized, but it shouldn't yet be. |
| 5049 | */ |
| 5050 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5051 | break; |
| 5052 | default: |
| 5053 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5054 | } |
| 5055 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5056 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5057 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5058 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5059 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5060 | if (params.vlan) |
| 5061 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5062 | return err; |
| 5063 | } |
| 5064 | |
| 5065 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5066 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5068 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5069 | struct station_del_parameters params; |
| 5070 | |
| 5071 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5072 | |
| 5073 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5074 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5075 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5076 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5077 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5079 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5080 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5082 | if (!rdev->ops->del_station) |
| 5083 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5084 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5085 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5086 | params.subtype = |
| 5087 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5088 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5089 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5090 | return -EINVAL; |
| 5091 | } else { |
| 5092 | /* Default to Deauthentication frame */ |
| 5093 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5094 | } |
| 5095 | |
| 5096 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5097 | params.reason_code = |
| 5098 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5099 | if (params.reason_code == 0) |
| 5100 | return -EINVAL; /* 0 is reserved */ |
| 5101 | } else { |
| 5102 | /* Default to reason code 2 */ |
| 5103 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5104 | } |
| 5105 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5106 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5107 | } |
| 5108 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5109 | 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] | 5110 | int flags, struct net_device *dev, |
| 5111 | u8 *dst, u8 *next_hop, |
| 5112 | struct mpath_info *pinfo) |
| 5113 | { |
| 5114 | void *hdr; |
| 5115 | struct nlattr *pinfoattr; |
| 5116 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5117 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5118 | if (!hdr) |
| 5119 | return -1; |
| 5120 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5121 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5122 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5123 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5124 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5125 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5126 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5127 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5128 | if (!pinfoattr) |
| 5129 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5130 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5131 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5132 | pinfo->frame_qlen)) |
| 5133 | goto nla_put_failure; |
| 5134 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5135 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5136 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5137 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5138 | pinfo->metric)) || |
| 5139 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5140 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5141 | pinfo->exptime)) || |
| 5142 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5143 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5144 | pinfo->flags)) || |
| 5145 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5146 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5147 | pinfo->discovery_timeout)) || |
| 5148 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5149 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5150 | pinfo->discovery_retries))) |
| 5151 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5152 | |
| 5153 | nla_nest_end(msg, pinfoattr); |
| 5154 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5155 | genlmsg_end(msg, hdr); |
| 5156 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5157 | |
| 5158 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5159 | genlmsg_cancel(msg, hdr); |
| 5160 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5164 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5165 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5166 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5167 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5168 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5169 | u8 dst[ETH_ALEN]; |
| 5170 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5171 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5172 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5173 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5174 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5175 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5176 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5177 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5178 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5179 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5180 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5181 | goto out_err; |
| 5182 | } |
| 5183 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5184 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5185 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5186 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5187 | } |
| 5188 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5189 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5190 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5191 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5192 | if (err == -ENOENT) |
| 5193 | break; |
| 5194 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5195 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5196 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5197 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5198 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5199 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5200 | &pinfo) < 0) |
| 5201 | goto out; |
| 5202 | |
| 5203 | path_idx++; |
| 5204 | } |
| 5205 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5206 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5207 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5208 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5209 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5210 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5211 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5215 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5216 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5217 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5218 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5219 | struct mpath_info pinfo; |
| 5220 | struct sk_buff *msg; |
| 5221 | u8 *dst = NULL; |
| 5222 | u8 next_hop[ETH_ALEN]; |
| 5223 | |
| 5224 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5225 | |
| 5226 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5227 | return -EINVAL; |
| 5228 | |
| 5229 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5230 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5231 | if (!rdev->ops->get_mpath) |
| 5232 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5233 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5234 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5235 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5236 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5237 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5238 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5239 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5240 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5241 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5242 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5243 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5244 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5245 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5246 | dev, dst, next_hop, &pinfo) < 0) { |
| 5247 | nlmsg_free(msg); |
| 5248 | return -ENOBUFS; |
| 5249 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5250 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5251 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5257 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5258 | u8 *dst = NULL; |
| 5259 | u8 *next_hop = NULL; |
| 5260 | |
| 5261 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5262 | return -EINVAL; |
| 5263 | |
| 5264 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5265 | return -EINVAL; |
| 5266 | |
| 5267 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5268 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5269 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5270 | if (!rdev->ops->change_mpath) |
| 5271 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5272 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5273 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5274 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5275 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5276 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5277 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5278 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5279 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5280 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5282 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5283 | u8 *dst = NULL; |
| 5284 | u8 *next_hop = NULL; |
| 5285 | |
| 5286 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5287 | return -EINVAL; |
| 5288 | |
| 5289 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5290 | return -EINVAL; |
| 5291 | |
| 5292 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5293 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5294 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5295 | if (!rdev->ops->add_mpath) |
| 5296 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5298 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5299 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5300 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5301 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5307 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5308 | u8 *dst = NULL; |
| 5309 | |
| 5310 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5311 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5312 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5313 | if (!rdev->ops->del_mpath) |
| 5314 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5315 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5316 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5317 | } |
| 5318 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5319 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5320 | { |
| 5321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5322 | int err; |
| 5323 | struct net_device *dev = info->user_ptr[1]; |
| 5324 | struct mpath_info pinfo; |
| 5325 | struct sk_buff *msg; |
| 5326 | u8 *dst = NULL; |
| 5327 | u8 mpp[ETH_ALEN]; |
| 5328 | |
| 5329 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5330 | |
| 5331 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5332 | return -EINVAL; |
| 5333 | |
| 5334 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5335 | |
| 5336 | if (!rdev->ops->get_mpp) |
| 5337 | return -EOPNOTSUPP; |
| 5338 | |
| 5339 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5340 | return -EOPNOTSUPP; |
| 5341 | |
| 5342 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5343 | if (err) |
| 5344 | return err; |
| 5345 | |
| 5346 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5347 | if (!msg) |
| 5348 | return -ENOMEM; |
| 5349 | |
| 5350 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5351 | dev, dst, mpp, &pinfo) < 0) { |
| 5352 | nlmsg_free(msg); |
| 5353 | return -ENOBUFS; |
| 5354 | } |
| 5355 | |
| 5356 | return genlmsg_reply(msg, info); |
| 5357 | } |
| 5358 | |
| 5359 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5360 | struct netlink_callback *cb) |
| 5361 | { |
| 5362 | struct mpath_info pinfo; |
| 5363 | struct cfg80211_registered_device *rdev; |
| 5364 | struct wireless_dev *wdev; |
| 5365 | u8 dst[ETH_ALEN]; |
| 5366 | u8 mpp[ETH_ALEN]; |
| 5367 | int path_idx = cb->args[2]; |
| 5368 | int err; |
| 5369 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5370 | rtnl_lock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5371 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5372 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5373 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5374 | |
| 5375 | if (!rdev->ops->dump_mpp) { |
| 5376 | err = -EOPNOTSUPP; |
| 5377 | goto out_err; |
| 5378 | } |
| 5379 | |
| 5380 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5381 | err = -EOPNOTSUPP; |
| 5382 | goto out_err; |
| 5383 | } |
| 5384 | |
| 5385 | while (1) { |
| 5386 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5387 | mpp, &pinfo); |
| 5388 | if (err == -ENOENT) |
| 5389 | break; |
| 5390 | if (err) |
| 5391 | goto out_err; |
| 5392 | |
| 5393 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5394 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5395 | wdev->netdev, dst, mpp, |
| 5396 | &pinfo) < 0) |
| 5397 | goto out; |
| 5398 | |
| 5399 | path_idx++; |
| 5400 | } |
| 5401 | |
| 5402 | out: |
| 5403 | cb->args[2] = path_idx; |
| 5404 | err = skb->len; |
| 5405 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5406 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5407 | return err; |
| 5408 | } |
| 5409 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5410 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5411 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5412 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5413 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5414 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5415 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5416 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5417 | |
| 5418 | memset(¶ms, 0, sizeof(params)); |
| 5419 | /* default to not changing parameters */ |
| 5420 | params.use_cts_prot = -1; |
| 5421 | params.use_short_preamble = -1; |
| 5422 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5423 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5424 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5425 | params.p2p_ctwindow = -1; |
| 5426 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5427 | |
| 5428 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5429 | params.use_cts_prot = |
| 5430 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5431 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5432 | params.use_short_preamble = |
| 5433 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5434 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5435 | params.use_short_slot_time = |
| 5436 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5437 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5438 | params.basic_rates = |
| 5439 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5440 | params.basic_rates_len = |
| 5441 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5442 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5443 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5444 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5445 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5446 | params.ht_opmode = |
| 5447 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5448 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5449 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5450 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5451 | return -EINVAL; |
| 5452 | params.p2p_ctwindow = |
| 5453 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5454 | if (params.p2p_ctwindow < 0) |
| 5455 | return -EINVAL; |
| 5456 | if (params.p2p_ctwindow != 0 && |
| 5457 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5458 | return -EINVAL; |
| 5459 | } |
| 5460 | |
| 5461 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5462 | u8 tmp; |
| 5463 | |
| 5464 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5465 | return -EINVAL; |
| 5466 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5467 | if (tmp > 1) |
| 5468 | return -EINVAL; |
| 5469 | params.p2p_opp_ps = tmp; |
| 5470 | if (params.p2p_opp_ps && |
| 5471 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5472 | return -EINVAL; |
| 5473 | } |
| 5474 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5475 | if (!rdev->ops->change_bss) |
| 5476 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5477 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5478 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5479 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5480 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5481 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5482 | wdev_lock(wdev); |
| 5483 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5484 | wdev_unlock(wdev); |
| 5485 | |
| 5486 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5487 | } |
| 5488 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5489 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5490 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5491 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5492 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5493 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5494 | u32 owner_nlportid; |
| 5495 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5496 | /* |
| 5497 | * You should only get this when cfg80211 hasn't yet initialized |
| 5498 | * completely when built-in to the kernel right between the time |
| 5499 | * window between nl80211_init() and regulatory_init(), if that is |
| 5500 | * even possible. |
| 5501 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5502 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5503 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5504 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5505 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5506 | user_reg_hint_type = |
| 5507 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5508 | else |
| 5509 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5510 | |
| 5511 | switch (user_reg_hint_type) { |
| 5512 | case NL80211_USER_REG_HINT_USER: |
| 5513 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5514 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5515 | return -EINVAL; |
| 5516 | |
| 5517 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5518 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5519 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5520 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5521 | owner_nlportid = info->snd_portid; |
| 5522 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5523 | } else { |
| 5524 | owner_nlportid = 0; |
| 5525 | is_indoor = true; |
| 5526 | } |
| 5527 | |
| 5528 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5529 | default: |
| 5530 | return -EINVAL; |
| 5531 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5534 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5535 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5536 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5538 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5539 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5540 | struct mesh_config cur_params; |
| 5541 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5542 | void *hdr; |
| 5543 | struct nlattr *pinfoattr; |
| 5544 | struct sk_buff *msg; |
| 5545 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5546 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5547 | return -EOPNOTSUPP; |
| 5548 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5549 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5550 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5551 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5552 | wdev_lock(wdev); |
| 5553 | /* If not connected, get default parameters */ |
| 5554 | if (!wdev->mesh_id_len) |
| 5555 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5556 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5557 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5558 | wdev_unlock(wdev); |
| 5559 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5560 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5561 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5562 | |
| 5563 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5564 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5565 | if (!msg) |
| 5566 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5567 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5568 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5569 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5570 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5571 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5572 | if (!pinfoattr) |
| 5573 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5574 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5575 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5576 | cur_params.dot11MeshRetryTimeout) || |
| 5577 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5578 | cur_params.dot11MeshConfirmTimeout) || |
| 5579 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5580 | cur_params.dot11MeshHoldingTimeout) || |
| 5581 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5582 | cur_params.dot11MeshMaxPeerLinks) || |
| 5583 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5584 | cur_params.dot11MeshMaxRetries) || |
| 5585 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5586 | cur_params.dot11MeshTTL) || |
| 5587 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5588 | cur_params.element_ttl) || |
| 5589 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5590 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5591 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5592 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5593 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5594 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5595 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5596 | cur_params.path_refresh_time) || |
| 5597 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5598 | cur_params.min_discovery_timeout) || |
| 5599 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5600 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5601 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5602 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5603 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5604 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5605 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5606 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5607 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5608 | cur_params.dot11MeshHWMPRootMode) || |
| 5609 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5610 | cur_params.dot11MeshHWMPRannInterval) || |
| 5611 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5612 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5613 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5614 | cur_params.dot11MeshForwarding) || |
| 5615 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5616 | cur_params.rssi_threshold) || |
| 5617 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5618 | cur_params.ht_opmode) || |
| 5619 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5620 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5621 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5622 | cur_params.dot11MeshHWMProotInterval) || |
| 5623 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5624 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5625 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5626 | cur_params.power_mode) || |
| 5627 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5628 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5629 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5630 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5631 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5632 | nla_nest_end(msg, pinfoattr); |
| 5633 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5634 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5635 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5636 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5637 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5638 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5639 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5640 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5641 | } |
| 5642 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5643 | 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] | 5644 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5645 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5646 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5647 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5648 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5649 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5650 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5651 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5652 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5653 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5654 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5655 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5656 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5657 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5658 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5659 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5660 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5661 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5662 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5663 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5664 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5665 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5666 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5667 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5668 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5669 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5670 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5671 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5672 | }; |
| 5673 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5674 | static const struct nla_policy |
| 5675 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5676 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5677 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5678 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5679 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5680 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5681 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5682 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5683 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5684 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5685 | }; |
| 5686 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5687 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5688 | { |
| 5689 | u8 val = nla_get_u8(nla); |
| 5690 | if (val < min || val > max) |
| 5691 | return -EINVAL; |
| 5692 | *out = val; |
| 5693 | return 0; |
| 5694 | } |
| 5695 | |
| 5696 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5697 | { |
| 5698 | u8 val = nla_get_u8(nla); |
| 5699 | if (val < min || val > max) |
| 5700 | return -EINVAL; |
| 5701 | *out = val; |
| 5702 | return 0; |
| 5703 | } |
| 5704 | |
| 5705 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5706 | { |
| 5707 | u16 val = nla_get_u16(nla); |
| 5708 | if (val < min || val > max) |
| 5709 | return -EINVAL; |
| 5710 | *out = val; |
| 5711 | return 0; |
| 5712 | } |
| 5713 | |
| 5714 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5715 | { |
| 5716 | u32 val = nla_get_u32(nla); |
| 5717 | if (val < min || val > max) |
| 5718 | return -EINVAL; |
| 5719 | *out = val; |
| 5720 | return 0; |
| 5721 | } |
| 5722 | |
| 5723 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5724 | { |
| 5725 | s32 val = nla_get_s32(nla); |
| 5726 | if (val < min || val > max) |
| 5727 | return -EINVAL; |
| 5728 | *out = val; |
| 5729 | return 0; |
| 5730 | } |
| 5731 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5732 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5733 | enum nl80211_mesh_power_mode min, |
| 5734 | enum nl80211_mesh_power_mode max, |
| 5735 | enum nl80211_mesh_power_mode *out) |
| 5736 | { |
| 5737 | u32 val = nla_get_u32(nla); |
| 5738 | if (val < min || val > max) |
| 5739 | return -EINVAL; |
| 5740 | *out = val; |
| 5741 | return 0; |
| 5742 | } |
| 5743 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5744 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5745 | struct mesh_config *cfg, |
| 5746 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5747 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5748 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5749 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5750 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5751 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5752 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5753 | do { \ |
| 5754 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5755 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5756 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5757 | mask |= (1 << (attr - 1)); \ |
| 5758 | } \ |
| 5759 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5760 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5761 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5762 | return -EINVAL; |
| 5763 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5764 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5765 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5766 | return -EINVAL; |
| 5767 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5768 | /* This makes sure that there aren't more than 32 mesh config |
| 5769 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5770 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5771 | |
| 5772 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5773 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5774 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5775 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5776 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5777 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5778 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5779 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5780 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5781 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5783 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5784 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5785 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5786 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5787 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5788 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5789 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5790 | 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] | 5791 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5792 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5793 | 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] | 5794 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5795 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5796 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5797 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5798 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5799 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5800 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5801 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5802 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5803 | 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] | 5804 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5805 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5806 | 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] | 5807 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5808 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5810 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5811 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5812 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5813 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5814 | 1, 65535, mask, |
| 5815 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5816 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5817 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5818 | 1, 65535, mask, |
| 5819 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5820 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5822 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5823 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5824 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5825 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5826 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5827 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5828 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5829 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5830 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5831 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5832 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5833 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5834 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5835 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5836 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5837 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5838 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5839 | 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] | 5840 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5841 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5842 | /* |
| 5843 | * Check HT operation mode based on |
| 5844 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5845 | */ |
| 5846 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5847 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5848 | |
| 5849 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5850 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5851 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5852 | return -EINVAL; |
| 5853 | |
| 5854 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5855 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5856 | return -EINVAL; |
| 5857 | |
| 5858 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5859 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5860 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5861 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 5862 | return -EINVAL; |
| 5863 | break; |
| 5864 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 5865 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 5866 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5867 | return -EINVAL; |
| 5868 | break; |
| 5869 | } |
| 5870 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | f9bd791 | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 5871 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5872 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5874 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5875 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5876 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5878 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5879 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5881 | dot11MeshHWMPconfirmationInterval, |
| 5882 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5883 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5884 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5885 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5886 | NL80211_MESH_POWER_ACTIVE, |
| 5887 | NL80211_MESH_POWER_MAX, |
| 5888 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5889 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5891 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5892 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5893 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5894 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5895 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5896 | if (mask_out) |
| 5897 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5898 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5899 | return 0; |
| 5900 | |
| 5901 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5902 | } |
| 5903 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5904 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5905 | struct mesh_setup *setup) |
| 5906 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5908 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5909 | |
| 5910 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5911 | return -EINVAL; |
| 5912 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5913 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5914 | nl80211_mesh_setup_params_policy)) |
| 5915 | return -EINVAL; |
| 5916 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5917 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5918 | setup->sync_method = |
| 5919 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5920 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5921 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5922 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5923 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5924 | setup->path_sel_proto = |
| 5925 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5926 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5927 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5928 | |
| 5929 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5930 | setup->path_metric = |
| 5931 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5932 | IEEE80211_PATH_METRIC_VENDOR : |
| 5933 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5934 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5935 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5936 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5937 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5938 | if (!is_valid_ie_attr(ieattr)) |
| 5939 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5940 | setup->ie = nla_data(ieattr); |
| 5941 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5942 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5943 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5944 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5945 | return -EINVAL; |
| 5946 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5947 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5948 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5949 | if (setup->is_secure) |
| 5950 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5951 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5952 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5953 | if (!setup->user_mpm) |
| 5954 | return -EINVAL; |
| 5955 | setup->auth_id = |
| 5956 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5957 | } |
| 5958 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5959 | return 0; |
| 5960 | } |
| 5961 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5962 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5963 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5964 | { |
| 5965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5966 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5967 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5968 | struct mesh_config cfg; |
| 5969 | u32 mask; |
| 5970 | int err; |
| 5971 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5972 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5973 | return -EOPNOTSUPP; |
| 5974 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5975 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5976 | return -EOPNOTSUPP; |
| 5977 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5978 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5979 | if (err) |
| 5980 | return err; |
| 5981 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5982 | wdev_lock(wdev); |
| 5983 | if (!wdev->mesh_id_len) |
| 5984 | err = -ENOLINK; |
| 5985 | |
| 5986 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5987 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5988 | |
| 5989 | wdev_unlock(wdev); |
| 5990 | |
| 5991 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5992 | } |
| 5993 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5994 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5995 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5996 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5997 | struct nlattr *nl_reg_rules; |
| 5998 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5999 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6000 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6001 | (regdom->dfs_region && |
| 6002 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6003 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6004 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6005 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6006 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6007 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6008 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6009 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6010 | struct nlattr *nl_reg_rule; |
| 6011 | const struct ieee80211_reg_rule *reg_rule; |
| 6012 | const struct ieee80211_freq_range *freq_range; |
| 6013 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6014 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6015 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6016 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6017 | freq_range = ®_rule->freq_range; |
| 6018 | power_rule = ®_rule->power_rule; |
| 6019 | |
| 6020 | nl_reg_rule = nla_nest_start(msg, i); |
| 6021 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6022 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6023 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6024 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6025 | if (!max_bandwidth_khz) |
| 6026 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6027 | reg_rule); |
| 6028 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6029 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6030 | reg_rule->flags) || |
| 6031 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6032 | freq_range->start_freq_khz) || |
| 6033 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6034 | freq_range->end_freq_khz) || |
| 6035 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6036 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6037 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6038 | power_rule->max_antenna_gain) || |
| 6039 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6040 | power_rule->max_eirp) || |
| 6041 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6042 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6043 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6044 | |
| 6045 | nla_nest_end(msg, nl_reg_rule); |
| 6046 | } |
| 6047 | |
| 6048 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6049 | return 0; |
| 6050 | |
| 6051 | nla_put_failure: |
| 6052 | return -EMSGSIZE; |
| 6053 | } |
| 6054 | |
| 6055 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6056 | { |
| 6057 | const struct ieee80211_regdomain *regdom = NULL; |
| 6058 | struct cfg80211_registered_device *rdev; |
| 6059 | struct wiphy *wiphy = NULL; |
| 6060 | struct sk_buff *msg; |
| 6061 | void *hdr; |
| 6062 | |
| 6063 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6064 | if (!msg) |
| 6065 | return -ENOBUFS; |
| 6066 | |
| 6067 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6068 | NL80211_CMD_GET_REG); |
| 6069 | if (!hdr) |
| 6070 | goto put_failure; |
| 6071 | |
| 6072 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6073 | bool self_managed; |
| 6074 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6075 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6076 | if (IS_ERR(rdev)) { |
| 6077 | nlmsg_free(msg); |
| 6078 | return PTR_ERR(rdev); |
| 6079 | } |
| 6080 | |
| 6081 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6082 | self_managed = wiphy->regulatory_flags & |
| 6083 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6084 | regdom = get_wiphy_regdom(wiphy); |
| 6085 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6086 | /* a self-managed-reg device must have a private regdom */ |
| 6087 | if (WARN_ON(!regdom && self_managed)) { |
| 6088 | nlmsg_free(msg); |
| 6089 | return -EINVAL; |
| 6090 | } |
| 6091 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6092 | if (regdom && |
| 6093 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6094 | goto nla_put_failure; |
| 6095 | } |
| 6096 | |
| 6097 | if (!wiphy && reg_last_request_cell_base() && |
| 6098 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6099 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6100 | goto nla_put_failure; |
| 6101 | |
| 6102 | rcu_read_lock(); |
| 6103 | |
| 6104 | if (!regdom) |
| 6105 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6106 | |
| 6107 | if (nl80211_put_regdom(regdom, msg)) |
| 6108 | goto nla_put_failure_rcu; |
| 6109 | |
| 6110 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6111 | |
| 6112 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6113 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6114 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6115 | nla_put_failure_rcu: |
| 6116 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6117 | nla_put_failure: |
| 6118 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6119 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6120 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6121 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6122 | } |
| 6123 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6124 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6125 | u32 seq, int flags, struct wiphy *wiphy, |
| 6126 | const struct ieee80211_regdomain *regdom) |
| 6127 | { |
| 6128 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6129 | NL80211_CMD_GET_REG); |
| 6130 | |
| 6131 | if (!hdr) |
| 6132 | return -1; |
| 6133 | |
| 6134 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6135 | |
| 6136 | if (nl80211_put_regdom(regdom, msg)) |
| 6137 | goto nla_put_failure; |
| 6138 | |
| 6139 | if (!wiphy && reg_last_request_cell_base() && |
| 6140 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6141 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6142 | goto nla_put_failure; |
| 6143 | |
| 6144 | if (wiphy && |
| 6145 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6146 | goto nla_put_failure; |
| 6147 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6148 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6149 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6150 | goto nla_put_failure; |
| 6151 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6152 | genlmsg_end(msg, hdr); |
| 6153 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6154 | |
| 6155 | nla_put_failure: |
| 6156 | genlmsg_cancel(msg, hdr); |
| 6157 | return -EMSGSIZE; |
| 6158 | } |
| 6159 | |
| 6160 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6161 | struct netlink_callback *cb) |
| 6162 | { |
| 6163 | const struct ieee80211_regdomain *regdom = NULL; |
| 6164 | struct cfg80211_registered_device *rdev; |
| 6165 | int err, reg_idx, start = cb->args[2]; |
| 6166 | |
| 6167 | rtnl_lock(); |
| 6168 | |
| 6169 | if (cfg80211_regdomain && start == 0) { |
| 6170 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6171 | NLM_F_MULTI, NULL, |
| 6172 | rtnl_dereference(cfg80211_regdomain)); |
| 6173 | if (err < 0) |
| 6174 | goto out_err; |
| 6175 | } |
| 6176 | |
| 6177 | /* the global regdom is idx 0 */ |
| 6178 | reg_idx = 1; |
| 6179 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6180 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6181 | if (!regdom) |
| 6182 | continue; |
| 6183 | |
| 6184 | if (++reg_idx <= start) |
| 6185 | continue; |
| 6186 | |
| 6187 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6188 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6189 | if (err < 0) { |
| 6190 | reg_idx--; |
| 6191 | break; |
| 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | cb->args[2] = reg_idx; |
| 6196 | err = skb->len; |
| 6197 | out_err: |
| 6198 | rtnl_unlock(); |
| 6199 | return err; |
| 6200 | } |
| 6201 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6202 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6203 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6204 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6205 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6206 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6207 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6208 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6209 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6210 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6211 | }; |
| 6212 | |
| 6213 | static int parse_reg_rule(struct nlattr *tb[], |
| 6214 | struct ieee80211_reg_rule *reg_rule) |
| 6215 | { |
| 6216 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6217 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6218 | |
| 6219 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6220 | return -EINVAL; |
| 6221 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6222 | return -EINVAL; |
| 6223 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6224 | return -EINVAL; |
| 6225 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6226 | return -EINVAL; |
| 6227 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6228 | return -EINVAL; |
| 6229 | |
| 6230 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6231 | |
| 6232 | freq_range->start_freq_khz = |
| 6233 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6234 | freq_range->end_freq_khz = |
| 6235 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6236 | freq_range->max_bandwidth_khz = |
| 6237 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6238 | |
| 6239 | power_rule->max_eirp = |
| 6240 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6241 | |
| 6242 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6243 | power_rule->max_antenna_gain = |
| 6244 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6245 | |
| 6246 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6247 | reg_rule->dfs_cac_ms = |
| 6248 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6249 | |
| 6250 | return 0; |
| 6251 | } |
| 6252 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6253 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6254 | { |
| 6255 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6256 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6257 | char *alpha2; |
| 6258 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6259 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6260 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6261 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6262 | |
| 6263 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6264 | return -EINVAL; |
| 6265 | |
| 6266 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6267 | return -EINVAL; |
| 6268 | |
| 6269 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6270 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6271 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6272 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6273 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6274 | 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] | 6275 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6276 | num_rules++; |
| 6277 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6278 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6281 | if (!reg_is_valid_request(alpha2)) |
| 6282 | return -EINVAL; |
| 6283 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6284 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6285 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6286 | |
| 6287 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6288 | if (!rd) |
| 6289 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6290 | |
| 6291 | rd->n_reg_rules = num_rules; |
| 6292 | rd->alpha2[0] = alpha2[0]; |
| 6293 | rd->alpha2[1] = alpha2[1]; |
| 6294 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6295 | /* |
| 6296 | * Disable DFS master mode if the DFS region was |
| 6297 | * not supported or known on this kernel. |
| 6298 | */ |
| 6299 | if (reg_supported_dfs_region(dfs_region)) |
| 6300 | rd->dfs_region = dfs_region; |
| 6301 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6302 | 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] | 6303 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6304 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 6305 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 6306 | reg_rule_policy); |
| 6307 | if (r) |
| 6308 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6309 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6310 | if (r) |
| 6311 | goto bad_reg; |
| 6312 | |
| 6313 | rule_idx++; |
| 6314 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6315 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6316 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6317 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6318 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6319 | } |
| 6320 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6321 | /* set_regdom takes ownership of rd */ |
| 6322 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6323 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6324 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6325 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6326 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6327 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6328 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6329 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6330 | { |
| 6331 | struct nlattr *attr1, *attr2; |
| 6332 | int n_channels = 0, tmp1, tmp2; |
| 6333 | |
| 6334 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6335 | n_channels++; |
| 6336 | /* |
| 6337 | * Some hardware has a limited channel list for |
| 6338 | * scanning, and it is pretty much nonsensical |
| 6339 | * to scan for a channel twice, so disallow that |
| 6340 | * and don't require drivers to check that the |
| 6341 | * channel list they get isn't longer than what |
| 6342 | * they can scan, as long as they can scan all |
| 6343 | * the channels they registered at once. |
| 6344 | */ |
| 6345 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6346 | if (attr1 != attr2 && |
| 6347 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6348 | return 0; |
| 6349 | } |
| 6350 | |
| 6351 | return n_channels; |
| 6352 | } |
| 6353 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6354 | 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] | 6355 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6356 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6360 | struct cfg80211_bss_selection *bss_select) |
| 6361 | { |
| 6362 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6363 | struct nlattr *nest; |
| 6364 | int err; |
| 6365 | bool found = false; |
| 6366 | int i; |
| 6367 | |
| 6368 | /* only process one nested attribute */ |
| 6369 | nest = nla_data(nla); |
| 6370 | if (!nla_ok(nest, nla_len(nest))) |
| 6371 | return -EINVAL; |
| 6372 | |
| 6373 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), |
| 6374 | nla_len(nest), nl80211_bss_select_policy); |
| 6375 | if (err) |
| 6376 | return err; |
| 6377 | |
| 6378 | /* only one attribute may be given */ |
| 6379 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6380 | if (attr[i]) { |
| 6381 | if (found) |
| 6382 | return -EINVAL; |
| 6383 | found = true; |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6388 | |
| 6389 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6390 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6391 | |
| 6392 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6393 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6394 | bss_select->param.band_pref = |
| 6395 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6396 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6397 | return -EINVAL; |
| 6398 | } |
| 6399 | |
| 6400 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6401 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6402 | |
| 6403 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6404 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6405 | bss_select->param.adjust.band = adj_param->band; |
| 6406 | bss_select->param.adjust.delta = adj_param->delta; |
| 6407 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6408 | return -EINVAL; |
| 6409 | } |
| 6410 | |
| 6411 | /* user-space did not provide behaviour attribute */ |
| 6412 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6413 | return -EINVAL; |
| 6414 | |
| 6415 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6416 | return -EINVAL; |
| 6417 | |
| 6418 | return 0; |
| 6419 | } |
| 6420 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6421 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6422 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6423 | { |
| 6424 | int i; |
| 6425 | |
| 6426 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6427 | eth_zero_addr(mac_addr); |
| 6428 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6429 | mac_addr[0] = 0x2; |
| 6430 | mac_addr_mask[0] = 0x3; |
| 6431 | |
| 6432 | return 0; |
| 6433 | } |
| 6434 | |
| 6435 | /* need both or none */ |
| 6436 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6437 | return -EINVAL; |
| 6438 | |
| 6439 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6440 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6441 | |
| 6442 | /* don't allow or configure an mcast address */ |
| 6443 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6444 | is_multicast_ether_addr(mac_addr)) |
| 6445 | return -EINVAL; |
| 6446 | |
| 6447 | /* |
| 6448 | * allow users to pass a MAC address that has bits set outside |
| 6449 | * of the mask, but don't bother drivers with having to deal |
| 6450 | * with such bits |
| 6451 | */ |
| 6452 | for (i = 0; i < ETH_ALEN; i++) |
| 6453 | mac_addr[i] &= mac_addr_mask[i]; |
| 6454 | |
| 6455 | return 0; |
| 6456 | } |
| 6457 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6458 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6461 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6462 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6463 | struct nlattr *attr; |
| 6464 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6465 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6466 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6467 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6468 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6469 | return -EINVAL; |
| 6470 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6471 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6472 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6473 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6474 | return -EOPNOTSUPP; |
| 6475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6476 | if (!rdev->ops->scan) |
| 6477 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6478 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6479 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6480 | err = -EBUSY; |
| 6481 | goto unlock; |
| 6482 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6483 | |
| 6484 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6485 | n_channels = validate_scan_freqs( |
| 6486 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6487 | if (!n_channels) { |
| 6488 | err = -EINVAL; |
| 6489 | goto unlock; |
| 6490 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6491 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6492 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6496 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6497 | n_ssids++; |
| 6498 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6499 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6500 | err = -EINVAL; |
| 6501 | goto unlock; |
| 6502 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6503 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6504 | if (info->attrs[NL80211_ATTR_IE]) |
| 6505 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6506 | else |
| 6507 | ie_len = 0; |
| 6508 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6509 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6510 | err = -EINVAL; |
| 6511 | goto unlock; |
| 6512 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6513 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6514 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6515 | + sizeof(*request->ssids) * n_ssids |
| 6516 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6517 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6518 | if (!request) { |
| 6519 | err = -ENOMEM; |
| 6520 | goto unlock; |
| 6521 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6522 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6523 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6524 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6525 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6526 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6527 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6528 | request->ie = (void *)(request->ssids + n_ssids); |
| 6529 | else |
| 6530 | request->ie = (void *)(request->channels + n_channels); |
| 6531 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6533 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6534 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6535 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6536 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6537 | struct ieee80211_channel *chan; |
| 6538 | |
| 6539 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6540 | |
| 6541 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6542 | err = -EINVAL; |
| 6543 | goto out_free; |
| 6544 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6545 | |
| 6546 | /* ignore disabled channels */ |
| 6547 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6548 | continue; |
| 6549 | |
| 6550 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6551 | i++; |
| 6552 | } |
| 6553 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6554 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6555 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6556 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6557 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6558 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6559 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6560 | if (!wiphy->bands[band]) |
| 6561 | continue; |
| 6562 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6563 | struct ieee80211_channel *chan; |
| 6564 | |
| 6565 | chan = &wiphy->bands[band]->channels[j]; |
| 6566 | |
| 6567 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6568 | continue; |
| 6569 | |
| 6570 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6571 | i++; |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6576 | if (!i) { |
| 6577 | err = -EINVAL; |
| 6578 | goto out_free; |
| 6579 | } |
| 6580 | |
| 6581 | request->n_channels = i; |
| 6582 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6583 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6584 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6585 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6586 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6587 | err = -EINVAL; |
| 6588 | goto out_free; |
| 6589 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6590 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6591 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6592 | i++; |
| 6593 | } |
| 6594 | } |
| 6595 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6596 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6597 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6598 | memcpy((void *)request->ie, |
| 6599 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6600 | request->ie_len); |
| 6601 | } |
| 6602 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6603 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6604 | if (wiphy->bands[i]) |
| 6605 | request->rates[i] = |
| 6606 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6607 | |
| 6608 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6609 | nla_for_each_nested(attr, |
| 6610 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6611 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6612 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6613 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6614 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6615 | err = -EINVAL; |
| 6616 | goto out_free; |
| 6617 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6618 | |
| 6619 | if (!wiphy->bands[band]) |
| 6620 | continue; |
| 6621 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6622 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6623 | nla_data(attr), |
| 6624 | nla_len(attr), |
| 6625 | &request->rates[band]); |
| 6626 | if (err) |
| 6627 | goto out_free; |
| 6628 | } |
| 6629 | } |
| 6630 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6631 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6632 | if (!wiphy_ext_feature_isset(wiphy, |
| 6633 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6634 | err = -EOPNOTSUPP; |
| 6635 | goto out_free; |
| 6636 | } |
| 6637 | |
| 6638 | request->duration = |
| 6639 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6640 | request->duration_mandatory = |
| 6641 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6642 | } |
| 6643 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6644 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6645 | request->flags = nla_get_u32( |
| 6646 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6647 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6648 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6649 | err = -EOPNOTSUPP; |
| 6650 | goto out_free; |
| 6651 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6652 | |
| 6653 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6654 | if (!(wiphy->features & |
| 6655 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6656 | err = -EOPNOTSUPP; |
| 6657 | goto out_free; |
| 6658 | } |
| 6659 | |
| 6660 | if (wdev->current_bss) { |
| 6661 | err = -EOPNOTSUPP; |
| 6662 | goto out_free; |
| 6663 | } |
| 6664 | |
| 6665 | err = nl80211_parse_random_mac(info->attrs, |
| 6666 | request->mac_addr, |
| 6667 | request->mac_addr_mask); |
| 6668 | if (err) |
| 6669 | goto out_free; |
| 6670 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6671 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6672 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6673 | request->no_cck = |
| 6674 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6675 | |
Vamsi Krishna | 4581639 | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6676 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6677 | * BSSID to scan for. This was problematic because that same attribute |
| 6678 | * was already used for another purpose (local random MAC address). The |
| 6679 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6680 | * compatibility with older userspace components, also use the |
| 6681 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6682 | * the specific BSSID use case instead of the random MAC address |
| 6683 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6684 | */ |
| 6685 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6686 | memcpy(request->bssid, |
| 6687 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6688 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6689 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6690 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6691 | ETH_ALEN); |
| 6692 | else |
| 6693 | eth_broadcast_addr(request->bssid); |
| 6694 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6695 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6696 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6697 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6698 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6699 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6700 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6701 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6702 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6703 | nl80211_send_scan_start(rdev, wdev); |
| 6704 | if (wdev->netdev) |
| 6705 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6706 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6707 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6708 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6709 | kfree(request); |
| 6710 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6711 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6712 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6713 | return err; |
| 6714 | } |
| 6715 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6716 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6717 | { |
| 6718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6719 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6720 | |
| 6721 | if (!rdev->ops->abort_scan) |
| 6722 | return -EOPNOTSUPP; |
| 6723 | |
| 6724 | if (rdev->scan_msg) |
| 6725 | return 0; |
| 6726 | |
| 6727 | if (!rdev->scan_req) |
| 6728 | return -ENOENT; |
| 6729 | |
| 6730 | rdev_abort_scan(rdev, wdev); |
| 6731 | return 0; |
| 6732 | } |
| 6733 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6734 | static int |
| 6735 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6736 | struct cfg80211_sched_scan_request *request, |
| 6737 | struct nlattr **attrs) |
| 6738 | { |
| 6739 | int tmp, err, i = 0; |
| 6740 | struct nlattr *attr; |
| 6741 | |
| 6742 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6743 | u32 interval; |
| 6744 | |
| 6745 | /* |
| 6746 | * If scan plans are not specified, |
| 6747 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6748 | * case one scan plan will be set with the specified scan |
| 6749 | * interval and infinite number of iterations. |
| 6750 | */ |
| 6751 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6752 | return -EINVAL; |
| 6753 | |
| 6754 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6755 | if (!interval) |
| 6756 | return -EINVAL; |
| 6757 | |
| 6758 | request->scan_plans[0].interval = |
| 6759 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6760 | if (!request->scan_plans[0].interval) |
| 6761 | return -EINVAL; |
| 6762 | |
| 6763 | if (request->scan_plans[0].interval > |
| 6764 | wiphy->max_sched_scan_plan_interval) |
| 6765 | request->scan_plans[0].interval = |
| 6766 | wiphy->max_sched_scan_plan_interval; |
| 6767 | |
| 6768 | return 0; |
| 6769 | } |
| 6770 | |
| 6771 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6772 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6773 | |
| 6774 | if (WARN_ON(i >= n_plans)) |
| 6775 | return -EINVAL; |
| 6776 | |
| 6777 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6778 | nla_data(attr), nla_len(attr), |
| 6779 | nl80211_plan_policy); |
| 6780 | if (err) |
| 6781 | return err; |
| 6782 | |
| 6783 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6784 | return -EINVAL; |
| 6785 | |
| 6786 | request->scan_plans[i].interval = |
| 6787 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6788 | if (!request->scan_plans[i].interval || |
| 6789 | request->scan_plans[i].interval > |
| 6790 | wiphy->max_sched_scan_plan_interval) |
| 6791 | return -EINVAL; |
| 6792 | |
| 6793 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6794 | request->scan_plans[i].iterations = |
| 6795 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6796 | if (!request->scan_plans[i].iterations || |
| 6797 | (request->scan_plans[i].iterations > |
| 6798 | wiphy->max_sched_scan_plan_iterations)) |
| 6799 | return -EINVAL; |
| 6800 | } else if (i < n_plans - 1) { |
| 6801 | /* |
| 6802 | * All scan plans but the last one must specify |
| 6803 | * a finite number of iterations |
| 6804 | */ |
| 6805 | return -EINVAL; |
| 6806 | } |
| 6807 | |
| 6808 | i++; |
| 6809 | } |
| 6810 | |
| 6811 | /* |
| 6812 | * The last scan plan must not specify the number of |
| 6813 | * iterations, it is supposed to run infinitely |
| 6814 | */ |
| 6815 | if (request->scan_plans[n_plans - 1].iterations) |
| 6816 | return -EINVAL; |
| 6817 | |
| 6818 | return 0; |
| 6819 | } |
| 6820 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6821 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6822 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6823 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6824 | { |
| 6825 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6826 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6827 | 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] | 6828 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6829 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6830 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6831 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6832 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6833 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6834 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6835 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6836 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6837 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6838 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6839 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6840 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6841 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6842 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6843 | } |
| 6844 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6845 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6846 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6847 | tmp) |
| 6848 | n_ssids++; |
| 6849 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6850 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6851 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6852 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6853 | /* |
| 6854 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6855 | * the old implementation, matchsets containing only the RSSI attribute |
| 6856 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6857 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6858 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6859 | * older userspace that treated a matchset with only the RSSI as the |
| 6860 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6861 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6862 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6863 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6864 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6865 | tmp) { |
| 6866 | struct nlattr *rssi; |
| 6867 | |
| 6868 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6869 | nla_data(attr), nla_len(attr), |
| 6870 | nl80211_match_policy); |
| 6871 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6872 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6873 | /* add other standalone attributes here */ |
| 6874 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6875 | n_match_sets++; |
| 6876 | continue; |
| 6877 | } |
| 6878 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6879 | if (rssi) |
| 6880 | default_match_rssi = nla_get_s32(rssi); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | /* However, if there's no other matchset, add the RSSI one */ |
| 6885 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6886 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6887 | |
| 6888 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6889 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6890 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6891 | if (attrs[NL80211_ATTR_IE]) |
| 6892 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6893 | else |
| 6894 | ie_len = 0; |
| 6895 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6896 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6897 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6898 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6899 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6900 | /* |
| 6901 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6902 | * each scan plan already specifies its own interval |
| 6903 | */ |
| 6904 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6905 | return ERR_PTR(-EINVAL); |
| 6906 | |
| 6907 | nla_for_each_nested(attr, |
| 6908 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6909 | n_plans++; |
| 6910 | } else { |
| 6911 | /* |
| 6912 | * The scan interval attribute is kept for backward |
| 6913 | * compatibility. If no scan plans are specified and sched scan |
| 6914 | * interval is specified, one scan plan will be set with this |
| 6915 | * scan interval and infinite number of iterations. |
| 6916 | */ |
| 6917 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6918 | return ERR_PTR(-EINVAL); |
| 6919 | |
| 6920 | n_plans = 1; |
| 6921 | } |
| 6922 | |
| 6923 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6924 | return ERR_PTR(-EINVAL); |
| 6925 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6926 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6927 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6928 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6929 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6930 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6931 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6932 | if (!request) |
| 6933 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6934 | |
| 6935 | if (n_ssids) |
| 6936 | request->ssids = (void *)&request->channels[n_channels]; |
| 6937 | request->n_ssids = n_ssids; |
| 6938 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6939 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6940 | request->ie = (void *)(request->ssids + n_ssids); |
| 6941 | else |
| 6942 | request->ie = (void *)(request->channels + n_channels); |
| 6943 | } |
| 6944 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6945 | if (n_match_sets) { |
| 6946 | if (request->ie) |
| 6947 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6948 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6949 | request->match_sets = |
| 6950 | (void *)(request->ssids + n_ssids); |
| 6951 | else |
| 6952 | request->match_sets = |
| 6953 | (void *)(request->channels + n_channels); |
| 6954 | } |
| 6955 | request->n_match_sets = n_match_sets; |
| 6956 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6957 | if (n_match_sets) |
| 6958 | request->scan_plans = (void *)(request->match_sets + |
| 6959 | n_match_sets); |
| 6960 | else if (request->ie) |
| 6961 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6962 | else if (n_ssids) |
| 6963 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6964 | else |
| 6965 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6966 | |
| 6967 | request->n_scan_plans = n_plans; |
| 6968 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6969 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6970 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6971 | /* user specified, bail out if channel not found */ |
| 6972 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6973 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6974 | tmp) { |
| 6975 | struct ieee80211_channel *chan; |
| 6976 | |
| 6977 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6978 | |
| 6979 | if (!chan) { |
| 6980 | err = -EINVAL; |
| 6981 | goto out_free; |
| 6982 | } |
| 6983 | |
| 6984 | /* ignore disabled channels */ |
| 6985 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6986 | continue; |
| 6987 | |
| 6988 | request->channels[i] = chan; |
| 6989 | i++; |
| 6990 | } |
| 6991 | } else { |
| 6992 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6993 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6994 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6995 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6996 | if (!wiphy->bands[band]) |
| 6997 | continue; |
| 6998 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6999 | struct ieee80211_channel *chan; |
| 7000 | |
| 7001 | chan = &wiphy->bands[band]->channels[j]; |
| 7002 | |
| 7003 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7004 | continue; |
| 7005 | |
| 7006 | request->channels[i] = chan; |
| 7007 | i++; |
| 7008 | } |
| 7009 | } |
| 7010 | } |
| 7011 | |
| 7012 | if (!i) { |
| 7013 | err = -EINVAL; |
| 7014 | goto out_free; |
| 7015 | } |
| 7016 | |
| 7017 | request->n_channels = i; |
| 7018 | |
| 7019 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7020 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7021 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7022 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7023 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7024 | err = -EINVAL; |
| 7025 | goto out_free; |
| 7026 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7027 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7028 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7029 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7030 | i++; |
| 7031 | } |
| 7032 | } |
| 7033 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7034 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7035 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7036 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7037 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7038 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 7039 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7040 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7041 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 7042 | nla_data(attr), nla_len(attr), |
| 7043 | nl80211_match_policy); |
| 7044 | if (err) |
| 7045 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7046 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7047 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7048 | if (WARN_ON(i >= n_match_sets)) { |
| 7049 | /* this indicates a programming error, |
| 7050 | * the loop above should have verified |
| 7051 | * things properly |
| 7052 | */ |
| 7053 | err = -EINVAL; |
| 7054 | goto out_free; |
| 7055 | } |
| 7056 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7057 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7058 | err = -EINVAL; |
| 7059 | goto out_free; |
| 7060 | } |
| 7061 | memcpy(request->match_sets[i].ssid.ssid, |
| 7062 | nla_data(ssid), nla_len(ssid)); |
| 7063 | request->match_sets[i].ssid.ssid_len = |
| 7064 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7065 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7066 | request->match_sets[i].rssi_thold = |
| 7067 | default_match_rssi; |
| 7068 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7069 | if (rssi) |
| 7070 | request->match_sets[i].rssi_thold = |
| 7071 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7072 | } |
| 7073 | i++; |
| 7074 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7075 | |
| 7076 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7077 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7078 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7079 | |
| 7080 | request->min_rssi_thold = INT_MAX; |
| 7081 | for (i = 0; i < n_match_sets; i++) |
| 7082 | request->min_rssi_thold = |
| 7083 | min(request->match_sets[i].rssi_thold, |
| 7084 | request->min_rssi_thold); |
| 7085 | } else { |
| 7086 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7087 | } |
| 7088 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7089 | if (ie_len) { |
| 7090 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7091 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7092 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7093 | request->ie_len); |
| 7094 | } |
| 7095 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7096 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7097 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7098 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 7099 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7100 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7101 | err = -EOPNOTSUPP; |
| 7102 | goto out_free; |
| 7103 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7104 | |
| 7105 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7106 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 7107 | |
| 7108 | if (!wdev) /* must be net-detect */ |
| 7109 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7110 | |
| 7111 | if (!(wiphy->features & flg)) { |
| 7112 | err = -EOPNOTSUPP; |
| 7113 | goto out_free; |
| 7114 | } |
| 7115 | |
| 7116 | if (wdev && wdev->current_bss) { |
| 7117 | err = -EOPNOTSUPP; |
| 7118 | goto out_free; |
| 7119 | } |
| 7120 | |
| 7121 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 7122 | request->mac_addr_mask); |
| 7123 | if (err) |
| 7124 | goto out_free; |
| 7125 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7126 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7127 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7128 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7129 | request->delay = |
| 7130 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7131 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7132 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7133 | if (err) |
| 7134 | goto out_free; |
| 7135 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7136 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7137 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7138 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7139 | |
| 7140 | out_free: |
| 7141 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7142 | return ERR_PTR(err); |
| 7143 | } |
| 7144 | |
| 7145 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7146 | struct genl_info *info) |
| 7147 | { |
| 7148 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7149 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7150 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7151 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7152 | int err; |
| 7153 | |
| 7154 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7155 | !rdev->ops->sched_scan_start) |
| 7156 | return -EOPNOTSUPP; |
| 7157 | |
| 7158 | if (rdev->sched_scan_req) |
| 7159 | return -EINPROGRESS; |
| 7160 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7161 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 7162 | info->attrs); |
| 7163 | |
| 7164 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7165 | if (err) |
| 7166 | goto out_err; |
| 7167 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7168 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7169 | if (err) |
| 7170 | goto out_free; |
| 7171 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7172 | sched_scan_req->dev = dev; |
| 7173 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7174 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7175 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7176 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7177 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7178 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7179 | |
| 7180 | nl80211_send_sched_scan(rdev, dev, |
| 7181 | NL80211_CMD_START_SCHED_SCAN); |
| 7182 | return 0; |
| 7183 | |
| 7184 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7185 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7186 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7187 | return err; |
| 7188 | } |
| 7189 | |
| 7190 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7191 | struct genl_info *info) |
| 7192 | { |
| 7193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7194 | |
| 7195 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7196 | !rdev->ops->sched_scan_stop) |
| 7197 | return -EOPNOTSUPP; |
| 7198 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7199 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7200 | } |
| 7201 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7202 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7203 | struct genl_info *info) |
| 7204 | { |
| 7205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7206 | struct net_device *dev = info->user_ptr[1]; |
| 7207 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7208 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7209 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7210 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7211 | int err; |
| 7212 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7213 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7214 | if (dfs_region == NL80211_DFS_UNSET) |
| 7215 | return -EINVAL; |
| 7216 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7217 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7218 | if (err) |
| 7219 | return err; |
| 7220 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7221 | if (netif_carrier_ok(dev)) |
| 7222 | return -EBUSY; |
| 7223 | |
Amar Singhal | 42839af | 2014-03-19 18:36:58 -0700 | [diff] [blame] | 7224 | if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD) |
| 7225 | return -EOPNOTSUPP; |
| 7226 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7227 | if (wdev->cac_started) |
| 7228 | return -EBUSY; |
| 7229 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7230 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7231 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7232 | if (err < 0) |
| 7233 | return err; |
| 7234 | |
| 7235 | if (err == 0) |
| 7236 | return -EINVAL; |
| 7237 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7238 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7239 | return -EINVAL; |
| 7240 | |
| 7241 | if (!rdev->ops->start_radar_detection) |
| 7242 | return -EOPNOTSUPP; |
| 7243 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7244 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7245 | if (WARN_ON(!cac_time_ms)) |
| 7246 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7247 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7248 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7249 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7250 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7251 | wdev->cac_started = true; |
| 7252 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7253 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7254 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7255 | return err; |
| 7256 | } |
| 7257 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7258 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7259 | { |
| 7260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7261 | struct net_device *dev = info->user_ptr[1]; |
| 7262 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7263 | struct cfg80211_csa_settings params; |
| 7264 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7265 | * function is called under RTNL lock, so this should not be a problem. |
| 7266 | */ |
| 7267 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7268 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7269 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7270 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7271 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7272 | |
| 7273 | if (!rdev->ops->channel_switch || |
| 7274 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7275 | return -EOPNOTSUPP; |
| 7276 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7277 | switch (dev->ieee80211_ptr->iftype) { |
| 7278 | case NL80211_IFTYPE_AP: |
| 7279 | case NL80211_IFTYPE_P2P_GO: |
| 7280 | need_new_beacon = true; |
| 7281 | |
| 7282 | /* useless if AP is not running */ |
| 7283 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7284 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7285 | break; |
| 7286 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7287 | if (!wdev->ssid_len) |
| 7288 | return -ENOTCONN; |
| 7289 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7290 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7291 | if (!wdev->mesh_id_len) |
| 7292 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7293 | break; |
| 7294 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7295 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7296 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7297 | |
| 7298 | memset(¶ms, 0, sizeof(params)); |
| 7299 | |
| 7300 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7301 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7302 | return -EINVAL; |
| 7303 | |
| 7304 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7305 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7306 | return -EINVAL; |
| 7307 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7308 | /* Even though the attribute is u32, the specification says |
| 7309 | * u8, so let's make sure we don't overflow. |
| 7310 | */ |
| 7311 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7312 | if (cs_count > 255) |
| 7313 | return -EINVAL; |
| 7314 | |
| 7315 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7316 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7317 | if (!need_new_beacon) |
| 7318 | goto skip_beacons; |
| 7319 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7320 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7321 | if (err) |
| 7322 | return err; |
| 7323 | |
| 7324 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7325 | info->attrs[NL80211_ATTR_CSA_IES], |
| 7326 | nl80211_policy); |
| 7327 | if (err) |
| 7328 | return err; |
| 7329 | |
| 7330 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7331 | if (err) |
| 7332 | return err; |
| 7333 | |
| 7334 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7335 | return -EINVAL; |
| 7336 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7337 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7338 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7339 | return -EINVAL; |
| 7340 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7341 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7342 | if (rdev->wiphy.max_num_csa_counters && |
| 7343 | (params.n_counter_offsets_beacon > |
| 7344 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7345 | return -EINVAL; |
| 7346 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7347 | params.counter_offsets_beacon = |
| 7348 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7349 | |
| 7350 | /* sanity checks - counters should fit and be the same */ |
| 7351 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7352 | u16 offset = params.counter_offsets_beacon[i]; |
| 7353 | |
| 7354 | if (offset >= params.beacon_csa.tail_len) |
| 7355 | return -EINVAL; |
| 7356 | |
| 7357 | if (params.beacon_csa.tail[offset] != params.count) |
| 7358 | return -EINVAL; |
| 7359 | } |
| 7360 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7361 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7362 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7363 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7364 | return -EINVAL; |
| 7365 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7366 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7367 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7368 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7369 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7370 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7371 | |
| 7372 | params.counter_offsets_presp = |
| 7373 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7374 | |
| 7375 | /* sanity checks - counters should fit and be the same */ |
| 7376 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7377 | u16 offset = params.counter_offsets_presp[i]; |
| 7378 | |
| 7379 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7380 | return -EINVAL; |
| 7381 | |
| 7382 | if (params.beacon_csa.probe_resp[offset] != |
| 7383 | params.count) |
| 7384 | return -EINVAL; |
| 7385 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7386 | } |
| 7387 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7388 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7389 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7390 | if (err) |
| 7391 | return err; |
| 7392 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7393 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7394 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7395 | return -EINVAL; |
| 7396 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7397 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7398 | ¶ms.chandef, |
| 7399 | wdev->iftype); |
| 7400 | if (err < 0) |
| 7401 | return err; |
| 7402 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 7403 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7404 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7405 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7406 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7407 | params.block_tx = true; |
| 7408 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7409 | wdev_lock(wdev); |
| 7410 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7411 | wdev_unlock(wdev); |
| 7412 | |
| 7413 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7414 | } |
| 7415 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7416 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7417 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7418 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7419 | struct wireless_dev *wdev, |
| 7420 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7421 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7422 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7423 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7424 | void *hdr; |
| 7425 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7426 | |
| 7427 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7428 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7429 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7430 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7431 | if (!hdr) |
| 7432 | return -1; |
| 7433 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7434 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7435 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7436 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7437 | goto nla_put_failure; |
| 7438 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7439 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7440 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7441 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7442 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7443 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7444 | |
| 7445 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7446 | if (!bss) |
| 7447 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7448 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7449 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7450 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7451 | |
| 7452 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7453 | /* indicate whether we have probe response data or not */ |
| 7454 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7455 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7456 | goto fail_unlock_rcu; |
| 7457 | |
| 7458 | /* this pointer prefers to be pointed to probe response data |
| 7459 | * but is always valid |
| 7460 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7461 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7462 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7463 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7464 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7465 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7466 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7467 | ies->len, ies->data)) |
| 7468 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7469 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7470 | |
| 7471 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7472 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7473 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7474 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7475 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7476 | goto fail_unlock_rcu; |
| 7477 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7478 | ies->len, ies->data)) |
| 7479 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7480 | } |
| 7481 | rcu_read_unlock(); |
| 7482 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7483 | if (res->beacon_interval && |
| 7484 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7485 | goto nla_put_failure; |
| 7486 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7487 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7488 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7489 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7490 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7491 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7492 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7493 | if (intbss->parent_tsf && |
| 7494 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7495 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7496 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7497 | intbss->parent_bssid))) |
| 7498 | goto nla_put_failure; |
| 7499 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7500 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7501 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7502 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7503 | goto nla_put_failure; |
| 7504 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7505 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7506 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7507 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7508 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7509 | break; |
| 7510 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7511 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7512 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7513 | break; |
| 7514 | default: |
| 7515 | break; |
| 7516 | } |
| 7517 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7518 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7519 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7520 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7521 | if (intbss == wdev->current_bss && |
| 7522 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7523 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7524 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7525 | break; |
| 7526 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7527 | if (intbss == wdev->current_bss && |
| 7528 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7529 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7530 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7531 | break; |
| 7532 | default: |
| 7533 | break; |
| 7534 | } |
| 7535 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7536 | nla_nest_end(msg, bss); |
| 7537 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7538 | genlmsg_end(msg, hdr); |
| 7539 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7540 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7541 | fail_unlock_rcu: |
| 7542 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7543 | nla_put_failure: |
| 7544 | genlmsg_cancel(msg, hdr); |
| 7545 | return -EMSGSIZE; |
| 7546 | } |
| 7547 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7548 | 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] | 7549 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7550 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7551 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7552 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7553 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7554 | int err; |
| 7555 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7556 | rtnl_lock(); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7557 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7558 | if (err) { |
| 7559 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7560 | return err; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7561 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7562 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7563 | wdev_lock(wdev); |
| 7564 | spin_lock_bh(&rdev->bss_lock); |
| 7565 | cfg80211_bss_expire(rdev); |
| 7566 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7567 | cb->seq = rdev->bss_generation; |
| 7568 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7569 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7570 | if (++idx <= start) |
| 7571 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7572 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7573 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7574 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7575 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7576 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7577 | } |
| 7578 | } |
| 7579 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7580 | spin_unlock_bh(&rdev->bss_lock); |
| 7581 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7582 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7583 | cb->args[2] = idx; |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7584 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7585 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7586 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7587 | } |
| 7588 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7589 | 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] | 7590 | int flags, struct net_device *dev, |
| 7591 | bool allow_radio_stats, |
| 7592 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7593 | { |
| 7594 | void *hdr; |
| 7595 | struct nlattr *infoattr; |
| 7596 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7597 | /* skip radio stats if userspace didn't request them */ |
| 7598 | if (!survey->channel && !allow_radio_stats) |
| 7599 | return 0; |
| 7600 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7601 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7602 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7603 | if (!hdr) |
| 7604 | return -ENOMEM; |
| 7605 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7606 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7607 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7608 | |
| 7609 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7610 | if (!infoattr) |
| 7611 | goto nla_put_failure; |
| 7612 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7613 | if (survey->channel && |
| 7614 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7615 | survey->channel->center_freq)) |
| 7616 | goto nla_put_failure; |
| 7617 | |
| 7618 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7619 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7620 | goto nla_put_failure; |
| 7621 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7622 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7623 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7624 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7625 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7626 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7627 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7628 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7629 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7630 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7631 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7632 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7633 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7634 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7635 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7636 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7637 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7638 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7639 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7640 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7641 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7642 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7643 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7644 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7645 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7646 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7647 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7648 | |
| 7649 | nla_nest_end(msg, infoattr); |
| 7650 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7651 | genlmsg_end(msg, hdr); |
| 7652 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7653 | |
| 7654 | nla_put_failure: |
| 7655 | genlmsg_cancel(msg, hdr); |
| 7656 | return -EMSGSIZE; |
| 7657 | } |
| 7658 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7659 | 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] | 7660 | { |
| 7661 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7662 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7663 | struct wireless_dev *wdev; |
| 7664 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7665 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7666 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7667 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7668 | rtnl_lock(); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7669 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7670 | if (res) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7671 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7672 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7673 | /* prepare_wdev_dump parsed the attributes */ |
| 7674 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 7675 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7676 | if (!wdev->netdev) { |
| 7677 | res = -EINVAL; |
| 7678 | goto out_err; |
| 7679 | } |
| 7680 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7681 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7682 | res = -EOPNOTSUPP; |
| 7683 | goto out_err; |
| 7684 | } |
| 7685 | |
| 7686 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7687 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7688 | if (res == -ENOENT) |
| 7689 | break; |
| 7690 | if (res) |
| 7691 | goto out_err; |
| 7692 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7693 | /* don't send disabled channels, but do send non-channel data */ |
| 7694 | if (survey.channel && |
| 7695 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7696 | survey_idx++; |
| 7697 | continue; |
| 7698 | } |
| 7699 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7700 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7701 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7702 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7703 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7704 | goto out; |
| 7705 | survey_idx++; |
| 7706 | } |
| 7707 | |
| 7708 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7709 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7710 | res = skb->len; |
| 7711 | out_err: |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 7712 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7713 | return res; |
| 7714 | } |
| 7715 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7716 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7717 | { |
| 7718 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7719 | NL80211_WPA_VERSION_2)); |
| 7720 | } |
| 7721 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7722 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7723 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7725 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7726 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7727 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 7728 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7729 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7730 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7731 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7732 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7733 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7734 | return -EINVAL; |
| 7735 | |
| 7736 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7737 | return -EINVAL; |
| 7738 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7739 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7740 | return -EINVAL; |
| 7741 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7742 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7743 | return -EINVAL; |
| 7744 | |
| 7745 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7746 | return -EINVAL; |
| 7747 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7748 | err = nl80211_parse_key(info, &key); |
| 7749 | if (err) |
| 7750 | return err; |
| 7751 | |
| 7752 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7753 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7754 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7755 | if (!key.p.key || !key.p.key_len) |
| 7756 | return -EINVAL; |
| 7757 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7758 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7759 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7760 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7761 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 7762 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7763 | return -EINVAL; |
| 7764 | } else { |
| 7765 | key.p.key_len = 0; |
| 7766 | key.p.key = NULL; |
| 7767 | } |
| 7768 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7769 | if (key.idx >= 0) { |
| 7770 | int i; |
| 7771 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7772 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7773 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7774 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7775 | ok = true; |
| 7776 | break; |
| 7777 | } |
| 7778 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7779 | if (!ok) |
| 7780 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7781 | } |
| 7782 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7783 | if (!rdev->ops->auth) |
| 7784 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7785 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7786 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7787 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7788 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7789 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7790 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7791 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7792 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7793 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7794 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7795 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7796 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7797 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7798 | |
| 7799 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7800 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7801 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7802 | } |
| 7803 | |
| 7804 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7805 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7806 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7807 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7808 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 7809 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 7810 | return -EINVAL; |
| 7811 | |
| 7812 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 7813 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 7814 | return -EINVAL; |
| 7815 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7816 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 7817 | /* need to include at least Auth Transaction and Status Code */ |
| 7818 | if (sae_data_len < 4) |
| 7819 | return -EINVAL; |
| 7820 | } |
| 7821 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7822 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7823 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7824 | /* |
| 7825 | * Since we no longer track auth state, ignore |
| 7826 | * requests to only change local state. |
| 7827 | */ |
| 7828 | if (local_state_change) |
| 7829 | return 0; |
| 7830 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7831 | wdev_lock(dev->ieee80211_ptr); |
| 7832 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7833 | ssid, ssid_len, ie, ie_len, |
| 7834 | key.p.key, key.p.key_len, key.idx, |
| 7835 | sae_data, sae_data_len); |
| 7836 | wdev_unlock(dev->ieee80211_ptr); |
| 7837 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7838 | } |
| 7839 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7840 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7841 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7842 | struct cfg80211_crypto_settings *settings, |
| 7843 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7844 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7845 | memset(settings, 0, sizeof(*settings)); |
| 7846 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7847 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7848 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7849 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7850 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7851 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7852 | proto = nla_get_u16( |
| 7853 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7854 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7855 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7856 | proto != ETH_P_PAE) |
| 7857 | return -EINVAL; |
| 7858 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7859 | settings->control_port_no_encrypt = true; |
| 7860 | } else |
| 7861 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7862 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7863 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7864 | void *data; |
| 7865 | int len, i; |
| 7866 | |
| 7867 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7868 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7869 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7870 | |
| 7871 | if (len % sizeof(u32)) |
| 7872 | return -EINVAL; |
| 7873 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7874 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7875 | return -EINVAL; |
| 7876 | |
| 7877 | memcpy(settings->ciphers_pairwise, data, len); |
| 7878 | |
| 7879 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7880 | if (!cfg80211_supported_cipher_suite( |
| 7881 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7882 | settings->ciphers_pairwise[i])) |
| 7883 | return -EINVAL; |
| 7884 | } |
| 7885 | |
| 7886 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7887 | settings->cipher_group = |
| 7888 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7889 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7890 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7891 | return -EINVAL; |
| 7892 | } |
| 7893 | |
| 7894 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7895 | settings->wpa_versions = |
| 7896 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7897 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7898 | return -EINVAL; |
| 7899 | } |
| 7900 | |
| 7901 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7902 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7903 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7904 | |
| 7905 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7906 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7907 | settings->n_akm_suites = len / sizeof(u32); |
| 7908 | |
| 7909 | if (len % sizeof(u32)) |
| 7910 | return -EINVAL; |
| 7911 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7912 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7913 | return -EINVAL; |
| 7914 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7915 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7916 | } |
| 7917 | |
| 7918 | return 0; |
| 7919 | } |
| 7920 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7921 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7922 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7924 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7925 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7926 | struct cfg80211_assoc_request req = {}; |
| 7927 | const u8 *bssid, *ssid; |
| 7928 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7929 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7931 | return -EINVAL; |
| 7932 | |
| 7933 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7934 | !info->attrs[NL80211_ATTR_SSID] || |
| 7935 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7936 | return -EINVAL; |
| 7937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7938 | if (!rdev->ops->assoc) |
| 7939 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7940 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7941 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7942 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7943 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7944 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7945 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7946 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7947 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7948 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7949 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7950 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7951 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7952 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7953 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7954 | |
| 7955 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7956 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7957 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7958 | } |
| 7959 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7960 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7961 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7962 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7963 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7964 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7965 | else if (mfp != NL80211_MFP_NO) |
| 7966 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7967 | } |
| 7968 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7969 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7970 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7971 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7972 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7973 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7974 | |
| 7975 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7976 | memcpy(&req.ht_capa_mask, |
| 7977 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7978 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7979 | |
| 7980 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7981 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7982 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7983 | memcpy(&req.ht_capa, |
| 7984 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7985 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7986 | } |
| 7987 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7988 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7989 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7990 | |
| 7991 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7992 | memcpy(&req.vht_capa_mask, |
| 7993 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7994 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7995 | |
| 7996 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7997 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7998 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7999 | memcpy(&req.vht_capa, |
| 8000 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8001 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8002 | } |
| 8003 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8004 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8005 | if (!((rdev->wiphy.features & |
| 8006 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8007 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8008 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8009 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8010 | return -EINVAL; |
| 8011 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8012 | } |
| 8013 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8014 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8015 | if (!err) { |
| 8016 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8017 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8018 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8019 | wdev_unlock(dev->ieee80211_ptr); |
| 8020 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8021 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8022 | return err; |
| 8023 | } |
| 8024 | |
| 8025 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8028 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8029 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8030 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8031 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8032 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8033 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8034 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8035 | return -EINVAL; |
| 8036 | |
| 8037 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8038 | return -EINVAL; |
| 8039 | |
| 8040 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8041 | return -EINVAL; |
| 8042 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8043 | if (!rdev->ops->deauth) |
| 8044 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8045 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8046 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8048 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8049 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8050 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8051 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8052 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8053 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8054 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8055 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8056 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8057 | |
| 8058 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8059 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8060 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8061 | } |
| 8062 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8063 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8064 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8065 | wdev_lock(dev->ieee80211_ptr); |
| 8066 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8067 | local_state_change); |
| 8068 | wdev_unlock(dev->ieee80211_ptr); |
| 8069 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8070 | } |
| 8071 | |
| 8072 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8073 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8075 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8076 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8077 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8078 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8079 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8080 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8081 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8082 | return -EINVAL; |
| 8083 | |
| 8084 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8085 | return -EINVAL; |
| 8086 | |
| 8087 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8088 | return -EINVAL; |
| 8089 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8090 | if (!rdev->ops->disassoc) |
| 8091 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8092 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8093 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8094 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8095 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8096 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8097 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8098 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8099 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8100 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8101 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8102 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8103 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8104 | |
| 8105 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8106 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8107 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8108 | } |
| 8109 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8110 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8111 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8112 | wdev_lock(dev->ieee80211_ptr); |
| 8113 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8114 | local_state_change); |
| 8115 | wdev_unlock(dev->ieee80211_ptr); |
| 8116 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8117 | } |
| 8118 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8119 | static bool |
| 8120 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8121 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8122 | int rateval) |
| 8123 | { |
| 8124 | struct wiphy *wiphy = &rdev->wiphy; |
| 8125 | bool found = false; |
| 8126 | int band, i; |
| 8127 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8128 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8129 | struct ieee80211_supported_band *sband; |
| 8130 | |
| 8131 | sband = wiphy->bands[band]; |
| 8132 | if (!sband) |
| 8133 | continue; |
| 8134 | |
| 8135 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8136 | if (sband->bitrates[i].bitrate == rateval) { |
| 8137 | mcast_rate[band] = i + 1; |
| 8138 | found = true; |
| 8139 | break; |
| 8140 | } |
| 8141 | } |
| 8142 | } |
| 8143 | |
| 8144 | return found; |
| 8145 | } |
| 8146 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8147 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8150 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8151 | struct cfg80211_ibss_params ibss; |
| 8152 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8153 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8154 | int err; |
| 8155 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8156 | memset(&ibss, 0, sizeof(ibss)); |
| 8157 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8158 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8159 | return -EINVAL; |
| 8160 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8161 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8162 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8163 | return -EINVAL; |
| 8164 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8165 | ibss.beacon_interval = 100; |
| 8166 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8167 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8168 | ibss.beacon_interval = |
| 8169 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8170 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8171 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8172 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8173 | if (err) |
| 8174 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8176 | if (!rdev->ops->join_ibss) |
| 8177 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8178 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8179 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8180 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8181 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8182 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8183 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8184 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8185 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8186 | |
| 8187 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8188 | return -EINVAL; |
| 8189 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8190 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8191 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8192 | |
| 8193 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8194 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8195 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8196 | } |
| 8197 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8198 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8199 | if (err) |
| 8200 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8201 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8202 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8203 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8204 | return -EINVAL; |
| 8205 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8206 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8207 | case NL80211_CHAN_WIDTH_5: |
| 8208 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8209 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8210 | break; |
| 8211 | case NL80211_CHAN_WIDTH_20: |
| 8212 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8213 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8214 | return -EINVAL; |
| 8215 | break; |
| 8216 | case NL80211_CHAN_WIDTH_80: |
| 8217 | case NL80211_CHAN_WIDTH_80P80: |
| 8218 | case NL80211_CHAN_WIDTH_160: |
| 8219 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8220 | return -EINVAL; |
| 8221 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8222 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8223 | return -EINVAL; |
| 8224 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8225 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8226 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8227 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8228 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8229 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8230 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8231 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8232 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8233 | u8 *rates = |
| 8234 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8235 | int n_rates = |
| 8236 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8237 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8238 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8239 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8240 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8241 | &ibss.basic_rates); |
| 8242 | if (err) |
| 8243 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8244 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8245 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8246 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8247 | memcpy(&ibss.ht_capa_mask, |
| 8248 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8249 | sizeof(ibss.ht_capa_mask)); |
| 8250 | |
| 8251 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8252 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8253 | return -EINVAL; |
| 8254 | memcpy(&ibss.ht_capa, |
| 8255 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8256 | sizeof(ibss.ht_capa)); |
| 8257 | } |
| 8258 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8259 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8260 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8261 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8262 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8264 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8265 | bool no_ht = false; |
| 8266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8267 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8268 | info->attrs[NL80211_ATTR_KEYS], |
| 8269 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8270 | if (IS_ERR(connkeys)) |
| 8271 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8272 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8273 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8274 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8275 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8276 | return -EINVAL; |
| 8277 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8278 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8279 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8280 | ibss.control_port = |
| 8281 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8282 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8283 | ibss.userspace_handles_dfs = |
| 8284 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8285 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8286 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8287 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8288 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8289 | return err; |
| 8290 | } |
| 8291 | |
| 8292 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8293 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8295 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8297 | if (!rdev->ops->leave_ibss) |
| 8298 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8300 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8301 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8303 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8304 | } |
| 8305 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8306 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8307 | { |
| 8308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8309 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8310 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8311 | u32 nla_rate; |
| 8312 | int err; |
| 8313 | |
| 8314 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8315 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8316 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8317 | return -EOPNOTSUPP; |
| 8318 | |
| 8319 | if (!rdev->ops->set_mcast_rate) |
| 8320 | return -EOPNOTSUPP; |
| 8321 | |
| 8322 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8323 | |
| 8324 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8325 | return -EINVAL; |
| 8326 | |
| 8327 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8328 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8329 | return -EINVAL; |
| 8330 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8331 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8332 | |
| 8333 | return err; |
| 8334 | } |
| 8335 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8336 | static struct sk_buff * |
| 8337 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8338 | struct wireless_dev *wdev, int approxlen, |
| 8339 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8340 | enum nl80211_attrs attr, |
| 8341 | const struct nl80211_vendor_cmd_info *info, |
| 8342 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8343 | { |
| 8344 | struct sk_buff *skb; |
| 8345 | void *hdr; |
| 8346 | struct nlattr *data; |
| 8347 | |
| 8348 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8349 | if (!skb) |
| 8350 | return NULL; |
| 8351 | |
| 8352 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8353 | if (!hdr) { |
| 8354 | kfree_skb(skb); |
| 8355 | return NULL; |
| 8356 | } |
| 8357 | |
| 8358 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8359 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8360 | |
| 8361 | if (info) { |
| 8362 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8363 | info->vendor_id)) |
| 8364 | goto nla_put_failure; |
| 8365 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8366 | info->subcmd)) |
| 8367 | goto nla_put_failure; |
| 8368 | } |
| 8369 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8370 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8371 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8372 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8373 | goto nla_put_failure; |
| 8374 | if (wdev->netdev && |
| 8375 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8376 | wdev->netdev->ifindex)) |
| 8377 | goto nla_put_failure; |
| 8378 | } |
| 8379 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8380 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8381 | if (!data) |
| 8382 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8383 | |
| 8384 | ((void **)skb->cb)[0] = rdev; |
| 8385 | ((void **)skb->cb)[1] = hdr; |
| 8386 | ((void **)skb->cb)[2] = data; |
| 8387 | |
| 8388 | return skb; |
| 8389 | |
| 8390 | nla_put_failure: |
| 8391 | kfree_skb(skb); |
| 8392 | return NULL; |
| 8393 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8394 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8395 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8396 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8397 | enum nl80211_commands cmd, |
| 8398 | enum nl80211_attrs attr, |
| 8399 | int vendor_event_idx, |
| 8400 | int approxlen, gfp_t gfp) |
| 8401 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8402 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8403 | const struct nl80211_vendor_cmd_info *info; |
| 8404 | |
| 8405 | switch (cmd) { |
| 8406 | case NL80211_CMD_TESTMODE: |
| 8407 | if (WARN_ON(vendor_event_idx != -1)) |
| 8408 | return NULL; |
| 8409 | info = NULL; |
| 8410 | break; |
| 8411 | case NL80211_CMD_VENDOR: |
| 8412 | if (WARN_ON(vendor_event_idx < 0 || |
| 8413 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8414 | return NULL; |
| 8415 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8416 | break; |
| 8417 | default: |
| 8418 | WARN_ON(1); |
| 8419 | return NULL; |
| 8420 | } |
| 8421 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8422 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8423 | cmd, attr, info, gfp); |
| 8424 | } |
| 8425 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8426 | |
| 8427 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8428 | { |
| 8429 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8430 | void *hdr = ((void **)skb->cb)[1]; |
| 8431 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8432 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8433 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8434 | /* clear CB data for netlink core to own from now on */ |
| 8435 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8436 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8437 | nla_nest_end(skb, data); |
| 8438 | genlmsg_end(skb, hdr); |
| 8439 | |
| 8440 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8441 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8442 | |
| 8443 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8444 | mcgrp, gfp); |
| 8445 | } |
| 8446 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8447 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8448 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8449 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8450 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8452 | struct wireless_dev *wdev = |
| 8453 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8454 | int err; |
| 8455 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8456 | if (!rdev->ops->testmode_cmd) |
| 8457 | return -EOPNOTSUPP; |
| 8458 | |
| 8459 | if (IS_ERR(wdev)) { |
| 8460 | err = PTR_ERR(wdev); |
| 8461 | if (err != -EINVAL) |
| 8462 | return err; |
| 8463 | wdev = NULL; |
| 8464 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8465 | return -EINVAL; |
| 8466 | } |
| 8467 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8468 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8469 | return -EINVAL; |
| 8470 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8471 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8472 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8473 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8474 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8475 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8476 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8477 | return err; |
| 8478 | } |
| 8479 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8480 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8481 | struct netlink_callback *cb) |
| 8482 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8483 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8484 | int err; |
| 8485 | long phy_idx; |
| 8486 | void *data = NULL; |
| 8487 | int data_len = 0; |
| 8488 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8489 | rtnl_lock(); |
| 8490 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8491 | if (cb->args[0]) { |
| 8492 | /* |
| 8493 | * 0 is a valid index, but not valid for args[0], |
| 8494 | * so we need to offset by 1. |
| 8495 | */ |
| 8496 | phy_idx = cb->args[0] - 1; |
| 8497 | } else { |
| 8498 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 8499 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 8500 | nl80211_policy); |
| 8501 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8502 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8503 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8504 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 8505 | nl80211_fam.attrbuf); |
| 8506 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8507 | err = PTR_ERR(rdev); |
| 8508 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8509 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8510 | phy_idx = rdev->wiphy_idx; |
| 8511 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8512 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8513 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 8514 | cb->args[1] = |
| 8515 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 8516 | } |
| 8517 | |
| 8518 | if (cb->args[1]) { |
| 8519 | data = nla_data((void *)cb->args[1]); |
| 8520 | data_len = nla_len((void *)cb->args[1]); |
| 8521 | } |
| 8522 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8523 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8524 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8525 | err = -ENOENT; |
| 8526 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8527 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8528 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8529 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8530 | err = -EOPNOTSUPP; |
| 8531 | goto out_err; |
| 8532 | } |
| 8533 | |
| 8534 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8535 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8536 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8537 | NL80211_CMD_TESTMODE); |
| 8538 | struct nlattr *tmdata; |
| 8539 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8540 | if (!hdr) |
| 8541 | break; |
| 8542 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8543 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8544 | genlmsg_cancel(skb, hdr); |
| 8545 | break; |
| 8546 | } |
| 8547 | |
| 8548 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8549 | if (!tmdata) { |
| 8550 | genlmsg_cancel(skb, hdr); |
| 8551 | break; |
| 8552 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8553 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8554 | nla_nest_end(skb, tmdata); |
| 8555 | |
| 8556 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8557 | genlmsg_cancel(skb, hdr); |
| 8558 | break; |
| 8559 | } else if (err) { |
| 8560 | genlmsg_cancel(skb, hdr); |
| 8561 | goto out_err; |
| 8562 | } |
| 8563 | |
| 8564 | genlmsg_end(skb, hdr); |
| 8565 | } |
| 8566 | |
| 8567 | err = skb->len; |
| 8568 | /* see above */ |
| 8569 | cb->args[0] = phy_idx + 1; |
| 8570 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8571 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8572 | return err; |
| 8573 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8574 | #endif |
| 8575 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8576 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8579 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8580 | struct cfg80211_connect_params connect; |
| 8581 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8582 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8583 | int err; |
| 8584 | |
| 8585 | memset(&connect, 0, sizeof(connect)); |
| 8586 | |
| 8587 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8588 | return -EINVAL; |
| 8589 | |
| 8590 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8591 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8592 | return -EINVAL; |
| 8593 | |
| 8594 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8595 | connect.auth_type = |
| 8596 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8597 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8598 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8599 | return -EINVAL; |
| 8600 | } else |
| 8601 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8602 | |
| 8603 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8604 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8605 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8606 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8607 | if (err) |
| 8608 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8609 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8610 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8611 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8612 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8613 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8614 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8615 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8616 | connect.bg_scan_period = -1; |
| 8617 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8618 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8619 | connect.bg_scan_period = |
| 8620 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8621 | } |
| 8622 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8623 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8624 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8625 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8626 | connect.bssid_hint = |
| 8627 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8628 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8629 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8630 | |
| 8631 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8632 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8633 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8634 | } |
| 8635 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8636 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8637 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8638 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8639 | connect.mfp != NL80211_MFP_NO) |
| 8640 | return -EINVAL; |
| 8641 | } else { |
| 8642 | connect.mfp = NL80211_MFP_NO; |
| 8643 | } |
| 8644 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8645 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8646 | connect.prev_bssid = |
| 8647 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8648 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8649 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8650 | connect.channel = nl80211_get_valid_chan( |
| 8651 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8652 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8653 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8654 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8655 | connect.channel_hint = nl80211_get_valid_chan( |
| 8656 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8657 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8658 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8659 | } |
| 8660 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8661 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8662 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8663 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8664 | if (IS_ERR(connkeys)) |
| 8665 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8666 | } |
| 8667 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8668 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8669 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8670 | |
| 8671 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8672 | memcpy(&connect.ht_capa_mask, |
| 8673 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8674 | sizeof(connect.ht_capa_mask)); |
| 8675 | |
| 8676 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8677 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8678 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8679 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8680 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8681 | memcpy(&connect.ht_capa, |
| 8682 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8683 | sizeof(connect.ht_capa)); |
| 8684 | } |
| 8685 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8686 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8687 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8688 | |
| 8689 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8690 | memcpy(&connect.vht_capa_mask, |
| 8691 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8692 | sizeof(connect.vht_capa_mask)); |
| 8693 | |
| 8694 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8695 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8696 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8697 | return -EINVAL; |
| 8698 | } |
| 8699 | memcpy(&connect.vht_capa, |
| 8700 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8701 | sizeof(connect.vht_capa)); |
| 8702 | } |
| 8703 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8704 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8705 | if (!((rdev->wiphy.features & |
| 8706 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8707 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8708 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8709 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8710 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8711 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8712 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8713 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8714 | } |
| 8715 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8716 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8717 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8718 | kzfree(connkeys); |
| 8719 | return -EOPNOTSUPP; |
| 8720 | } |
| 8721 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8722 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8723 | /* bss selection makes no sense if bssid is set */ |
| 8724 | if (connect.bssid) { |
| 8725 | kzfree(connkeys); |
| 8726 | return -EINVAL; |
| 8727 | } |
| 8728 | |
| 8729 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8730 | wiphy, &connect.bss_select); |
| 8731 | if (err) { |
| 8732 | kzfree(connkeys); |
| 8733 | return err; |
| 8734 | } |
| 8735 | } |
| 8736 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8737 | wdev_lock(dev->ieee80211_ptr); |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8738 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8739 | connect.prev_bssid); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8740 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8741 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8742 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8743 | return err; |
| 8744 | } |
| 8745 | |
| 8746 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8747 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8749 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8750 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8751 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8752 | |
| 8753 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8754 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8755 | else |
| 8756 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8757 | |
| 8758 | if (reason == 0) |
| 8759 | return -EINVAL; |
| 8760 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8762 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8763 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8764 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8765 | wdev_lock(dev->ieee80211_ptr); |
| 8766 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8767 | wdev_unlock(dev->ieee80211_ptr); |
| 8768 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8769 | } |
| 8770 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8771 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8772 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8774 | struct net *net; |
| 8775 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8776 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8777 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8778 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8779 | |
| 8780 | net = get_net_ns_by_pid(pid); |
| 8781 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8782 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8783 | |
| 8784 | net = get_net_ns_by_fd(fd); |
| 8785 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8786 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8787 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8788 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8789 | if (IS_ERR(net)) |
| 8790 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8791 | |
| 8792 | err = 0; |
| 8793 | |
| 8794 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8795 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8796 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8797 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8798 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8799 | return err; |
| 8800 | } |
| 8801 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8802 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8803 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8805 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8806 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8807 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8808 | struct cfg80211_pmksa pmksa; |
| 8809 | |
| 8810 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8811 | |
| 8812 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8813 | return -EINVAL; |
| 8814 | |
| 8815 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8816 | return -EINVAL; |
| 8817 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8818 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8819 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8820 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8822 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8823 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8824 | |
| 8825 | switch (info->genlhdr->cmd) { |
| 8826 | case NL80211_CMD_SET_PMKSA: |
| 8827 | rdev_ops = rdev->ops->set_pmksa; |
| 8828 | break; |
| 8829 | case NL80211_CMD_DEL_PMKSA: |
| 8830 | rdev_ops = rdev->ops->del_pmksa; |
| 8831 | break; |
| 8832 | default: |
| 8833 | WARN_ON(1); |
| 8834 | break; |
| 8835 | } |
| 8836 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8837 | if (!rdev_ops) |
| 8838 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8839 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8840 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8841 | } |
| 8842 | |
| 8843 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8844 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8846 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8847 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8848 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8849 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8850 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8851 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8852 | if (!rdev->ops->flush_pmksa) |
| 8853 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8854 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8855 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8856 | } |
| 8857 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8858 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8859 | { |
| 8860 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8861 | struct net_device *dev = info->user_ptr[1]; |
| 8862 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8863 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8864 | u16 status_code; |
| 8865 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8866 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8867 | |
| 8868 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8869 | !rdev->ops->tdls_mgmt) |
| 8870 | return -EOPNOTSUPP; |
| 8871 | |
| 8872 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8873 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8874 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8875 | !info->attrs[NL80211_ATTR_IE] || |
| 8876 | !info->attrs[NL80211_ATTR_MAC]) |
| 8877 | return -EINVAL; |
| 8878 | |
| 8879 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8880 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8881 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8882 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8883 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8884 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8885 | peer_capability = |
| 8886 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8887 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8888 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8889 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8890 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8891 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8892 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8893 | } |
| 8894 | |
| 8895 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8896 | { |
| 8897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8898 | struct net_device *dev = info->user_ptr[1]; |
| 8899 | enum nl80211_tdls_operation operation; |
| 8900 | u8 *peer; |
| 8901 | |
| 8902 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8903 | !rdev->ops->tdls_oper) |
| 8904 | return -EOPNOTSUPP; |
| 8905 | |
| 8906 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8907 | !info->attrs[NL80211_ATTR_MAC]) |
| 8908 | return -EINVAL; |
| 8909 | |
| 8910 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8911 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8912 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8913 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8914 | } |
| 8915 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8916 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8917 | struct genl_info *info) |
| 8918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8920 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8921 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8922 | struct sk_buff *msg; |
| 8923 | void *hdr; |
| 8924 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8925 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8926 | int err; |
| 8927 | |
| 8928 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8929 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8930 | return -EINVAL; |
| 8931 | |
| 8932 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 8933 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8934 | if (!rdev->ops->remain_on_channel || |
| 8935 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8936 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8937 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8938 | /* |
| 8939 | * We should be on that channel for at least a minimum amount of |
| 8940 | * time (10ms) but no longer than the driver supports. |
| 8941 | */ |
| 8942 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8943 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 8944 | return -EINVAL; |
| 8945 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8946 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8947 | if (err) |
| 8948 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8949 | |
| 8950 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8951 | if (!msg) |
| 8952 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8953 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8954 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8955 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8956 | if (!hdr) { |
| 8957 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8958 | goto free_msg; |
| 8959 | } |
| 8960 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8961 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 8962 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8963 | |
| 8964 | if (err) |
| 8965 | goto free_msg; |
| 8966 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8967 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 8968 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8969 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8970 | |
| 8971 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8972 | |
| 8973 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8974 | |
| 8975 | nla_put_failure: |
| 8976 | err = -ENOBUFS; |
| 8977 | free_msg: |
| 8978 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8979 | return err; |
| 8980 | } |
| 8981 | |
| 8982 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 8983 | struct genl_info *info) |
| 8984 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8986 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8987 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8988 | |
| 8989 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8990 | return -EINVAL; |
| 8991 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8992 | if (!rdev->ops->cancel_remain_on_channel) |
| 8993 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8994 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8995 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8996 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8997 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8998 | } |
| 8999 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9000 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9001 | struct genl_info *info) |
| 9002 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9003 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9005 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9006 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9007 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9008 | if (!rdev->ops->set_bitrate_mask) |
| 9009 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9010 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9011 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9012 | if (err) |
| 9013 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9014 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9015 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9016 | } |
| 9017 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9018 | 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] | 9019 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9021 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9022 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9023 | |
| 9024 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9025 | return -EINVAL; |
| 9026 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9027 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9028 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9029 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9030 | switch (wdev->iftype) { |
| 9031 | case NL80211_IFTYPE_STATION: |
| 9032 | case NL80211_IFTYPE_ADHOC: |
| 9033 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9034 | case NL80211_IFTYPE_AP: |
| 9035 | case NL80211_IFTYPE_AP_VLAN: |
| 9036 | case NL80211_IFTYPE_MESH_POINT: |
| 9037 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9038 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9039 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9040 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9041 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9042 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9043 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9044 | |
| 9045 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9046 | if (!rdev->ops->mgmt_tx) |
| 9047 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9048 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9049 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9050 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9051 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9052 | } |
| 9053 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9054 | 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] | 9055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9057 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9058 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9059 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9060 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9061 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9062 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9063 | struct cfg80211_mgmt_tx_params params = { |
| 9064 | .dont_wait_for_ack = |
| 9065 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9066 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9067 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9068 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9069 | return -EINVAL; |
| 9070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9071 | if (!rdev->ops->mgmt_tx) |
| 9072 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9073 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9074 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9075 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9076 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9077 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9078 | case NL80211_IFTYPE_STATION: |
| 9079 | case NL80211_IFTYPE_ADHOC: |
| 9080 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9081 | case NL80211_IFTYPE_AP: |
| 9082 | case NL80211_IFTYPE_AP_VLAN: |
| 9083 | case NL80211_IFTYPE_MESH_POINT: |
| 9084 | case NL80211_IFTYPE_P2P_GO: |
| 9085 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9086 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9087 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9088 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9089 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9090 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9091 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9092 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9093 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9094 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9095 | |
| 9096 | /* |
| 9097 | * We should wait on the channel for at least a minimum amount |
| 9098 | * of time (10ms) but no longer than the driver supports. |
| 9099 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9100 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9101 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9102 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9103 | } |
| 9104 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9105 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9106 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9107 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9108 | return -EINVAL; |
| 9109 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9110 | 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] | 9111 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9112 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9113 | * the driver. The latter will use the current one |
| 9114 | */ |
| 9115 | chandef.chan = NULL; |
| 9116 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9117 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9118 | if (err) |
| 9119 | return err; |
| 9120 | } |
| 9121 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9122 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9123 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9124 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9125 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9126 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9127 | |
| 9128 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9129 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9130 | int i; |
| 9131 | |
| 9132 | if (len % sizeof(u16)) |
| 9133 | return -EINVAL; |
| 9134 | |
| 9135 | params.n_csa_offsets = len / sizeof(u16); |
| 9136 | params.csa_offsets = |
| 9137 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9138 | |
| 9139 | /* check that all the offsets fit the frame */ |
| 9140 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9141 | if (params.csa_offsets[i] >= params.len) |
| 9142 | return -EINVAL; |
| 9143 | } |
| 9144 | } |
| 9145 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9146 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9148 | if (!msg) |
| 9149 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9150 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9151 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9152 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9153 | if (!hdr) { |
| 9154 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9155 | goto free_msg; |
| 9156 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9157 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9158 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9159 | params.chan = chandef.chan; |
| 9160 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9161 | if (err) |
| 9162 | goto free_msg; |
| 9163 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9164 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9165 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9166 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9167 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9168 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9169 | genlmsg_end(msg, hdr); |
| 9170 | return genlmsg_reply(msg, info); |
| 9171 | } |
| 9172 | |
| 9173 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9174 | |
| 9175 | nla_put_failure: |
| 9176 | err = -ENOBUFS; |
| 9177 | free_msg: |
| 9178 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9179 | return err; |
| 9180 | } |
| 9181 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9182 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9183 | { |
| 9184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9185 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9186 | u64 cookie; |
| 9187 | |
| 9188 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9189 | return -EINVAL; |
| 9190 | |
| 9191 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9192 | return -EOPNOTSUPP; |
| 9193 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9194 | switch (wdev->iftype) { |
| 9195 | case NL80211_IFTYPE_STATION: |
| 9196 | case NL80211_IFTYPE_ADHOC: |
| 9197 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9198 | case NL80211_IFTYPE_AP: |
| 9199 | case NL80211_IFTYPE_AP_VLAN: |
| 9200 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9201 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9202 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9203 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9204 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9205 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9206 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9207 | |
| 9208 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9209 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9210 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9211 | } |
| 9212 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9213 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9214 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9216 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9217 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9218 | u8 ps_state; |
| 9219 | bool state; |
| 9220 | int err; |
| 9221 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9222 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9223 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9224 | |
| 9225 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9226 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9227 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9228 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9229 | |
| 9230 | wdev = dev->ieee80211_ptr; |
| 9231 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9232 | if (!rdev->ops->set_power_mgmt) |
| 9233 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9234 | |
| 9235 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9236 | |
| 9237 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9238 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9240 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9241 | if (!err) |
| 9242 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9243 | return err; |
| 9244 | } |
| 9245 | |
| 9246 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9247 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9249 | enum nl80211_ps_state ps_state; |
| 9250 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9251 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9252 | struct sk_buff *msg; |
| 9253 | void *hdr; |
| 9254 | int err; |
| 9255 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9256 | wdev = dev->ieee80211_ptr; |
| 9257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9258 | if (!rdev->ops->set_power_mgmt) |
| 9259 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9260 | |
| 9261 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9262 | if (!msg) |
| 9263 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9264 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9265 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9266 | NL80211_CMD_GET_POWER_SAVE); |
| 9267 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9268 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9269 | goto free_msg; |
| 9270 | } |
| 9271 | |
| 9272 | if (wdev->ps) |
| 9273 | ps_state = NL80211_PS_ENABLED; |
| 9274 | else |
| 9275 | ps_state = NL80211_PS_DISABLED; |
| 9276 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9277 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9278 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9279 | |
| 9280 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9281 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9283 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9284 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9285 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9286 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9287 | return err; |
| 9288 | } |
| 9289 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9290 | static const struct nla_policy |
| 9291 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9292 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9293 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9294 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9295 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9296 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9297 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9298 | }; |
| 9299 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9300 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9301 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9302 | { |
| 9303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9304 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9305 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9306 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9307 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9308 | return -EINVAL; |
| 9309 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9310 | if (!rdev->ops->set_cqm_txe_config) |
| 9311 | return -EOPNOTSUPP; |
| 9312 | |
| 9313 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9314 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9315 | return -EOPNOTSUPP; |
| 9316 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9317 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9318 | } |
| 9319 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9320 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9321 | s32 threshold, u32 hysteresis) |
| 9322 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9324 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9326 | |
| 9327 | if (threshold > 0) |
| 9328 | return -EINVAL; |
| 9329 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9330 | /* disabling - hysteresis should also be zero then */ |
| 9331 | if (threshold == 0) |
| 9332 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9333 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9334 | if (!rdev->ops->set_cqm_rssi_config) |
| 9335 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9336 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9337 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9338 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9339 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9340 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9341 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9342 | } |
| 9343 | |
| 9344 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9345 | { |
| 9346 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9347 | struct nlattr *cqm; |
| 9348 | int err; |
| 9349 | |
| 9350 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9351 | if (!cqm) |
| 9352 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9353 | |
| 9354 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9355 | nl80211_attr_cqm_policy); |
| 9356 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9357 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9358 | |
| 9359 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9360 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9361 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9362 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9363 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9364 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9365 | } |
| 9366 | |
| 9367 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9368 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9369 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9370 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9371 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9372 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9373 | |
| 9374 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9375 | } |
| 9376 | |
| 9377 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9378 | } |
| 9379 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9380 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9381 | { |
| 9382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9383 | struct net_device *dev = info->user_ptr[1]; |
| 9384 | struct ocb_setup setup = {}; |
| 9385 | int err; |
| 9386 | |
| 9387 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9388 | if (err) |
| 9389 | return err; |
| 9390 | |
| 9391 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9392 | } |
| 9393 | |
| 9394 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9395 | { |
| 9396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9397 | struct net_device *dev = info->user_ptr[1]; |
| 9398 | |
| 9399 | return cfg80211_leave_ocb(rdev, dev); |
| 9400 | } |
| 9401 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9402 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9403 | { |
| 9404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9405 | struct net_device *dev = info->user_ptr[1]; |
| 9406 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9407 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9408 | int err; |
| 9409 | |
| 9410 | /* start with default */ |
| 9411 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9412 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9413 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9414 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9415 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9416 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9417 | if (err) |
| 9418 | return err; |
| 9419 | } |
| 9420 | |
| 9421 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9422 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9423 | return -EINVAL; |
| 9424 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9425 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9426 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9427 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9428 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9429 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9430 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9431 | return -EINVAL; |
| 9432 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9433 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9434 | setup.beacon_interval = |
| 9435 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9436 | |
Purushottam Kushwaha | c6800ff | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9437 | err = cfg80211_validate_beacon_int(rdev, |
| 9438 | NL80211_IFTYPE_MESH_POINT, |
| 9439 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9440 | if (err) |
| 9441 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9442 | } |
| 9443 | |
| 9444 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9445 | setup.dtim_period = |
| 9446 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9447 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9448 | return -EINVAL; |
| 9449 | } |
| 9450 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9451 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9452 | /* parse additional setup parameters if given */ |
| 9453 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9454 | if (err) |
| 9455 | return err; |
| 9456 | } |
| 9457 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9458 | if (setup.user_mpm) |
| 9459 | cfg.auto_open_plinks = false; |
| 9460 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9461 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9462 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9463 | if (err) |
| 9464 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9465 | } else { |
| 9466 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9467 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9468 | } |
| 9469 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9470 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9471 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9472 | int n_rates = |
| 9473 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9474 | struct ieee80211_supported_band *sband; |
| 9475 | |
| 9476 | if (!setup.chandef.chan) |
| 9477 | return -EINVAL; |
| 9478 | |
| 9479 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9480 | |
| 9481 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9482 | &setup.basic_rates); |
| 9483 | if (err) |
| 9484 | return err; |
| 9485 | } |
| 9486 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9487 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 9488 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 9489 | if (err) |
| 9490 | return err; |
| 9491 | |
| 9492 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 9493 | &setup.beacon_rate); |
| 9494 | if (err) |
| 9495 | return err; |
| 9496 | } |
| 9497 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9498 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9499 | } |
| 9500 | |
| 9501 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9502 | { |
| 9503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9504 | struct net_device *dev = info->user_ptr[1]; |
| 9505 | |
| 9506 | return cfg80211_leave_mesh(rdev, dev); |
| 9507 | } |
| 9508 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9509 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9510 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9511 | struct cfg80211_registered_device *rdev) |
| 9512 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9513 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9514 | struct nlattr *nl_pats, *nl_pat; |
| 9515 | int i, pat_len; |
| 9516 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9517 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9518 | return 0; |
| 9519 | |
| 9520 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9521 | if (!nl_pats) |
| 9522 | return -ENOBUFS; |
| 9523 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9524 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9525 | nl_pat = nla_nest_start(msg, i + 1); |
| 9526 | if (!nl_pat) |
| 9527 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9528 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9529 | 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] | 9530 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9531 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9532 | wowlan->patterns[i].pattern) || |
| 9533 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9534 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9535 | return -ENOBUFS; |
| 9536 | nla_nest_end(msg, nl_pat); |
| 9537 | } |
| 9538 | nla_nest_end(msg, nl_pats); |
| 9539 | |
| 9540 | return 0; |
| 9541 | } |
| 9542 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9543 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9544 | struct cfg80211_wowlan_tcp *tcp) |
| 9545 | { |
| 9546 | struct nlattr *nl_tcp; |
| 9547 | |
| 9548 | if (!tcp) |
| 9549 | return 0; |
| 9550 | |
| 9551 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9552 | if (!nl_tcp) |
| 9553 | return -ENOBUFS; |
| 9554 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9555 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9556 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9557 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9558 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9559 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9560 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9561 | tcp->payload_len, tcp->payload) || |
| 9562 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9563 | tcp->data_interval) || |
| 9564 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9565 | tcp->wake_len, tcp->wake_data) || |
| 9566 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9567 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9568 | return -ENOBUFS; |
| 9569 | |
| 9570 | if (tcp->payload_seq.len && |
| 9571 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9572 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9573 | return -ENOBUFS; |
| 9574 | |
| 9575 | if (tcp->payload_tok.len && |
| 9576 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9577 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9578 | &tcp->payload_tok)) |
| 9579 | return -ENOBUFS; |
| 9580 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9581 | nla_nest_end(msg, nl_tcp); |
| 9582 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9583 | return 0; |
| 9584 | } |
| 9585 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9586 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9587 | struct cfg80211_sched_scan_request *req) |
| 9588 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9589 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9590 | int i; |
| 9591 | |
| 9592 | if (!req) |
| 9593 | return 0; |
| 9594 | |
| 9595 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9596 | if (!nd) |
| 9597 | return -ENOBUFS; |
| 9598 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9599 | if (req->n_scan_plans == 1 && |
| 9600 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9601 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9602 | return -ENOBUFS; |
| 9603 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9604 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9605 | return -ENOBUFS; |
| 9606 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9607 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9608 | if (!freqs) |
| 9609 | return -ENOBUFS; |
| 9610 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9611 | for (i = 0; i < req->n_channels; i++) { |
| 9612 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9613 | return -ENOBUFS; |
| 9614 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9615 | |
| 9616 | nla_nest_end(msg, freqs); |
| 9617 | |
| 9618 | if (req->n_match_sets) { |
| 9619 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9620 | if (!matches) |
| 9621 | return -ENOBUFS; |
| 9622 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9623 | for (i = 0; i < req->n_match_sets; i++) { |
| 9624 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9625 | if (!match) |
| 9626 | return -ENOBUFS; |
| 9627 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9628 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9629 | req->match_sets[i].ssid.ssid_len, |
| 9630 | req->match_sets[i].ssid.ssid)) |
| 9631 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9632 | nla_nest_end(msg, match); |
| 9633 | } |
| 9634 | nla_nest_end(msg, matches); |
| 9635 | } |
| 9636 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9637 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9638 | if (!scan_plans) |
| 9639 | return -ENOBUFS; |
| 9640 | |
| 9641 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9642 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9643 | if (!scan_plan) |
| 9644 | return -ENOBUFS; |
| 9645 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9646 | if (!scan_plan || |
| 9647 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9648 | req->scan_plans[i].interval) || |
| 9649 | (req->scan_plans[i].iterations && |
| 9650 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9651 | req->scan_plans[i].iterations))) |
| 9652 | return -ENOBUFS; |
| 9653 | nla_nest_end(msg, scan_plan); |
| 9654 | } |
| 9655 | nla_nest_end(msg, scan_plans); |
| 9656 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9657 | nla_nest_end(msg, nd); |
| 9658 | |
| 9659 | return 0; |
| 9660 | } |
| 9661 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9662 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9663 | { |
| 9664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9665 | struct sk_buff *msg; |
| 9666 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9667 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9668 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9669 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9670 | return -EOPNOTSUPP; |
| 9671 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9672 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9673 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9674 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9675 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9676 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9677 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9678 | } |
| 9679 | |
| 9680 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9681 | if (!msg) |
| 9682 | return -ENOMEM; |
| 9683 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9684 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9685 | NL80211_CMD_GET_WOWLAN); |
| 9686 | if (!hdr) |
| 9687 | goto nla_put_failure; |
| 9688 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9689 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9690 | struct nlattr *nl_wowlan; |
| 9691 | |
| 9692 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9693 | if (!nl_wowlan) |
| 9694 | goto nla_put_failure; |
| 9695 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9696 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9697 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9698 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9699 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9700 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9701 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9702 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9703 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9704 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9705 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9706 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9707 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9708 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9709 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9710 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9711 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9712 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9713 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9714 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9715 | if (nl80211_send_wowlan_tcp(msg, |
| 9716 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9717 | goto nla_put_failure; |
| 9718 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9719 | if (nl80211_send_wowlan_nd( |
| 9720 | msg, |
| 9721 | rdev->wiphy.wowlan_config->nd_config)) |
| 9722 | goto nla_put_failure; |
| 9723 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9724 | nla_nest_end(msg, nl_wowlan); |
| 9725 | } |
| 9726 | |
| 9727 | genlmsg_end(msg, hdr); |
| 9728 | return genlmsg_reply(msg, info); |
| 9729 | |
| 9730 | nla_put_failure: |
| 9731 | nlmsg_free(msg); |
| 9732 | return -ENOBUFS; |
| 9733 | } |
| 9734 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9735 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9736 | struct nlattr *attr, |
| 9737 | struct cfg80211_wowlan *trig) |
| 9738 | { |
| 9739 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9740 | struct cfg80211_wowlan_tcp *cfg; |
| 9741 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9742 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9743 | u32 size; |
| 9744 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9745 | int err, port; |
| 9746 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9747 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9748 | return -EINVAL; |
| 9749 | |
| 9750 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 9751 | nla_data(attr), nla_len(attr), |
| 9752 | nl80211_wowlan_tcp_policy); |
| 9753 | if (err) |
| 9754 | return err; |
| 9755 | |
| 9756 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9757 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9758 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9759 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9760 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9761 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9762 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9763 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9764 | return -EINVAL; |
| 9765 | |
| 9766 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9767 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9768 | return -EINVAL; |
| 9769 | |
| 9770 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9771 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9772 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9773 | return -EINVAL; |
| 9774 | |
| 9775 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9776 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9777 | return -EINVAL; |
| 9778 | |
| 9779 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9780 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9781 | return -EINVAL; |
| 9782 | |
| 9783 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9784 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9785 | |
| 9786 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9787 | tokens_size = tokln - sizeof(*tok); |
| 9788 | |
| 9789 | if (!tok->len || tokens_size % tok->len) |
| 9790 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9791 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9792 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9793 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9794 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9795 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9796 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9797 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9798 | return -EINVAL; |
| 9799 | if (tok->offset + tok->len > data_size) |
| 9800 | return -EINVAL; |
| 9801 | } |
| 9802 | |
| 9803 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9804 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9805 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9806 | return -EINVAL; |
| 9807 | if (seq->len == 0 || seq->len > 4) |
| 9808 | return -EINVAL; |
| 9809 | if (seq->len + seq->offset > data_size) |
| 9810 | return -EINVAL; |
| 9811 | } |
| 9812 | |
| 9813 | size = sizeof(*cfg); |
| 9814 | size += data_size; |
| 9815 | size += wake_size + wake_mask_size; |
| 9816 | size += tokens_size; |
| 9817 | |
| 9818 | cfg = kzalloc(size, GFP_KERNEL); |
| 9819 | if (!cfg) |
| 9820 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9821 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9822 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9823 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9824 | ETH_ALEN); |
| 9825 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9826 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9827 | else |
| 9828 | port = 0; |
| 9829 | #ifdef CONFIG_INET |
| 9830 | /* allocate a socket and port for it and use it */ |
| 9831 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9832 | IPPROTO_TCP, &cfg->sock, 1); |
| 9833 | if (err) { |
| 9834 | kfree(cfg); |
| 9835 | return err; |
| 9836 | } |
| 9837 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9838 | sock_release(cfg->sock); |
| 9839 | kfree(cfg); |
| 9840 | return -EADDRINUSE; |
| 9841 | } |
| 9842 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9843 | #else |
| 9844 | if (!port) { |
| 9845 | kfree(cfg); |
| 9846 | return -EINVAL; |
| 9847 | } |
| 9848 | cfg->src_port = port; |
| 9849 | #endif |
| 9850 | |
| 9851 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9852 | cfg->payload_len = data_size; |
| 9853 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9854 | memcpy((void *)cfg->payload, |
| 9855 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9856 | data_size); |
| 9857 | if (seq) |
| 9858 | cfg->payload_seq = *seq; |
| 9859 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9860 | cfg->wake_len = wake_size; |
| 9861 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9862 | memcpy((void *)cfg->wake_data, |
| 9863 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9864 | wake_size); |
| 9865 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9866 | data_size + wake_size; |
| 9867 | memcpy((void *)cfg->wake_mask, |
| 9868 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9869 | wake_mask_size); |
| 9870 | if (tok) { |
| 9871 | cfg->tokens_size = tokens_size; |
| 9872 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9873 | } |
| 9874 | |
| 9875 | trig->tcp = cfg; |
| 9876 | |
| 9877 | return 0; |
| 9878 | } |
| 9879 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9880 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9881 | const struct wiphy_wowlan_support *wowlan, |
| 9882 | struct nlattr *attr, |
| 9883 | struct cfg80211_wowlan *trig) |
| 9884 | { |
| 9885 | struct nlattr **tb; |
| 9886 | int err; |
| 9887 | |
| 9888 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9889 | if (!tb) |
| 9890 | return -ENOMEM; |
| 9891 | |
| 9892 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9893 | err = -EOPNOTSUPP; |
| 9894 | goto out; |
| 9895 | } |
| 9896 | |
| 9897 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 9898 | nla_data(attr), nla_len(attr), |
| 9899 | nl80211_policy); |
| 9900 | if (err) |
| 9901 | goto out; |
| 9902 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9903 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9904 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9905 | if (err) |
| 9906 | trig->nd_config = NULL; |
| 9907 | |
| 9908 | out: |
| 9909 | kfree(tb); |
| 9910 | return err; |
| 9911 | } |
| 9912 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9913 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9914 | { |
| 9915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9916 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9917 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9918 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9919 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9920 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9921 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9922 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9923 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9924 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9925 | return -EOPNOTSUPP; |
| 9926 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9927 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9928 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9929 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9930 | goto set_wakeup; |
| 9931 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9932 | |
| 9933 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 9934 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9935 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 9936 | nl80211_wowlan_policy); |
| 9937 | if (err) |
| 9938 | return err; |
| 9939 | |
| 9940 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 9941 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 9942 | return -EINVAL; |
| 9943 | new_triggers.any = true; |
| 9944 | } |
| 9945 | |
| 9946 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9947 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9948 | return -EINVAL; |
| 9949 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9950 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9951 | } |
| 9952 | |
| 9953 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9954 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9955 | return -EINVAL; |
| 9956 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9957 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9958 | } |
| 9959 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9960 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9961 | return -EINVAL; |
| 9962 | |
| 9963 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9964 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9965 | return -EINVAL; |
| 9966 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9967 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9968 | } |
| 9969 | |
| 9970 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9971 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9972 | return -EINVAL; |
| 9973 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9974 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9975 | } |
| 9976 | |
| 9977 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9978 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9979 | return -EINVAL; |
| 9980 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9981 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9982 | } |
| 9983 | |
| 9984 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9985 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9986 | return -EINVAL; |
| 9987 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9988 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9989 | } |
| 9990 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9991 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9992 | struct nlattr *pat; |
| 9993 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9994 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9995 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9996 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9997 | regular = true; |
| 9998 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9999 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10000 | rem) |
| 10001 | n_patterns++; |
| 10002 | if (n_patterns > wowlan->n_patterns) |
| 10003 | return -EINVAL; |
| 10004 | |
| 10005 | new_triggers.patterns = kcalloc(n_patterns, |
| 10006 | sizeof(new_triggers.patterns[0]), |
| 10007 | GFP_KERNEL); |
| 10008 | if (!new_triggers.patterns) |
| 10009 | return -ENOMEM; |
| 10010 | |
| 10011 | new_triggers.n_patterns = n_patterns; |
| 10012 | i = 0; |
| 10013 | |
| 10014 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10015 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10016 | u8 *mask_pat; |
| 10017 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10018 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 10019 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10020 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10021 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10022 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10023 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10024 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10025 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10026 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10027 | goto error; |
| 10028 | if (pat_len > wowlan->pattern_max_len || |
| 10029 | pat_len < wowlan->pattern_min_len) |
| 10030 | goto error; |
| 10031 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10032 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10033 | pkt_offset = 0; |
| 10034 | else |
| 10035 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10036 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10037 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10038 | goto error; |
| 10039 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10040 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10041 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10042 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10043 | err = -ENOMEM; |
| 10044 | goto error; |
| 10045 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10046 | new_triggers.patterns[i].mask = mask_pat; |
| 10047 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10048 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10049 | mask_pat += mask_len; |
| 10050 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10051 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10052 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10053 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10054 | pat_len); |
| 10055 | i++; |
| 10056 | } |
| 10057 | } |
| 10058 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10059 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10060 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10061 | err = nl80211_parse_wowlan_tcp( |
| 10062 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10063 | &new_triggers); |
| 10064 | if (err) |
| 10065 | goto error; |
| 10066 | } |
| 10067 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10068 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10069 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10070 | err = nl80211_parse_wowlan_nd( |
| 10071 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10072 | &new_triggers); |
| 10073 | if (err) |
| 10074 | goto error; |
| 10075 | } |
| 10076 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10077 | /* The 'any' trigger means the device continues operating more or less |
| 10078 | * as in its normal operation mode and wakes up the host on most of the |
| 10079 | * normal interrupts (like packet RX, ...) |
| 10080 | * It therefore makes little sense to combine with the more constrained |
| 10081 | * wakeup trigger modes. |
| 10082 | */ |
| 10083 | if (new_triggers.any && regular) { |
| 10084 | err = -EINVAL; |
| 10085 | goto error; |
| 10086 | } |
| 10087 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10088 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10089 | if (!ntrig) { |
| 10090 | err = -ENOMEM; |
| 10091 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10092 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10093 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10094 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10095 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10096 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10097 | if (rdev->ops->set_wakeup && |
| 10098 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10099 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10100 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10101 | return 0; |
| 10102 | error: |
| 10103 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10104 | kfree(new_triggers.patterns[i].mask); |
| 10105 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10106 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10107 | sock_release(new_triggers.tcp->sock); |
| 10108 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10109 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10110 | return err; |
| 10111 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10112 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10113 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10114 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10115 | struct cfg80211_registered_device *rdev) |
| 10116 | { |
| 10117 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10118 | int i, j, pat_len; |
| 10119 | struct cfg80211_coalesce_rules *rule; |
| 10120 | |
| 10121 | if (!rdev->coalesce->n_rules) |
| 10122 | return 0; |
| 10123 | |
| 10124 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10125 | if (!nl_rules) |
| 10126 | return -ENOBUFS; |
| 10127 | |
| 10128 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10129 | nl_rule = nla_nest_start(msg, i + 1); |
| 10130 | if (!nl_rule) |
| 10131 | return -ENOBUFS; |
| 10132 | |
| 10133 | rule = &rdev->coalesce->rules[i]; |
| 10134 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10135 | rule->delay)) |
| 10136 | return -ENOBUFS; |
| 10137 | |
| 10138 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10139 | rule->condition)) |
| 10140 | return -ENOBUFS; |
| 10141 | |
| 10142 | nl_pats = nla_nest_start(msg, |
| 10143 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10144 | if (!nl_pats) |
| 10145 | return -ENOBUFS; |
| 10146 | |
| 10147 | for (j = 0; j < rule->n_patterns; j++) { |
| 10148 | nl_pat = nla_nest_start(msg, j + 1); |
| 10149 | if (!nl_pat) |
| 10150 | return -ENOBUFS; |
| 10151 | pat_len = rule->patterns[j].pattern_len; |
| 10152 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10153 | DIV_ROUND_UP(pat_len, 8), |
| 10154 | rule->patterns[j].mask) || |
| 10155 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10156 | rule->patterns[j].pattern) || |
| 10157 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10158 | rule->patterns[j].pkt_offset)) |
| 10159 | return -ENOBUFS; |
| 10160 | nla_nest_end(msg, nl_pat); |
| 10161 | } |
| 10162 | nla_nest_end(msg, nl_pats); |
| 10163 | nla_nest_end(msg, nl_rule); |
| 10164 | } |
| 10165 | nla_nest_end(msg, nl_rules); |
| 10166 | |
| 10167 | return 0; |
| 10168 | } |
| 10169 | |
| 10170 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10171 | { |
| 10172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10173 | struct sk_buff *msg; |
| 10174 | void *hdr; |
| 10175 | |
| 10176 | if (!rdev->wiphy.coalesce) |
| 10177 | return -EOPNOTSUPP; |
| 10178 | |
| 10179 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10180 | if (!msg) |
| 10181 | return -ENOMEM; |
| 10182 | |
| 10183 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10184 | NL80211_CMD_GET_COALESCE); |
| 10185 | if (!hdr) |
| 10186 | goto nla_put_failure; |
| 10187 | |
| 10188 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10189 | goto nla_put_failure; |
| 10190 | |
| 10191 | genlmsg_end(msg, hdr); |
| 10192 | return genlmsg_reply(msg, info); |
| 10193 | |
| 10194 | nla_put_failure: |
| 10195 | nlmsg_free(msg); |
| 10196 | return -ENOBUFS; |
| 10197 | } |
| 10198 | |
| 10199 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10200 | { |
| 10201 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10202 | int i, j; |
| 10203 | struct cfg80211_coalesce_rules *rule; |
| 10204 | |
| 10205 | if (!coalesce) |
| 10206 | return; |
| 10207 | |
| 10208 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10209 | rule = &coalesce->rules[i]; |
| 10210 | for (j = 0; j < rule->n_patterns; j++) |
| 10211 | kfree(rule->patterns[j].mask); |
| 10212 | kfree(rule->patterns); |
| 10213 | } |
| 10214 | kfree(coalesce->rules); |
| 10215 | kfree(coalesce); |
| 10216 | rdev->coalesce = NULL; |
| 10217 | } |
| 10218 | |
| 10219 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10220 | struct nlattr *rule, |
| 10221 | struct cfg80211_coalesce_rules *new_rule) |
| 10222 | { |
| 10223 | int err, i; |
| 10224 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10225 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10226 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10227 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10228 | |
| 10229 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 10230 | nla_len(rule), nl80211_coalesce_policy); |
| 10231 | if (err) |
| 10232 | return err; |
| 10233 | |
| 10234 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10235 | new_rule->delay = |
| 10236 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10237 | if (new_rule->delay > coalesce->max_delay) |
| 10238 | return -EINVAL; |
| 10239 | |
| 10240 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10241 | new_rule->condition = |
| 10242 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10243 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10244 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10245 | return -EINVAL; |
| 10246 | |
| 10247 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10248 | return -EINVAL; |
| 10249 | |
| 10250 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10251 | rem) |
| 10252 | n_patterns++; |
| 10253 | if (n_patterns > coalesce->n_patterns) |
| 10254 | return -EINVAL; |
| 10255 | |
| 10256 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10257 | GFP_KERNEL); |
| 10258 | if (!new_rule->patterns) |
| 10259 | return -ENOMEM; |
| 10260 | |
| 10261 | new_rule->n_patterns = n_patterns; |
| 10262 | i = 0; |
| 10263 | |
| 10264 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10265 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10266 | u8 *mask_pat; |
| 10267 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10268 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 10269 | nla_len(pat), NULL); |
| 10270 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10271 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10272 | return -EINVAL; |
| 10273 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10274 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10275 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10276 | return -EINVAL; |
| 10277 | if (pat_len > coalesce->pattern_max_len || |
| 10278 | pat_len < coalesce->pattern_min_len) |
| 10279 | return -EINVAL; |
| 10280 | |
| 10281 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10282 | pkt_offset = 0; |
| 10283 | else |
| 10284 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10285 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10286 | return -EINVAL; |
| 10287 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10288 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10289 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10290 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10291 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10292 | |
| 10293 | new_rule->patterns[i].mask = mask_pat; |
| 10294 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10295 | mask_len); |
| 10296 | |
| 10297 | mask_pat += mask_len; |
| 10298 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10299 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10300 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10301 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10302 | i++; |
| 10303 | } |
| 10304 | |
| 10305 | return 0; |
| 10306 | } |
| 10307 | |
| 10308 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10309 | { |
| 10310 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10311 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10312 | struct cfg80211_coalesce new_coalesce = {}; |
| 10313 | struct cfg80211_coalesce *n_coalesce; |
| 10314 | int err, rem_rule, n_rules = 0, i, j; |
| 10315 | struct nlattr *rule; |
| 10316 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10317 | |
| 10318 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10319 | return -EOPNOTSUPP; |
| 10320 | |
| 10321 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10322 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10323 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10324 | return 0; |
| 10325 | } |
| 10326 | |
| 10327 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10328 | rem_rule) |
| 10329 | n_rules++; |
| 10330 | if (n_rules > coalesce->n_rules) |
| 10331 | return -EINVAL; |
| 10332 | |
| 10333 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10334 | GFP_KERNEL); |
| 10335 | if (!new_coalesce.rules) |
| 10336 | return -ENOMEM; |
| 10337 | |
| 10338 | new_coalesce.n_rules = n_rules; |
| 10339 | i = 0; |
| 10340 | |
| 10341 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10342 | rem_rule) { |
| 10343 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10344 | &new_coalesce.rules[i]); |
| 10345 | if (err) |
| 10346 | goto error; |
| 10347 | |
| 10348 | i++; |
| 10349 | } |
| 10350 | |
Ilan Peer | a1056b1 | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10351 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10352 | if (err) |
| 10353 | goto error; |
| 10354 | |
| 10355 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10356 | if (!n_coalesce) { |
| 10357 | err = -ENOMEM; |
| 10358 | goto error; |
| 10359 | } |
| 10360 | cfg80211_rdev_free_coalesce(rdev); |
| 10361 | rdev->coalesce = n_coalesce; |
| 10362 | |
| 10363 | return 0; |
| 10364 | error: |
| 10365 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10366 | tmp_rule = &new_coalesce.rules[i]; |
| 10367 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10368 | kfree(tmp_rule->patterns[j].mask); |
| 10369 | kfree(tmp_rule->patterns); |
| 10370 | } |
| 10371 | kfree(new_coalesce.rules); |
| 10372 | |
| 10373 | return err; |
| 10374 | } |
| 10375 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10376 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10377 | { |
| 10378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10379 | struct net_device *dev = info->user_ptr[1]; |
| 10380 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10381 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10382 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10383 | int err; |
| 10384 | |
| 10385 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10386 | return -EINVAL; |
| 10387 | |
| 10388 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 10389 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10390 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 10391 | nl80211_rekey_policy); |
| 10392 | if (err) |
| 10393 | return err; |
| 10394 | |
| 10395 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10396 | return -ERANGE; |
| 10397 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10398 | return -ERANGE; |
| 10399 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10400 | return -ERANGE; |
| 10401 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10402 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10403 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10404 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10405 | |
| 10406 | wdev_lock(wdev); |
| 10407 | if (!wdev->current_bss) { |
| 10408 | err = -ENOTCONN; |
| 10409 | goto out; |
| 10410 | } |
| 10411 | |
| 10412 | if (!rdev->ops->set_rekey_data) { |
| 10413 | err = -EOPNOTSUPP; |
| 10414 | goto out; |
| 10415 | } |
| 10416 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10417 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10418 | out: |
| 10419 | wdev_unlock(wdev); |
| 10420 | return err; |
| 10421 | } |
| 10422 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10423 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10424 | struct genl_info *info) |
| 10425 | { |
| 10426 | struct net_device *dev = info->user_ptr[1]; |
| 10427 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10428 | |
| 10429 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10430 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10431 | return -EINVAL; |
| 10432 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10433 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10434 | return -EBUSY; |
| 10435 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10436 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10437 | return 0; |
| 10438 | } |
| 10439 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10440 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10441 | struct genl_info *info) |
| 10442 | { |
| 10443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10444 | struct net_device *dev = info->user_ptr[1]; |
| 10445 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10446 | struct sk_buff *msg; |
| 10447 | void *hdr; |
| 10448 | const u8 *addr; |
| 10449 | u64 cookie; |
| 10450 | int err; |
| 10451 | |
| 10452 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10453 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10454 | return -EOPNOTSUPP; |
| 10455 | |
| 10456 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10457 | return -EINVAL; |
| 10458 | |
| 10459 | if (!rdev->ops->probe_client) |
| 10460 | return -EOPNOTSUPP; |
| 10461 | |
| 10462 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10463 | if (!msg) |
| 10464 | return -ENOMEM; |
| 10465 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10466 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10467 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10468 | if (!hdr) { |
| 10469 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10470 | goto free_msg; |
| 10471 | } |
| 10472 | |
| 10473 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10474 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10475 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10476 | if (err) |
| 10477 | goto free_msg; |
| 10478 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10479 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10480 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10481 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10482 | |
| 10483 | genlmsg_end(msg, hdr); |
| 10484 | |
| 10485 | return genlmsg_reply(msg, info); |
| 10486 | |
| 10487 | nla_put_failure: |
| 10488 | err = -ENOBUFS; |
| 10489 | free_msg: |
| 10490 | nlmsg_free(msg); |
| 10491 | return err; |
| 10492 | } |
| 10493 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10494 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10495 | { |
| 10496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10497 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10498 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10499 | |
| 10500 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10501 | return -EOPNOTSUPP; |
| 10502 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10503 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10504 | if (!nreg) |
| 10505 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10506 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10507 | /* First, check if already registered. */ |
| 10508 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10509 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10510 | if (reg->nlportid == info->snd_portid) { |
| 10511 | rv = -EALREADY; |
| 10512 | goto out_err; |
| 10513 | } |
| 10514 | } |
| 10515 | /* Add it to the list */ |
| 10516 | nreg->nlportid = info->snd_portid; |
| 10517 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10518 | |
| 10519 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10520 | |
| 10521 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10522 | out_err: |
| 10523 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10524 | kfree(nreg); |
| 10525 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10526 | } |
| 10527 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10528 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10529 | { |
| 10530 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10531 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10532 | int err; |
| 10533 | |
| 10534 | if (!rdev->ops->start_p2p_device) |
| 10535 | return -EOPNOTSUPP; |
| 10536 | |
| 10537 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10538 | return -EOPNOTSUPP; |
| 10539 | |
| 10540 | if (wdev->p2p_started) |
| 10541 | return 0; |
| 10542 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10543 | if (rfkill_blocked(rdev->rfkill)) |
| 10544 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10545 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10546 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10547 | if (err) |
| 10548 | return err; |
| 10549 | |
| 10550 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10551 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10552 | |
| 10553 | return 0; |
| 10554 | } |
| 10555 | |
| 10556 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10557 | { |
| 10558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10559 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10560 | |
| 10561 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10562 | return -EOPNOTSUPP; |
| 10563 | |
| 10564 | if (!rdev->ops->stop_p2p_device) |
| 10565 | return -EOPNOTSUPP; |
| 10566 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10567 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10568 | |
| 10569 | return 0; |
| 10570 | } |
| 10571 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10572 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 10573 | { |
| 10574 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10575 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10576 | struct cfg80211_nan_conf conf = {}; |
| 10577 | int err; |
| 10578 | |
| 10579 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10580 | return -EOPNOTSUPP; |
| 10581 | |
| 10582 | if (wdev->nan_started) |
| 10583 | return -EEXIST; |
| 10584 | |
| 10585 | if (rfkill_blocked(rdev->rfkill)) |
| 10586 | return -ERFKILL; |
| 10587 | |
| 10588 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 10589 | return -EINVAL; |
| 10590 | |
| 10591 | if (!info->attrs[NL80211_ATTR_NAN_DUAL]) |
| 10592 | return -EINVAL; |
| 10593 | |
| 10594 | conf.master_pref = |
| 10595 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 10596 | if (!conf.master_pref) |
| 10597 | return -EINVAL; |
| 10598 | |
| 10599 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 10600 | |
| 10601 | err = rdev_start_nan(rdev, wdev, &conf); |
| 10602 | if (err) |
| 10603 | return err; |
| 10604 | |
| 10605 | wdev->nan_started = true; |
| 10606 | rdev->opencount++; |
| 10607 | |
| 10608 | return 0; |
| 10609 | } |
| 10610 | |
| 10611 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 10612 | { |
| 10613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10614 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10615 | |
| 10616 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10617 | return -EOPNOTSUPP; |
| 10618 | |
| 10619 | cfg80211_stop_nan(rdev, wdev); |
| 10620 | |
| 10621 | return 0; |
| 10622 | } |
| 10623 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10624 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 10625 | { |
| 10626 | struct nlattr *attr; |
| 10627 | int len = 0, n_entries = 0, rem; |
| 10628 | |
| 10629 | nla_for_each_nested(attr, filter_attr, rem) { |
| 10630 | len += nla_len(attr); |
| 10631 | n_entries++; |
| 10632 | } |
| 10633 | |
| 10634 | if (len >= U8_MAX) |
| 10635 | return -EINVAL; |
| 10636 | |
| 10637 | return n_entries; |
| 10638 | } |
| 10639 | |
| 10640 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 10641 | struct cfg80211_nan_func *func, |
| 10642 | bool tx) |
| 10643 | { |
| 10644 | struct nlattr *attr; |
| 10645 | int n_entries, rem, i; |
| 10646 | struct cfg80211_nan_func_filter *filter; |
| 10647 | |
| 10648 | n_entries = validate_nan_filter(attr_filter); |
| 10649 | if (n_entries < 0) |
| 10650 | return n_entries; |
| 10651 | |
| 10652 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 10653 | |
| 10654 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 10655 | if (!filter) |
| 10656 | return -ENOMEM; |
| 10657 | |
| 10658 | i = 0; |
| 10659 | nla_for_each_nested(attr, attr_filter, rem) { |
| 10660 | filter[i].filter = kmemdup(nla_data(attr), nla_len(attr), |
| 10661 | GFP_KERNEL); |
| 10662 | filter[i].len = nla_len(attr); |
| 10663 | i++; |
| 10664 | } |
| 10665 | if (tx) { |
| 10666 | func->num_tx_filters = n_entries; |
| 10667 | func->tx_filters = filter; |
| 10668 | } else { |
| 10669 | func->num_rx_filters = n_entries; |
| 10670 | func->rx_filters = filter; |
| 10671 | } |
| 10672 | |
| 10673 | return 0; |
| 10674 | } |
| 10675 | |
| 10676 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 10677 | struct genl_info *info) |
| 10678 | { |
| 10679 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10680 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10681 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 10682 | struct cfg80211_nan_func *func; |
| 10683 | struct sk_buff *msg = NULL; |
| 10684 | void *hdr = NULL; |
| 10685 | int err = 0; |
| 10686 | |
| 10687 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10688 | return -EOPNOTSUPP; |
| 10689 | |
| 10690 | if (!wdev->nan_started) |
| 10691 | return -ENOTCONN; |
| 10692 | |
| 10693 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 10694 | return -EINVAL; |
| 10695 | |
| 10696 | if (wdev->owner_nlportid && |
| 10697 | wdev->owner_nlportid != info->snd_portid) |
| 10698 | return -ENOTCONN; |
| 10699 | |
| 10700 | err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 10701 | nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]), |
| 10702 | nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]), |
| 10703 | nl80211_nan_func_policy); |
| 10704 | if (err) |
| 10705 | return err; |
| 10706 | |
| 10707 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 10708 | if (!func) |
| 10709 | return -ENOMEM; |
| 10710 | |
| 10711 | func->cookie = wdev->wiphy->cookie_counter++; |
| 10712 | |
| 10713 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 10714 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 10715 | err = -EINVAL; |
| 10716 | goto out; |
| 10717 | } |
| 10718 | |
| 10719 | |
| 10720 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 10721 | |
| 10722 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 10723 | err = -EINVAL; |
| 10724 | goto out; |
| 10725 | } |
| 10726 | |
| 10727 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 10728 | sizeof(func->service_id)); |
| 10729 | |
| 10730 | func->close_range = |
| 10731 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 10732 | |
| 10733 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 10734 | func->serv_spec_info_len = |
| 10735 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 10736 | func->serv_spec_info = |
| 10737 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 10738 | func->serv_spec_info_len, |
| 10739 | GFP_KERNEL); |
| 10740 | if (!func->serv_spec_info) { |
| 10741 | err = -ENOMEM; |
| 10742 | goto out; |
| 10743 | } |
| 10744 | } |
| 10745 | |
| 10746 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 10747 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 10748 | |
| 10749 | switch (func->type) { |
| 10750 | case NL80211_NAN_FUNC_PUBLISH: |
| 10751 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 10752 | err = -EINVAL; |
| 10753 | goto out; |
| 10754 | } |
| 10755 | |
| 10756 | func->publish_type = |
| 10757 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 10758 | func->publish_bcast = |
| 10759 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 10760 | |
| 10761 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 10762 | func->publish_bcast) { |
| 10763 | err = -EINVAL; |
| 10764 | goto out; |
| 10765 | } |
| 10766 | break; |
| 10767 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 10768 | func->subscribe_active = |
| 10769 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 10770 | break; |
| 10771 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 10772 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 10773 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 10774 | err = -EINVAL; |
| 10775 | goto out; |
| 10776 | } |
| 10777 | |
| 10778 | func->followup_id = |
| 10779 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 10780 | func->followup_reqid = |
| 10781 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 10782 | memcpy(func->followup_dest.addr, |
| 10783 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 10784 | sizeof(func->followup_dest.addr)); |
| 10785 | if (func->ttl) { |
| 10786 | err = -EINVAL; |
| 10787 | goto out; |
| 10788 | } |
| 10789 | break; |
| 10790 | default: |
| 10791 | err = -EINVAL; |
| 10792 | goto out; |
| 10793 | } |
| 10794 | |
| 10795 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 10796 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 10797 | |
| 10798 | err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 10799 | nla_data(tb[NL80211_NAN_FUNC_SRF]), |
| 10800 | nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL); |
| 10801 | if (err) |
| 10802 | goto out; |
| 10803 | |
| 10804 | func->srf_include = |
| 10805 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 10806 | |
| 10807 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 10808 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 10809 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 10810 | err = -EINVAL; |
| 10811 | goto out; |
| 10812 | } |
| 10813 | |
| 10814 | func->srf_bf_len = |
| 10815 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 10816 | func->srf_bf = |
| 10817 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 10818 | func->srf_bf_len, GFP_KERNEL); |
| 10819 | if (!func->srf_bf) { |
| 10820 | err = -ENOMEM; |
| 10821 | goto out; |
| 10822 | } |
| 10823 | |
| 10824 | func->srf_bf_idx = |
| 10825 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 10826 | } else { |
| 10827 | struct nlattr *attr, *mac_attr = |
| 10828 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 10829 | int n_entries, rem, i = 0; |
| 10830 | |
| 10831 | if (!mac_attr) { |
| 10832 | err = -EINVAL; |
| 10833 | goto out; |
| 10834 | } |
| 10835 | |
| 10836 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 10837 | if (n_entries <= 0) { |
| 10838 | err = -EINVAL; |
| 10839 | goto out; |
| 10840 | } |
| 10841 | |
| 10842 | func->srf_num_macs = n_entries; |
| 10843 | func->srf_macs = |
| 10844 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 10845 | GFP_KERNEL); |
| 10846 | if (!func->srf_macs) { |
| 10847 | err = -ENOMEM; |
| 10848 | goto out; |
| 10849 | } |
| 10850 | |
| 10851 | nla_for_each_nested(attr, mac_attr, rem) |
| 10852 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 10853 | sizeof(*func->srf_macs)); |
| 10854 | } |
| 10855 | } |
| 10856 | |
| 10857 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 10858 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 10859 | func, true); |
| 10860 | if (err) |
| 10861 | goto out; |
| 10862 | } |
| 10863 | |
| 10864 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 10865 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 10866 | func, false); |
| 10867 | if (err) |
| 10868 | goto out; |
| 10869 | } |
| 10870 | |
| 10871 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10872 | if (!msg) { |
| 10873 | err = -ENOMEM; |
| 10874 | goto out; |
| 10875 | } |
| 10876 | |
| 10877 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10878 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 10879 | /* This can't really happen - we just allocated 4KB */ |
| 10880 | if (WARN_ON(!hdr)) { |
| 10881 | err = -ENOMEM; |
| 10882 | goto out; |
| 10883 | } |
| 10884 | |
| 10885 | err = rdev_add_nan_func(rdev, wdev, func); |
| 10886 | out: |
| 10887 | if (err < 0) { |
| 10888 | cfg80211_free_nan_func(func); |
| 10889 | nlmsg_free(msg); |
| 10890 | return err; |
| 10891 | } |
| 10892 | |
| 10893 | /* propagate the instance id and cookie to userspace */ |
| 10894 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 10895 | NL80211_ATTR_PAD)) |
| 10896 | goto nla_put_failure; |
| 10897 | |
| 10898 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 10899 | if (!func_attr) |
| 10900 | goto nla_put_failure; |
| 10901 | |
| 10902 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 10903 | func->instance_id)) |
| 10904 | goto nla_put_failure; |
| 10905 | |
| 10906 | nla_nest_end(msg, func_attr); |
| 10907 | |
| 10908 | genlmsg_end(msg, hdr); |
| 10909 | return genlmsg_reply(msg, info); |
| 10910 | |
| 10911 | nla_put_failure: |
| 10912 | nlmsg_free(msg); |
| 10913 | return -ENOBUFS; |
| 10914 | } |
| 10915 | |
| 10916 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 10917 | struct genl_info *info) |
| 10918 | { |
| 10919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10920 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10921 | u64 cookie; |
| 10922 | |
| 10923 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10924 | return -EOPNOTSUPP; |
| 10925 | |
| 10926 | if (!wdev->nan_started) |
| 10927 | return -ENOTCONN; |
| 10928 | |
| 10929 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10930 | return -EINVAL; |
| 10931 | |
| 10932 | if (wdev->owner_nlportid && |
| 10933 | wdev->owner_nlportid != info->snd_portid) |
| 10934 | return -ENOTCONN; |
| 10935 | |
| 10936 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10937 | |
| 10938 | rdev_del_nan_func(rdev, wdev, cookie); |
| 10939 | |
| 10940 | return 0; |
| 10941 | } |
| 10942 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 10943 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 10944 | struct genl_info *info) |
| 10945 | { |
| 10946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10947 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10948 | struct cfg80211_nan_conf conf = {}; |
| 10949 | u32 changed = 0; |
| 10950 | |
| 10951 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10952 | return -EOPNOTSUPP; |
| 10953 | |
| 10954 | if (!wdev->nan_started) |
| 10955 | return -ENOTCONN; |
| 10956 | |
| 10957 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 10958 | conf.master_pref = |
| 10959 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 10960 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 10961 | return -EINVAL; |
| 10962 | |
| 10963 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 10964 | } |
| 10965 | |
| 10966 | if (info->attrs[NL80211_ATTR_NAN_DUAL]) { |
| 10967 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 10968 | changed |= CFG80211_NAN_CONF_CHANGED_DUAL; |
| 10969 | } |
| 10970 | |
| 10971 | if (!changed) |
| 10972 | return -EINVAL; |
| 10973 | |
| 10974 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 10975 | } |
| 10976 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 10977 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 10978 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 10979 | { |
| 10980 | struct wiphy *wiphy = wdev->wiphy; |
| 10981 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 10982 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 10983 | struct sk_buff *msg; |
| 10984 | void *hdr; |
| 10985 | |
| 10986 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 10987 | return; |
| 10988 | |
| 10989 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10990 | if (!msg) |
| 10991 | return; |
| 10992 | |
| 10993 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 10994 | if (!hdr) { |
| 10995 | nlmsg_free(msg); |
| 10996 | return; |
| 10997 | } |
| 10998 | |
| 10999 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11000 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11001 | wdev->netdev->ifindex)) || |
| 11002 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11003 | NL80211_ATTR_PAD)) |
| 11004 | goto nla_put_failure; |
| 11005 | |
| 11006 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11007 | NL80211_ATTR_PAD) || |
| 11008 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11009 | goto nla_put_failure; |
| 11010 | |
| 11011 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11012 | if (!match_attr) |
| 11013 | goto nla_put_failure; |
| 11014 | |
| 11015 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11016 | if (!local_func_attr) |
| 11017 | goto nla_put_failure; |
| 11018 | |
| 11019 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11020 | goto nla_put_failure; |
| 11021 | |
| 11022 | nla_nest_end(msg, local_func_attr); |
| 11023 | |
| 11024 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11025 | if (!peer_func_attr) |
| 11026 | goto nla_put_failure; |
| 11027 | |
| 11028 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11029 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11030 | goto nla_put_failure; |
| 11031 | |
| 11032 | if (match->info && match->info_len && |
| 11033 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11034 | match->info)) |
| 11035 | goto nla_put_failure; |
| 11036 | |
| 11037 | nla_nest_end(msg, peer_func_attr); |
| 11038 | nla_nest_end(msg, match_attr); |
| 11039 | genlmsg_end(msg, hdr); |
| 11040 | |
| 11041 | if (!wdev->owner_nlportid) |
| 11042 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11043 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11044 | else |
| 11045 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11046 | wdev->owner_nlportid); |
| 11047 | |
| 11048 | return; |
| 11049 | |
| 11050 | nla_put_failure: |
| 11051 | nlmsg_free(msg); |
| 11052 | } |
| 11053 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11054 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11055 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11056 | u8 inst_id, |
| 11057 | enum nl80211_nan_func_term_reason reason, |
| 11058 | u64 cookie, gfp_t gfp) |
| 11059 | { |
| 11060 | struct wiphy *wiphy = wdev->wiphy; |
| 11061 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11062 | struct sk_buff *msg; |
| 11063 | struct nlattr *func_attr; |
| 11064 | void *hdr; |
| 11065 | |
| 11066 | if (WARN_ON(!inst_id)) |
| 11067 | return; |
| 11068 | |
| 11069 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11070 | if (!msg) |
| 11071 | return; |
| 11072 | |
| 11073 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11074 | if (!hdr) { |
| 11075 | nlmsg_free(msg); |
| 11076 | return; |
| 11077 | } |
| 11078 | |
| 11079 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11080 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11081 | wdev->netdev->ifindex)) || |
| 11082 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11083 | NL80211_ATTR_PAD)) |
| 11084 | goto nla_put_failure; |
| 11085 | |
| 11086 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11087 | NL80211_ATTR_PAD)) |
| 11088 | goto nla_put_failure; |
| 11089 | |
| 11090 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11091 | if (!func_attr) |
| 11092 | goto nla_put_failure; |
| 11093 | |
| 11094 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11095 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11096 | goto nla_put_failure; |
| 11097 | |
| 11098 | nla_nest_end(msg, func_attr); |
| 11099 | genlmsg_end(msg, hdr); |
| 11100 | |
| 11101 | if (!wdev->owner_nlportid) |
| 11102 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11103 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11104 | else |
| 11105 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11106 | wdev->owner_nlportid); |
| 11107 | |
| 11108 | return; |
| 11109 | |
| 11110 | nla_put_failure: |
| 11111 | nlmsg_free(msg); |
| 11112 | } |
| 11113 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11114 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11115 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11116 | struct genl_info *info) |
| 11117 | { |
| 11118 | void *hdr; |
| 11119 | struct sk_buff *msg; |
| 11120 | |
| 11121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11122 | if (!msg) |
| 11123 | return -ENOMEM; |
| 11124 | |
| 11125 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11126 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11127 | if (!hdr) |
| 11128 | goto nla_put_failure; |
| 11129 | |
| 11130 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11131 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11132 | goto nla_put_failure; |
| 11133 | |
| 11134 | genlmsg_end(msg, hdr); |
| 11135 | return genlmsg_reply(msg, info); |
| 11136 | |
| 11137 | nla_put_failure: |
| 11138 | kfree_skb(msg); |
| 11139 | return -ENOBUFS; |
| 11140 | } |
| 11141 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11142 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11143 | { |
| 11144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11145 | struct cfg80211_update_ft_ies_params ft_params; |
| 11146 | struct net_device *dev = info->user_ptr[1]; |
| 11147 | |
| 11148 | if (!rdev->ops->update_ft_ies) |
| 11149 | return -EOPNOTSUPP; |
| 11150 | |
| 11151 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11152 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11153 | return -EINVAL; |
| 11154 | |
| 11155 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11156 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11157 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11158 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11159 | |
| 11160 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11161 | } |
| 11162 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11163 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11164 | struct genl_info *info) |
| 11165 | { |
| 11166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11167 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11168 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11169 | u16 duration; |
| 11170 | int ret; |
| 11171 | |
| 11172 | if (!rdev->ops->crit_proto_start) |
| 11173 | return -EOPNOTSUPP; |
| 11174 | |
| 11175 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11176 | return -EINVAL; |
| 11177 | |
| 11178 | if (rdev->crit_proto_nlportid) |
| 11179 | return -EBUSY; |
| 11180 | |
| 11181 | /* determine protocol if provided */ |
| 11182 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11183 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11184 | |
| 11185 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11186 | return -EINVAL; |
| 11187 | |
| 11188 | /* timeout must be provided */ |
| 11189 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11190 | return -EINVAL; |
| 11191 | |
| 11192 | duration = |
| 11193 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11194 | |
| 11195 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11196 | return -ERANGE; |
| 11197 | |
| 11198 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11199 | if (!ret) |
| 11200 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11201 | |
| 11202 | return ret; |
| 11203 | } |
| 11204 | |
| 11205 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11206 | struct genl_info *info) |
| 11207 | { |
| 11208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11209 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11210 | |
| 11211 | if (!rdev->ops->crit_proto_stop) |
| 11212 | return -EOPNOTSUPP; |
| 11213 | |
| 11214 | if (rdev->crit_proto_nlportid) { |
| 11215 | rdev->crit_proto_nlportid = 0; |
| 11216 | rdev_crit_proto_stop(rdev, wdev); |
| 11217 | } |
| 11218 | return 0; |
| 11219 | } |
| 11220 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11221 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11222 | { |
| 11223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11224 | struct wireless_dev *wdev = |
| 11225 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11226 | int i, err; |
| 11227 | u32 vid, subcmd; |
| 11228 | |
| 11229 | if (!rdev->wiphy.vendor_commands) |
| 11230 | return -EOPNOTSUPP; |
| 11231 | |
| 11232 | if (IS_ERR(wdev)) { |
| 11233 | err = PTR_ERR(wdev); |
| 11234 | if (err != -EINVAL) |
| 11235 | return err; |
| 11236 | wdev = NULL; |
| 11237 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11238 | return -EINVAL; |
| 11239 | } |
| 11240 | |
| 11241 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11242 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11243 | return -EINVAL; |
| 11244 | |
| 11245 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11246 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11247 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11248 | const struct wiphy_vendor_command *vcmd; |
| 11249 | void *data = NULL; |
| 11250 | int len = 0; |
| 11251 | |
| 11252 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11253 | |
| 11254 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11255 | continue; |
| 11256 | |
| 11257 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11258 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11259 | if (!wdev) |
| 11260 | return -EINVAL; |
| 11261 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11262 | !wdev->netdev) |
| 11263 | return -EINVAL; |
| 11264 | |
| 11265 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 11266 | if (wdev->netdev && |
| 11267 | !netif_running(wdev->netdev)) |
| 11268 | return -ENETDOWN; |
| 11269 | if (!wdev->netdev && !wdev->p2p_started) |
| 11270 | return -ENETDOWN; |
| 11271 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11272 | |
| 11273 | if (!vcmd->doit) |
| 11274 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11275 | } else { |
| 11276 | wdev = NULL; |
| 11277 | } |
| 11278 | |
| 11279 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11280 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11281 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11282 | } |
| 11283 | |
| 11284 | rdev->cur_cmd_info = info; |
| 11285 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11286 | data, len); |
| 11287 | rdev->cur_cmd_info = NULL; |
| 11288 | return err; |
| 11289 | } |
| 11290 | |
| 11291 | return -EOPNOTSUPP; |
| 11292 | } |
| 11293 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11294 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11295 | struct netlink_callback *cb, |
| 11296 | struct cfg80211_registered_device **rdev, |
| 11297 | struct wireless_dev **wdev) |
| 11298 | { |
| 11299 | u32 vid, subcmd; |
| 11300 | unsigned int i; |
| 11301 | int vcmd_idx = -1; |
| 11302 | int err; |
| 11303 | void *data = NULL; |
| 11304 | unsigned int data_len = 0; |
| 11305 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11306 | if (cb->args[0]) { |
| 11307 | /* subtract the 1 again here */ |
| 11308 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11309 | struct wireless_dev *tmp; |
| 11310 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11311 | if (!wiphy) |
| 11312 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11313 | *rdev = wiphy_to_rdev(wiphy); |
| 11314 | *wdev = NULL; |
| 11315 | |
| 11316 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11317 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11318 | if (tmp->identifier == cb->args[1] - 1) { |
| 11319 | *wdev = tmp; |
| 11320 | break; |
| 11321 | } |
| 11322 | } |
| 11323 | } |
| 11324 | |
| 11325 | /* keep rtnl locked in successful case */ |
| 11326 | return 0; |
| 11327 | } |
| 11328 | |
| 11329 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 11330 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 11331 | nl80211_policy); |
| 11332 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11333 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11334 | |
| 11335 | if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11336 | !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11337 | return -EINVAL; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11338 | |
| 11339 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 11340 | nl80211_fam.attrbuf); |
| 11341 | if (IS_ERR(*wdev)) |
| 11342 | *wdev = NULL; |
| 11343 | |
| 11344 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 11345 | nl80211_fam.attrbuf); |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11346 | if (IS_ERR(*rdev)) |
| 11347 | return PTR_ERR(*rdev); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11348 | |
| 11349 | vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11350 | subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11351 | |
| 11352 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11353 | const struct wiphy_vendor_command *vcmd; |
| 11354 | |
| 11355 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11356 | |
| 11357 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11358 | continue; |
| 11359 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11360 | if (!vcmd->dumpit) |
| 11361 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11362 | |
| 11363 | vcmd_idx = i; |
| 11364 | break; |
| 11365 | } |
| 11366 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11367 | if (vcmd_idx < 0) |
| 11368 | return -EOPNOTSUPP; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11369 | |
| 11370 | if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11371 | data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11372 | data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11373 | } |
| 11374 | |
| 11375 | /* 0 is the first index - add 1 to parse only once */ |
| 11376 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11377 | /* add 1 to know if it was NULL */ |
| 11378 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11379 | cb->args[2] = vcmd_idx; |
| 11380 | cb->args[3] = (unsigned long)data; |
| 11381 | cb->args[4] = data_len; |
| 11382 | |
| 11383 | /* keep rtnl locked in successful case */ |
| 11384 | return 0; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11385 | } |
| 11386 | |
| 11387 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11388 | struct netlink_callback *cb) |
| 11389 | { |
| 11390 | struct cfg80211_registered_device *rdev; |
| 11391 | struct wireless_dev *wdev; |
| 11392 | unsigned int vcmd_idx; |
| 11393 | const struct wiphy_vendor_command *vcmd; |
| 11394 | void *data; |
| 11395 | int data_len; |
| 11396 | int err; |
| 11397 | struct nlattr *vendor_data; |
| 11398 | |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11399 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11400 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11401 | if (err) |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11402 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11403 | |
| 11404 | vcmd_idx = cb->args[2]; |
| 11405 | data = (void *)cb->args[3]; |
| 11406 | data_len = cb->args[4]; |
| 11407 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11408 | |
| 11409 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11410 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11411 | if (!wdev) { |
| 11412 | err = -EINVAL; |
| 11413 | goto out; |
| 11414 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11415 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11416 | !wdev->netdev) { |
| 11417 | err = -EINVAL; |
| 11418 | goto out; |
| 11419 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11420 | |
| 11421 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 11422 | if (wdev->netdev && |
Johannes Berg | 56769e7 | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 11423 | !netif_running(wdev->netdev)) { |
| 11424 | err = -ENETDOWN; |
| 11425 | goto out; |
| 11426 | } |
| 11427 | if (!wdev->netdev && !wdev->p2p_started) { |
| 11428 | err = -ENETDOWN; |
| 11429 | goto out; |
| 11430 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11431 | } |
| 11432 | } |
| 11433 | |
| 11434 | while (1) { |
| 11435 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11436 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11437 | NL80211_CMD_VENDOR); |
| 11438 | if (!hdr) |
| 11439 | break; |
| 11440 | |
| 11441 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11442 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11443 | wdev_id(wdev), |
| 11444 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11445 | genlmsg_cancel(skb, hdr); |
| 11446 | break; |
| 11447 | } |
| 11448 | |
| 11449 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11450 | if (!vendor_data) { |
| 11451 | genlmsg_cancel(skb, hdr); |
| 11452 | break; |
| 11453 | } |
| 11454 | |
| 11455 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11456 | (unsigned long *)&cb->args[5]); |
| 11457 | nla_nest_end(skb, vendor_data); |
| 11458 | |
| 11459 | if (err == -ENOBUFS || err == -ENOENT) { |
| 11460 | genlmsg_cancel(skb, hdr); |
| 11461 | break; |
| 11462 | } else if (err) { |
| 11463 | genlmsg_cancel(skb, hdr); |
| 11464 | goto out; |
| 11465 | } |
| 11466 | |
| 11467 | genlmsg_end(skb, hdr); |
| 11468 | } |
| 11469 | |
| 11470 | err = skb->len; |
| 11471 | out: |
| 11472 | rtnl_unlock(); |
| 11473 | return err; |
| 11474 | } |
| 11475 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11476 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 11477 | enum nl80211_commands cmd, |
| 11478 | enum nl80211_attrs attr, |
| 11479 | int approxlen) |
| 11480 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11481 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11482 | |
| 11483 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 11484 | return NULL; |
| 11485 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 11486 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11487 | rdev->cur_cmd_info->snd_portid, |
| 11488 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 11489 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11490 | } |
| 11491 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 11492 | |
| 11493 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 11494 | { |
| 11495 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 11496 | void *hdr = ((void **)skb->cb)[1]; |
| 11497 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 11498 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 11499 | /* clear CB data for netlink core to own from now on */ |
| 11500 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 11501 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11502 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 11503 | kfree_skb(skb); |
| 11504 | return -EINVAL; |
| 11505 | } |
| 11506 | |
| 11507 | nla_nest_end(skb, data); |
| 11508 | genlmsg_end(skb, hdr); |
| 11509 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 11510 | } |
| 11511 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 11512 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11513 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 11514 | struct genl_info *info) |
| 11515 | { |
| 11516 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11517 | struct cfg80211_qos_map *qos_map = NULL; |
| 11518 | struct net_device *dev = info->user_ptr[1]; |
| 11519 | u8 *pos, len, num_des, des_len, des; |
| 11520 | int ret; |
| 11521 | |
| 11522 | if (!rdev->ops->set_qos_map) |
| 11523 | return -EOPNOTSUPP; |
| 11524 | |
| 11525 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 11526 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11527 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11528 | |
| 11529 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 11530 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 11531 | return -EINVAL; |
| 11532 | |
| 11533 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 11534 | if (!qos_map) |
| 11535 | return -ENOMEM; |
| 11536 | |
| 11537 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 11538 | if (num_des) { |
| 11539 | des_len = num_des * |
| 11540 | sizeof(struct cfg80211_dscp_exception); |
| 11541 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 11542 | qos_map->num_des = num_des; |
| 11543 | for (des = 0; des < num_des; des++) { |
| 11544 | if (qos_map->dscp_exception[des].up > 7) { |
| 11545 | kfree(qos_map); |
| 11546 | return -EINVAL; |
| 11547 | } |
| 11548 | } |
| 11549 | pos += des_len; |
| 11550 | } |
| 11551 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 11552 | } |
| 11553 | |
| 11554 | wdev_lock(dev->ieee80211_ptr); |
| 11555 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 11556 | if (!ret) |
| 11557 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 11558 | wdev_unlock(dev->ieee80211_ptr); |
| 11559 | |
| 11560 | kfree(qos_map); |
| 11561 | return ret; |
| 11562 | } |
| 11563 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11564 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11565 | { |
| 11566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11567 | struct net_device *dev = info->user_ptr[1]; |
| 11568 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11569 | const u8 *peer; |
| 11570 | u8 tsid, up; |
| 11571 | u16 admitted_time = 0; |
| 11572 | int err; |
| 11573 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11574 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11575 | return -EOPNOTSUPP; |
| 11576 | |
| 11577 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 11578 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 11579 | return -EINVAL; |
| 11580 | |
| 11581 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11582 | if (tsid >= IEEE80211_NUM_TIDS) |
| 11583 | return -EINVAL; |
| 11584 | |
| 11585 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 11586 | if (up >= IEEE80211_NUM_UPS) |
| 11587 | return -EINVAL; |
| 11588 | |
| 11589 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11590 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11591 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11592 | * need more attributes for that (e.g. BA session requirement); |
| 11593 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11594 | */ |
| 11595 | return -EINVAL; |
| 11596 | } |
| 11597 | |
| 11598 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11599 | |
| 11600 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 11601 | admitted_time = |
| 11602 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 11603 | if (!admitted_time) |
| 11604 | return -EINVAL; |
| 11605 | } |
| 11606 | |
| 11607 | wdev_lock(wdev); |
| 11608 | switch (wdev->iftype) { |
| 11609 | case NL80211_IFTYPE_STATION: |
| 11610 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11611 | if (wdev->current_bss) |
| 11612 | break; |
| 11613 | err = -ENOTCONN; |
| 11614 | goto out; |
| 11615 | default: |
| 11616 | err = -EOPNOTSUPP; |
| 11617 | goto out; |
| 11618 | } |
| 11619 | |
| 11620 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 11621 | |
| 11622 | out: |
| 11623 | wdev_unlock(wdev); |
| 11624 | return err; |
| 11625 | } |
| 11626 | |
| 11627 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11628 | { |
| 11629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11630 | struct net_device *dev = info->user_ptr[1]; |
| 11631 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11632 | const u8 *peer; |
| 11633 | u8 tsid; |
| 11634 | int err; |
| 11635 | |
| 11636 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 11637 | return -EINVAL; |
| 11638 | |
| 11639 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11640 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11641 | |
| 11642 | wdev_lock(wdev); |
| 11643 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 11644 | wdev_unlock(wdev); |
| 11645 | |
| 11646 | return err; |
| 11647 | } |
| 11648 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11649 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 11650 | struct genl_info *info) |
| 11651 | { |
| 11652 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11653 | struct net_device *dev = info->user_ptr[1]; |
| 11654 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11655 | struct cfg80211_chan_def chandef = {}; |
| 11656 | const u8 *addr; |
| 11657 | u8 oper_class; |
| 11658 | int err; |
| 11659 | |
| 11660 | if (!rdev->ops->tdls_channel_switch || |
| 11661 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11662 | return -EOPNOTSUPP; |
| 11663 | |
| 11664 | switch (dev->ieee80211_ptr->iftype) { |
| 11665 | case NL80211_IFTYPE_STATION: |
| 11666 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11667 | break; |
| 11668 | default: |
| 11669 | return -EOPNOTSUPP; |
| 11670 | } |
| 11671 | |
| 11672 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 11673 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 11674 | return -EINVAL; |
| 11675 | |
| 11676 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11677 | if (err) |
| 11678 | return err; |
| 11679 | |
| 11680 | /* |
| 11681 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 11682 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 11683 | * specification is not defined for them. |
| 11684 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 11685 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11686 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 11687 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 11688 | return -EINVAL; |
| 11689 | |
| 11690 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 11691 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 11692 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11693 | return -EINVAL; |
| 11694 | |
| 11695 | /* don't allow switching to DFS channels */ |
| 11696 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 11697 | return -EINVAL; |
| 11698 | |
| 11699 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11700 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 11701 | |
| 11702 | wdev_lock(wdev); |
| 11703 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 11704 | wdev_unlock(wdev); |
| 11705 | |
| 11706 | return err; |
| 11707 | } |
| 11708 | |
| 11709 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 11710 | struct genl_info *info) |
| 11711 | { |
| 11712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11713 | struct net_device *dev = info->user_ptr[1]; |
| 11714 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11715 | const u8 *addr; |
| 11716 | |
| 11717 | if (!rdev->ops->tdls_channel_switch || |
| 11718 | !rdev->ops->tdls_cancel_channel_switch || |
| 11719 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11720 | return -EOPNOTSUPP; |
| 11721 | |
| 11722 | switch (dev->ieee80211_ptr->iftype) { |
| 11723 | case NL80211_IFTYPE_STATION: |
| 11724 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11725 | break; |
| 11726 | default: |
| 11727 | return -EOPNOTSUPP; |
| 11728 | } |
| 11729 | |
| 11730 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11731 | return -EINVAL; |
| 11732 | |
| 11733 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11734 | |
| 11735 | wdev_lock(wdev); |
| 11736 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 11737 | wdev_unlock(wdev); |
| 11738 | |
| 11739 | return 0; |
| 11740 | } |
| 11741 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11742 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 11743 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 11744 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11745 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 11746 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 11747 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11748 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11749 | /* 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] | 11750 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 11751 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11752 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11753 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11754 | 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] | 11755 | struct genl_info *info) |
| 11756 | { |
| 11757 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11758 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11759 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11760 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 11761 | |
| 11762 | if (rtnl) |
| 11763 | rtnl_lock(); |
| 11764 | |
| 11765 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 11766 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11767 | if (IS_ERR(rdev)) { |
| 11768 | if (rtnl) |
| 11769 | rtnl_unlock(); |
| 11770 | return PTR_ERR(rdev); |
| 11771 | } |
| 11772 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11773 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 11774 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11775 | ASSERT_RTNL(); |
| 11776 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11777 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 11778 | info->attrs); |
| 11779 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11780 | if (rtnl) |
| 11781 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11782 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11783 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11784 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11785 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11786 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11787 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11788 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 11789 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11790 | if (rtnl) |
| 11791 | rtnl_unlock(); |
| 11792 | return -EINVAL; |
| 11793 | } |
| 11794 | |
| 11795 | info->user_ptr[1] = dev; |
| 11796 | } else { |
| 11797 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11798 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11799 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11800 | if (dev) { |
| 11801 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 11802 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11803 | if (rtnl) |
| 11804 | rtnl_unlock(); |
| 11805 | return -ENETDOWN; |
| 11806 | } |
| 11807 | |
| 11808 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11809 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11810 | if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE && |
| 11811 | !wdev->p2p_started) { |
| 11812 | if (rtnl) |
| 11813 | rtnl_unlock(); |
| 11814 | return -ENETDOWN; |
| 11815 | } |
| 11816 | if (wdev->iftype == NL80211_IFTYPE_NAN && |
| 11817 | !wdev->nan_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11818 | if (rtnl) |
| 11819 | rtnl_unlock(); |
| 11820 | return -ENETDOWN; |
| 11821 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11822 | } |
| 11823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11824 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11825 | } |
| 11826 | |
| 11827 | return 0; |
| 11828 | } |
| 11829 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11830 | 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] | 11831 | struct genl_info *info) |
| 11832 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11833 | if (info->user_ptr[1]) { |
| 11834 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 11835 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11836 | |
| 11837 | if (wdev->netdev) |
| 11838 | dev_put(wdev->netdev); |
| 11839 | } else { |
| 11840 | dev_put(info->user_ptr[1]); |
| 11841 | } |
| 11842 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11843 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11844 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 11845 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11846 | |
| 11847 | /* If needed, clear the netlink message payload from the SKB |
| 11848 | * as it might contain key data that shouldn't stick around on |
| 11849 | * the heap after the SKB is freed. The netlink message header |
| 11850 | * is still needed for further processing, so leave it intact. |
| 11851 | */ |
| 11852 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 11853 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 11854 | |
| 11855 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 11856 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11857 | } |
| 11858 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 11859 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11860 | { |
| 11861 | .cmd = NL80211_CMD_GET_WIPHY, |
| 11862 | .doit = nl80211_get_wiphy, |
| 11863 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11864 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11865 | .policy = nl80211_policy, |
| 11866 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11867 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11868 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11869 | }, |
| 11870 | { |
| 11871 | .cmd = NL80211_CMD_SET_WIPHY, |
| 11872 | .doit = nl80211_set_wiphy, |
| 11873 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11874 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11875 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11876 | }, |
| 11877 | { |
| 11878 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 11879 | .doit = nl80211_get_interface, |
| 11880 | .dumpit = nl80211_dump_interface, |
| 11881 | .policy = nl80211_policy, |
| 11882 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11883 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11884 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11885 | }, |
| 11886 | { |
| 11887 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 11888 | .doit = nl80211_set_interface, |
| 11889 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11890 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11891 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11892 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11893 | }, |
| 11894 | { |
| 11895 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 11896 | .doit = nl80211_new_interface, |
| 11897 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11898 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11899 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11900 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11901 | }, |
| 11902 | { |
| 11903 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 11904 | .doit = nl80211_del_interface, |
| 11905 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11906 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 11907 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11908 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11909 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11910 | { |
| 11911 | .cmd = NL80211_CMD_GET_KEY, |
| 11912 | .doit = nl80211_get_key, |
| 11913 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11914 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11915 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11916 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11917 | }, |
| 11918 | { |
| 11919 | .cmd = NL80211_CMD_SET_KEY, |
| 11920 | .doit = nl80211_set_key, |
| 11921 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11922 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11923 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11924 | NL80211_FLAG_NEED_RTNL | |
| 11925 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11926 | }, |
| 11927 | { |
| 11928 | .cmd = NL80211_CMD_NEW_KEY, |
| 11929 | .doit = nl80211_new_key, |
| 11930 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11931 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11932 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11933 | NL80211_FLAG_NEED_RTNL | |
| 11934 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11935 | }, |
| 11936 | { |
| 11937 | .cmd = NL80211_CMD_DEL_KEY, |
| 11938 | .doit = nl80211_del_key, |
| 11939 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11940 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11942 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11943 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11944 | { |
| 11945 | .cmd = NL80211_CMD_SET_BEACON, |
| 11946 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11947 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11948 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11950 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11951 | }, |
| 11952 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11953 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11954 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11955 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11956 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11958 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11959 | }, |
| 11960 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11961 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11962 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11963 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 11964 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11965 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11966 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 11967 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11968 | { |
| 11969 | .cmd = NL80211_CMD_GET_STATION, |
| 11970 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 11971 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11972 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11973 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11974 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11975 | }, |
| 11976 | { |
| 11977 | .cmd = NL80211_CMD_SET_STATION, |
| 11978 | .doit = nl80211_set_station, |
| 11979 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11980 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11981 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11982 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11983 | }, |
| 11984 | { |
| 11985 | .cmd = NL80211_CMD_NEW_STATION, |
| 11986 | .doit = nl80211_new_station, |
| 11987 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11988 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11989 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11990 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11991 | }, |
| 11992 | { |
| 11993 | .cmd = NL80211_CMD_DEL_STATION, |
| 11994 | .doit = nl80211_del_station, |
| 11995 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11996 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11998 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 11999 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12000 | { |
| 12001 | .cmd = NL80211_CMD_GET_MPATH, |
| 12002 | .doit = nl80211_get_mpath, |
| 12003 | .dumpit = nl80211_dump_mpath, |
| 12004 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12005 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12007 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12008 | }, |
| 12009 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12010 | .cmd = NL80211_CMD_GET_MPP, |
| 12011 | .doit = nl80211_get_mpp, |
| 12012 | .dumpit = nl80211_dump_mpp, |
| 12013 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12014 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12015 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12016 | NL80211_FLAG_NEED_RTNL, |
| 12017 | }, |
| 12018 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12019 | .cmd = NL80211_CMD_SET_MPATH, |
| 12020 | .doit = nl80211_set_mpath, |
| 12021 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12022 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12024 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12025 | }, |
| 12026 | { |
| 12027 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12028 | .doit = nl80211_new_mpath, |
| 12029 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12030 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12032 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12033 | }, |
| 12034 | { |
| 12035 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12036 | .doit = nl80211_del_mpath, |
| 12037 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12038 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12040 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12041 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12042 | { |
| 12043 | .cmd = NL80211_CMD_SET_BSS, |
| 12044 | .doit = nl80211_set_bss, |
| 12045 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12046 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12048 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12049 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12050 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12051 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12052 | .doit = nl80211_get_reg_do, |
| 12053 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12054 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12055 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12056 | /* can be retrieved by unprivileged users */ |
| 12057 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12058 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12059 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12060 | .cmd = NL80211_CMD_SET_REG, |
| 12061 | .doit = nl80211_set_reg, |
| 12062 | .policy = nl80211_policy, |
| 12063 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12064 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12065 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12066 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12067 | { |
| 12068 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12069 | .doit = nl80211_req_set_reg, |
| 12070 | .policy = nl80211_policy, |
| 12071 | .flags = GENL_ADMIN_PERM, |
| 12072 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12073 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12074 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12075 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12076 | .policy = nl80211_policy, |
| 12077 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12078 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12079 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12080 | }, |
| 12081 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12082 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12083 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12084 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12085 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12086 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12087 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12088 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12089 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12090 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12091 | .doit = nl80211_trigger_scan, |
| 12092 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12093 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12094 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12095 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12096 | }, |
| 12097 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12098 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12099 | .doit = nl80211_abort_scan, |
| 12100 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12101 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12102 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12103 | NL80211_FLAG_NEED_RTNL, |
| 12104 | }, |
| 12105 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12106 | .cmd = NL80211_CMD_GET_SCAN, |
| 12107 | .policy = nl80211_policy, |
| 12108 | .dumpit = nl80211_dump_scan, |
| 12109 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12110 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12111 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12112 | .doit = nl80211_start_sched_scan, |
| 12113 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12114 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12115 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12116 | NL80211_FLAG_NEED_RTNL, |
| 12117 | }, |
| 12118 | { |
| 12119 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12120 | .doit = nl80211_stop_sched_scan, |
| 12121 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12122 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12123 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12124 | NL80211_FLAG_NEED_RTNL, |
| 12125 | }, |
| 12126 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12127 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12128 | .doit = nl80211_authenticate, |
| 12129 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12130 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12131 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12132 | NL80211_FLAG_NEED_RTNL | |
| 12133 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12134 | }, |
| 12135 | { |
| 12136 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12137 | .doit = nl80211_associate, |
| 12138 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12139 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12140 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12141 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12142 | }, |
| 12143 | { |
| 12144 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12145 | .doit = nl80211_deauthenticate, |
| 12146 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12147 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12148 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12149 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12150 | }, |
| 12151 | { |
| 12152 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12153 | .doit = nl80211_disassociate, |
| 12154 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12155 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12156 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12157 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12158 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12159 | { |
| 12160 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12161 | .doit = nl80211_join_ibss, |
| 12162 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12163 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12164 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12165 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12166 | }, |
| 12167 | { |
| 12168 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12169 | .doit = nl80211_leave_ibss, |
| 12170 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12171 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12172 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12173 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12174 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12175 | #ifdef CONFIG_NL80211_TESTMODE |
| 12176 | { |
| 12177 | .cmd = NL80211_CMD_TESTMODE, |
| 12178 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12179 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12180 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12181 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12182 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12183 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12184 | }, |
| 12185 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12186 | { |
| 12187 | .cmd = NL80211_CMD_CONNECT, |
| 12188 | .doit = nl80211_connect, |
| 12189 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12190 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12191 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12192 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12193 | }, |
| 12194 | { |
| 12195 | .cmd = NL80211_CMD_DISCONNECT, |
| 12196 | .doit = nl80211_disconnect, |
| 12197 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12198 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12199 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12200 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12201 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12202 | { |
| 12203 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12204 | .doit = nl80211_wiphy_netns, |
| 12205 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12206 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12207 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12208 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12209 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12210 | { |
| 12211 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12212 | .policy = nl80211_policy, |
| 12213 | .dumpit = nl80211_dump_survey, |
| 12214 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12215 | { |
| 12216 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12217 | .doit = nl80211_setdel_pmksa, |
| 12218 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12219 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12220 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12221 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12222 | }, |
| 12223 | { |
| 12224 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12225 | .doit = nl80211_setdel_pmksa, |
| 12226 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12227 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12228 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12229 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12230 | }, |
| 12231 | { |
| 12232 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12233 | .doit = nl80211_flush_pmksa, |
| 12234 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12235 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12237 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12238 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12239 | { |
| 12240 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12241 | .doit = nl80211_remain_on_channel, |
| 12242 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12243 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12244 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12245 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12246 | }, |
| 12247 | { |
| 12248 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12249 | .doit = nl80211_cancel_remain_on_channel, |
| 12250 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12251 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12252 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12253 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12254 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12255 | { |
| 12256 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12257 | .doit = nl80211_set_tx_bitrate_mask, |
| 12258 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12259 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12260 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12261 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12262 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12263 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12264 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12265 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12266 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12267 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12268 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12269 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12270 | }, |
| 12271 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12272 | .cmd = NL80211_CMD_FRAME, |
| 12273 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12274 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12275 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12276 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12277 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12278 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12279 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12280 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12281 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12282 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12283 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12284 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12285 | NL80211_FLAG_NEED_RTNL, |
| 12286 | }, |
| 12287 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12288 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12289 | .doit = nl80211_set_power_save, |
| 12290 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12291 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12292 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12293 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12294 | }, |
| 12295 | { |
| 12296 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12297 | .doit = nl80211_get_power_save, |
| 12298 | .policy = nl80211_policy, |
| 12299 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12300 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12301 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12302 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12303 | { |
| 12304 | .cmd = NL80211_CMD_SET_CQM, |
| 12305 | .doit = nl80211_set_cqm, |
| 12306 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12307 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12308 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12309 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12310 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12311 | { |
| 12312 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12313 | .doit = nl80211_set_channel, |
| 12314 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12315 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12316 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12317 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12318 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12319 | { |
| 12320 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12321 | .doit = nl80211_set_wds_peer, |
| 12322 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12323 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12324 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12325 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12326 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12327 | { |
| 12328 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12329 | .doit = nl80211_join_mesh, |
| 12330 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12331 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12332 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12333 | NL80211_FLAG_NEED_RTNL, |
| 12334 | }, |
| 12335 | { |
| 12336 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12337 | .doit = nl80211_leave_mesh, |
| 12338 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12339 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12340 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12341 | NL80211_FLAG_NEED_RTNL, |
| 12342 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12343 | { |
| 12344 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12345 | .doit = nl80211_join_ocb, |
| 12346 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12347 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12348 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12349 | NL80211_FLAG_NEED_RTNL, |
| 12350 | }, |
| 12351 | { |
| 12352 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12353 | .doit = nl80211_leave_ocb, |
| 12354 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12355 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12357 | NL80211_FLAG_NEED_RTNL, |
| 12358 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12359 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12360 | { |
| 12361 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 12362 | .doit = nl80211_get_wowlan, |
| 12363 | .policy = nl80211_policy, |
| 12364 | /* can be retrieved by unprivileged users */ |
| 12365 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12366 | NL80211_FLAG_NEED_RTNL, |
| 12367 | }, |
| 12368 | { |
| 12369 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 12370 | .doit = nl80211_set_wowlan, |
| 12371 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12372 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12374 | NL80211_FLAG_NEED_RTNL, |
| 12375 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12376 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12377 | { |
| 12378 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 12379 | .doit = nl80211_set_rekey_data, |
| 12380 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12381 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12383 | NL80211_FLAG_NEED_RTNL | |
| 12384 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12385 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12386 | { |
| 12387 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 12388 | .doit = nl80211_tdls_mgmt, |
| 12389 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12390 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12392 | NL80211_FLAG_NEED_RTNL, |
| 12393 | }, |
| 12394 | { |
| 12395 | .cmd = NL80211_CMD_TDLS_OPER, |
| 12396 | .doit = nl80211_tdls_oper, |
| 12397 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12398 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12400 | NL80211_FLAG_NEED_RTNL, |
| 12401 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12402 | { |
| 12403 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 12404 | .doit = nl80211_register_unexpected_frame, |
| 12405 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12406 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12407 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12408 | NL80211_FLAG_NEED_RTNL, |
| 12409 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12410 | { |
| 12411 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 12412 | .doit = nl80211_probe_client, |
| 12413 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12414 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12415 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12416 | NL80211_FLAG_NEED_RTNL, |
| 12417 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12418 | { |
| 12419 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 12420 | .doit = nl80211_register_beacons, |
| 12421 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12422 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12423 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12424 | NL80211_FLAG_NEED_RTNL, |
| 12425 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12426 | { |
| 12427 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 12428 | .doit = nl80211_set_noack_map, |
| 12429 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12430 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12431 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12432 | NL80211_FLAG_NEED_RTNL, |
| 12433 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12434 | { |
| 12435 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 12436 | .doit = nl80211_start_p2p_device, |
| 12437 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12438 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12439 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12440 | NL80211_FLAG_NEED_RTNL, |
| 12441 | }, |
| 12442 | { |
| 12443 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 12444 | .doit = nl80211_stop_p2p_device, |
| 12445 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12446 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12447 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12448 | NL80211_FLAG_NEED_RTNL, |
| 12449 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12450 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12451 | .cmd = NL80211_CMD_START_NAN, |
| 12452 | .doit = nl80211_start_nan, |
| 12453 | .policy = nl80211_policy, |
| 12454 | .flags = GENL_ADMIN_PERM, |
| 12455 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12456 | NL80211_FLAG_NEED_RTNL, |
| 12457 | }, |
| 12458 | { |
| 12459 | .cmd = NL80211_CMD_STOP_NAN, |
| 12460 | .doit = nl80211_stop_nan, |
| 12461 | .policy = nl80211_policy, |
| 12462 | .flags = GENL_ADMIN_PERM, |
| 12463 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12464 | NL80211_FLAG_NEED_RTNL, |
| 12465 | }, |
| 12466 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12467 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 12468 | .doit = nl80211_nan_add_func, |
| 12469 | .policy = nl80211_policy, |
| 12470 | .flags = GENL_ADMIN_PERM, |
| 12471 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12472 | NL80211_FLAG_NEED_RTNL, |
| 12473 | }, |
| 12474 | { |
| 12475 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 12476 | .doit = nl80211_nan_del_func, |
| 12477 | .policy = nl80211_policy, |
| 12478 | .flags = GENL_ADMIN_PERM, |
| 12479 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12480 | NL80211_FLAG_NEED_RTNL, |
| 12481 | }, |
| 12482 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12483 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 12484 | .doit = nl80211_nan_change_config, |
| 12485 | .policy = nl80211_policy, |
| 12486 | .flags = GENL_ADMIN_PERM, |
| 12487 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12488 | NL80211_FLAG_NEED_RTNL, |
| 12489 | }, |
| 12490 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12491 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 12492 | .doit = nl80211_set_mcast_rate, |
| 12493 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12494 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12495 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12496 | NL80211_FLAG_NEED_RTNL, |
| 12497 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12498 | { |
| 12499 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 12500 | .doit = nl80211_set_mac_acl, |
| 12501 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12502 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12503 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12504 | NL80211_FLAG_NEED_RTNL, |
| 12505 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12506 | { |
| 12507 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 12508 | .doit = nl80211_start_radar_detection, |
| 12509 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12510 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12511 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12512 | NL80211_FLAG_NEED_RTNL, |
| 12513 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12514 | { |
| 12515 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 12516 | .doit = nl80211_get_protocol_features, |
| 12517 | .policy = nl80211_policy, |
| 12518 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12519 | { |
| 12520 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 12521 | .doit = nl80211_update_ft_ies, |
| 12522 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12523 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12524 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12525 | NL80211_FLAG_NEED_RTNL, |
| 12526 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12527 | { |
| 12528 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 12529 | .doit = nl80211_crit_protocol_start, |
| 12530 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12531 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12532 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12533 | NL80211_FLAG_NEED_RTNL, |
| 12534 | }, |
| 12535 | { |
| 12536 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 12537 | .doit = nl80211_crit_protocol_stop, |
| 12538 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12539 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12540 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12541 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12542 | }, |
| 12543 | { |
| 12544 | .cmd = NL80211_CMD_GET_COALESCE, |
| 12545 | .doit = nl80211_get_coalesce, |
| 12546 | .policy = nl80211_policy, |
| 12547 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12548 | NL80211_FLAG_NEED_RTNL, |
| 12549 | }, |
| 12550 | { |
| 12551 | .cmd = NL80211_CMD_SET_COALESCE, |
| 12552 | .doit = nl80211_set_coalesce, |
| 12553 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12554 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12555 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12556 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12557 | }, |
| 12558 | { |
| 12559 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 12560 | .doit = nl80211_channel_switch, |
| 12561 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12562 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12564 | NL80211_FLAG_NEED_RTNL, |
| 12565 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12566 | { |
| 12567 | .cmd = NL80211_CMD_VENDOR, |
| 12568 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12569 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12570 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12571 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12572 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12573 | NL80211_FLAG_NEED_RTNL, |
| 12574 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12575 | { |
| 12576 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 12577 | .doit = nl80211_set_qos_map, |
| 12578 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12579 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12580 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12581 | NL80211_FLAG_NEED_RTNL, |
| 12582 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12583 | { |
| 12584 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 12585 | .doit = nl80211_add_tx_ts, |
| 12586 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12587 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12588 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12589 | NL80211_FLAG_NEED_RTNL, |
| 12590 | }, |
| 12591 | { |
| 12592 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 12593 | .doit = nl80211_del_tx_ts, |
| 12594 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12595 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12596 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12597 | NL80211_FLAG_NEED_RTNL, |
| 12598 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12599 | { |
| 12600 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 12601 | .doit = nl80211_tdls_channel_switch, |
| 12602 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12603 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12604 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12605 | NL80211_FLAG_NEED_RTNL, |
| 12606 | }, |
| 12607 | { |
| 12608 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 12609 | .doit = nl80211_tdls_cancel_channel_switch, |
| 12610 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12611 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12613 | NL80211_FLAG_NEED_RTNL, |
| 12614 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12615 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12616 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12617 | /* notification functions */ |
| 12618 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12619 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 12620 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12621 | { |
| 12622 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12623 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12624 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12625 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 12626 | cmd != NL80211_CMD_DEL_WIPHY); |
| 12627 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12628 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12629 | if (!msg) |
| 12630 | return; |
| 12631 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12632 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12633 | nlmsg_free(msg); |
| 12634 | return; |
| 12635 | } |
| 12636 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12637 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12638 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12639 | } |
| 12640 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 12641 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 12642 | struct wireless_dev *wdev, |
| 12643 | enum nl80211_commands cmd) |
| 12644 | { |
| 12645 | struct sk_buff *msg; |
| 12646 | |
| 12647 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 12648 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 12649 | |
| 12650 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12651 | if (!msg) |
| 12652 | return; |
| 12653 | |
| 12654 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 12655 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 12656 | nlmsg_free(msg); |
| 12657 | return; |
| 12658 | } |
| 12659 | |
| 12660 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12661 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 12662 | } |
| 12663 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12664 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 12665 | struct cfg80211_registered_device *rdev) |
| 12666 | { |
| 12667 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 12668 | struct nlattr *nest; |
| 12669 | int i; |
| 12670 | |
| 12671 | if (WARN_ON(!req)) |
| 12672 | return 0; |
| 12673 | |
| 12674 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 12675 | if (!nest) |
| 12676 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12677 | for (i = 0; i < req->n_ssids; i++) { |
| 12678 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 12679 | goto nla_put_failure; |
| 12680 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12681 | nla_nest_end(msg, nest); |
| 12682 | |
| 12683 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12684 | if (!nest) |
| 12685 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12686 | for (i = 0; i < req->n_channels; i++) { |
| 12687 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 12688 | goto nla_put_failure; |
| 12689 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12690 | nla_nest_end(msg, nest); |
| 12691 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12692 | if (req->ie && |
| 12693 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 12694 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12695 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12696 | if (req->flags && |
| 12697 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 12698 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 12699 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 12700 | if (req->info.scan_start_tsf && |
| 12701 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 12702 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 12703 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 12704 | req->info.tsf_bssid))) |
| 12705 | goto nla_put_failure; |
| 12706 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12707 | return 0; |
| 12708 | nla_put_failure: |
| 12709 | return -ENOBUFS; |
| 12710 | } |
| 12711 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12712 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 12713 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12714 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12715 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12716 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12717 | { |
| 12718 | void *hdr; |
| 12719 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12720 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12721 | if (!hdr) |
| 12722 | return -1; |
| 12723 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12724 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12725 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12726 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12727 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12728 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12729 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12730 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12731 | /* ignore errors and send incomplete event anyway */ |
| 12732 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12733 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 12734 | genlmsg_end(msg, hdr); |
| 12735 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12736 | |
| 12737 | nla_put_failure: |
| 12738 | genlmsg_cancel(msg, hdr); |
| 12739 | return -EMSGSIZE; |
| 12740 | } |
| 12741 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12742 | static int |
| 12743 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 12744 | struct cfg80211_registered_device *rdev, |
| 12745 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12746 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12747 | { |
| 12748 | void *hdr; |
| 12749 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12750 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12751 | if (!hdr) |
| 12752 | return -1; |
| 12753 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12754 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12755 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12756 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12757 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 12758 | genlmsg_end(msg, hdr); |
| 12759 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12760 | |
| 12761 | nla_put_failure: |
| 12762 | genlmsg_cancel(msg, hdr); |
| 12763 | return -EMSGSIZE; |
| 12764 | } |
| 12765 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12766 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12767 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12768 | { |
| 12769 | struct sk_buff *msg; |
| 12770 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12772 | if (!msg) |
| 12773 | return; |
| 12774 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12775 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12776 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 12777 | nlmsg_free(msg); |
| 12778 | return; |
| 12779 | } |
| 12780 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12781 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12782 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12783 | } |
| 12784 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12785 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 12786 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12787 | { |
| 12788 | struct sk_buff *msg; |
| 12789 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12790 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12791 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12792 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12793 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12794 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12795 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 12796 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12797 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12798 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12799 | } |
| 12800 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12801 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12802 | } |
| 12803 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12804 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 12805 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12806 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12807 | if (!msg) |
| 12808 | return; |
| 12809 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12810 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12811 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12812 | } |
| 12813 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12814 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 12815 | struct net_device *netdev) |
| 12816 | { |
| 12817 | struct sk_buff *msg; |
| 12818 | |
| 12819 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12820 | if (!msg) |
| 12821 | return; |
| 12822 | |
| 12823 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 12824 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 12825 | nlmsg_free(msg); |
| 12826 | return; |
| 12827 | } |
| 12828 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12829 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12830 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12831 | } |
| 12832 | |
| 12833 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 12834 | struct net_device *netdev, u32 cmd) |
| 12835 | { |
| 12836 | struct sk_buff *msg; |
| 12837 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12838 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12839 | if (!msg) |
| 12840 | return; |
| 12841 | |
| 12842 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 12843 | nlmsg_free(msg); |
| 12844 | return; |
| 12845 | } |
| 12846 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12847 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12848 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12849 | } |
| 12850 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12851 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 12852 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12853 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12854 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12855 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 12856 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12857 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12858 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 12859 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12860 | NL80211_REGDOM_TYPE_WORLD)) |
| 12861 | goto nla_put_failure; |
| 12862 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 12863 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12864 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 12865 | goto nla_put_failure; |
| 12866 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 12867 | request->intersect) { |
| 12868 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12869 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 12870 | goto nla_put_failure; |
| 12871 | } else { |
| 12872 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12873 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 12874 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 12875 | request->alpha2)) |
| 12876 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12877 | } |
| 12878 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12879 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 12880 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 12881 | |
| 12882 | if (wiphy && |
| 12883 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 12884 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 12885 | |
| 12886 | if (wiphy && |
| 12887 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 12888 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 12889 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12890 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12891 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12892 | return true; |
| 12893 | |
| 12894 | nla_put_failure: |
| 12895 | return false; |
| 12896 | } |
| 12897 | |
| 12898 | /* |
| 12899 | * This can happen on global regulatory changes or device specific settings |
| 12900 | * based on custom regulatory domains. |
| 12901 | */ |
| 12902 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 12903 | struct regulatory_request *request) |
| 12904 | { |
| 12905 | struct sk_buff *msg; |
| 12906 | void *hdr; |
| 12907 | |
| 12908 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12909 | if (!msg) |
| 12910 | return; |
| 12911 | |
| 12912 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 12913 | if (!hdr) { |
| 12914 | nlmsg_free(msg); |
| 12915 | return; |
| 12916 | } |
| 12917 | |
| 12918 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 12919 | goto nla_put_failure; |
| 12920 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12921 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12922 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12923 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12924 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12925 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 12926 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12927 | |
| 12928 | return; |
| 12929 | |
| 12930 | nla_put_failure: |
| 12931 | genlmsg_cancel(msg, hdr); |
| 12932 | nlmsg_free(msg); |
| 12933 | } |
| 12934 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12935 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 12936 | struct net_device *netdev, |
| 12937 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12938 | enum nl80211_commands cmd, gfp_t gfp, |
| 12939 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12940 | { |
| 12941 | struct sk_buff *msg; |
| 12942 | void *hdr; |
| 12943 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12945 | if (!msg) |
| 12946 | return; |
| 12947 | |
| 12948 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 12949 | if (!hdr) { |
| 12950 | nlmsg_free(msg); |
| 12951 | return; |
| 12952 | } |
| 12953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12954 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12955 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12956 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 12957 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12958 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12959 | if (uapsd_queues >= 0) { |
| 12960 | struct nlattr *nla_wmm = |
| 12961 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 12962 | if (!nla_wmm) |
| 12963 | goto nla_put_failure; |
| 12964 | |
| 12965 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 12966 | uapsd_queues)) |
| 12967 | goto nla_put_failure; |
| 12968 | |
| 12969 | nla_nest_end(msg, nla_wmm); |
| 12970 | } |
| 12971 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12972 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12973 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12974 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12975 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12976 | return; |
| 12977 | |
| 12978 | nla_put_failure: |
| 12979 | genlmsg_cancel(msg, hdr); |
| 12980 | nlmsg_free(msg); |
| 12981 | } |
| 12982 | |
| 12983 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12984 | struct net_device *netdev, const u8 *buf, |
| 12985 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12986 | { |
| 12987 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12988 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12989 | } |
| 12990 | |
| 12991 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 12992 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12993 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12994 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 12995 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 12996 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 12997 | } |
| 12998 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 12999 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13000 | struct net_device *netdev, const u8 *buf, |
| 13001 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13002 | { |
| 13003 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13004 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13005 | } |
| 13006 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13007 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13008 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13009 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13010 | { |
| 13011 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13012 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13013 | } |
| 13014 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13015 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13016 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13017 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13018 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13019 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13020 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13021 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13022 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13023 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13024 | if (WARN_ON(len < 2)) |
| 13025 | return; |
| 13026 | |
| 13027 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13028 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13029 | else |
| 13030 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13031 | |
| 13032 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13033 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13034 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13035 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13036 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13037 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13038 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13039 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13040 | { |
| 13041 | struct sk_buff *msg; |
| 13042 | void *hdr; |
| 13043 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13045 | if (!msg) |
| 13046 | return; |
| 13047 | |
| 13048 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13049 | if (!hdr) { |
| 13050 | nlmsg_free(msg); |
| 13051 | return; |
| 13052 | } |
| 13053 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13054 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13055 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13056 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13057 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13058 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13059 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13060 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13061 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13062 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13063 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13064 | return; |
| 13065 | |
| 13066 | nla_put_failure: |
| 13067 | genlmsg_cancel(msg, hdr); |
| 13068 | nlmsg_free(msg); |
| 13069 | } |
| 13070 | |
| 13071 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13072 | struct net_device *netdev, const u8 *addr, |
| 13073 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13074 | { |
| 13075 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13076 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13077 | } |
| 13078 | |
| 13079 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13080 | struct net_device *netdev, const u8 *addr, |
| 13081 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13082 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13083 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13084 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13085 | } |
| 13086 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13087 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 13088 | struct net_device *netdev, const u8 *bssid, |
| 13089 | const u8 *req_ie, size_t req_ie_len, |
| 13090 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13091 | int status, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13092 | { |
| 13093 | struct sk_buff *msg; |
| 13094 | void *hdr; |
| 13095 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13096 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13097 | if (!msg) |
| 13098 | return; |
| 13099 | |
| 13100 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13101 | if (!hdr) { |
| 13102 | nlmsg_free(msg); |
| 13103 | return; |
| 13104 | } |
| 13105 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13106 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13107 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13108 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13109 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 13110 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13111 | status) || |
| 13112 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13113 | (req_ie && |
| 13114 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 13115 | (resp_ie && |
| 13116 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 13117 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13118 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13119 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13120 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13121 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13122 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13123 | return; |
| 13124 | |
| 13125 | nla_put_failure: |
| 13126 | genlmsg_cancel(msg, hdr); |
| 13127 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13128 | } |
| 13129 | |
| 13130 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 13131 | struct net_device *netdev, const u8 *bssid, |
| 13132 | const u8 *req_ie, size_t req_ie_len, |
| 13133 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 13134 | { |
| 13135 | struct sk_buff *msg; |
| 13136 | void *hdr; |
| 13137 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13138 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13139 | if (!msg) |
| 13140 | return; |
| 13141 | |
| 13142 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13143 | if (!hdr) { |
| 13144 | nlmsg_free(msg); |
| 13145 | return; |
| 13146 | } |
| 13147 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13148 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13149 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13150 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 13151 | (req_ie && |
| 13152 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 13153 | (resp_ie && |
| 13154 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 13155 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13156 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13157 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13158 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13159 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13160 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13161 | return; |
| 13162 | |
| 13163 | nla_put_failure: |
| 13164 | genlmsg_cancel(msg, hdr); |
| 13165 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13166 | } |
| 13167 | |
| 13168 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13169 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13170 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13171 | { |
| 13172 | struct sk_buff *msg; |
| 13173 | void *hdr; |
| 13174 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13175 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13176 | if (!msg) |
| 13177 | return; |
| 13178 | |
| 13179 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13180 | if (!hdr) { |
| 13181 | nlmsg_free(msg); |
| 13182 | return; |
| 13183 | } |
| 13184 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13185 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13186 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13187 | (from_ap && reason && |
| 13188 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13189 | (from_ap && |
| 13190 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13191 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13192 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13193 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13194 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13195 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13196 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13197 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13198 | return; |
| 13199 | |
| 13200 | nla_put_failure: |
| 13201 | genlmsg_cancel(msg, hdr); |
| 13202 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13203 | } |
| 13204 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13205 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13206 | struct net_device *netdev, const u8 *bssid, |
| 13207 | gfp_t gfp) |
| 13208 | { |
| 13209 | struct sk_buff *msg; |
| 13210 | void *hdr; |
| 13211 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13213 | if (!msg) |
| 13214 | return; |
| 13215 | |
| 13216 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13217 | if (!hdr) { |
| 13218 | nlmsg_free(msg); |
| 13219 | return; |
| 13220 | } |
| 13221 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13223 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13224 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13225 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13226 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13227 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13228 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13229 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13230 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13231 | return; |
| 13232 | |
| 13233 | nla_put_failure: |
| 13234 | genlmsg_cancel(msg, hdr); |
| 13235 | nlmsg_free(msg); |
| 13236 | } |
| 13237 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13238 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13239 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13240 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13241 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13242 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13243 | struct sk_buff *msg; |
| 13244 | void *hdr; |
| 13245 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13246 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13247 | return; |
| 13248 | |
| 13249 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13250 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13251 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13252 | if (!msg) |
| 13253 | return; |
| 13254 | |
| 13255 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13256 | if (!hdr) { |
| 13257 | nlmsg_free(msg); |
| 13258 | return; |
| 13259 | } |
| 13260 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13261 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13262 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13263 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13264 | (ie_len && ie && |
| 13265 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13266 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13267 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13268 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13269 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13270 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13271 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13272 | return; |
| 13273 | |
| 13274 | nla_put_failure: |
| 13275 | genlmsg_cancel(msg, hdr); |
| 13276 | nlmsg_free(msg); |
| 13277 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13278 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13279 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13280 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13281 | struct net_device *netdev, const u8 *addr, |
| 13282 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13283 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13284 | { |
| 13285 | struct sk_buff *msg; |
| 13286 | void *hdr; |
| 13287 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13288 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13289 | if (!msg) |
| 13290 | return; |
| 13291 | |
| 13292 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 13293 | if (!hdr) { |
| 13294 | nlmsg_free(msg); |
| 13295 | return; |
| 13296 | } |
| 13297 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13298 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13299 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13300 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 13301 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 13302 | (key_id != -1 && |
| 13303 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 13304 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 13305 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13306 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13307 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13308 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13309 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13310 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13311 | return; |
| 13312 | |
| 13313 | nla_put_failure: |
| 13314 | genlmsg_cancel(msg, hdr); |
| 13315 | nlmsg_free(msg); |
| 13316 | } |
| 13317 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13318 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 13319 | struct ieee80211_channel *channel_before, |
| 13320 | struct ieee80211_channel *channel_after) |
| 13321 | { |
| 13322 | struct sk_buff *msg; |
| 13323 | void *hdr; |
| 13324 | struct nlattr *nl_freq; |
| 13325 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13326 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13327 | if (!msg) |
| 13328 | return; |
| 13329 | |
| 13330 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 13331 | if (!hdr) { |
| 13332 | nlmsg_free(msg); |
| 13333 | return; |
| 13334 | } |
| 13335 | |
| 13336 | /* |
| 13337 | * Since we are applying the beacon hint to a wiphy we know its |
| 13338 | * wiphy_idx is valid |
| 13339 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 13341 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13342 | |
| 13343 | /* Before */ |
| 13344 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 13345 | if (!nl_freq) |
| 13346 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13347 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13348 | goto nla_put_failure; |
| 13349 | nla_nest_end(msg, nl_freq); |
| 13350 | |
| 13351 | /* After */ |
| 13352 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 13353 | if (!nl_freq) |
| 13354 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13355 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13356 | goto nla_put_failure; |
| 13357 | nla_nest_end(msg, nl_freq); |
| 13358 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13359 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13360 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13361 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13362 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13363 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13364 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13365 | |
| 13366 | return; |
| 13367 | |
| 13368 | nla_put_failure: |
| 13369 | genlmsg_cancel(msg, hdr); |
| 13370 | nlmsg_free(msg); |
| 13371 | } |
| 13372 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13373 | static void nl80211_send_remain_on_chan_event( |
| 13374 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13375 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13376 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13377 | unsigned int duration, gfp_t gfp) |
| 13378 | { |
| 13379 | struct sk_buff *msg; |
| 13380 | void *hdr; |
| 13381 | |
| 13382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13383 | if (!msg) |
| 13384 | return; |
| 13385 | |
| 13386 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13387 | if (!hdr) { |
| 13388 | nlmsg_free(msg); |
| 13389 | return; |
| 13390 | } |
| 13391 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13393 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13394 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13395 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13396 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13397 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13398 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 13399 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13400 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13401 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13402 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13403 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13404 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 13405 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 13406 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13407 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13408 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13409 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13410 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13411 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13412 | return; |
| 13413 | |
| 13414 | nla_put_failure: |
| 13415 | genlmsg_cancel(msg, hdr); |
| 13416 | nlmsg_free(msg); |
| 13417 | } |
| 13418 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13419 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 13420 | struct ieee80211_channel *chan, |
| 13421 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13422 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13423 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13424 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13425 | |
| 13426 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13427 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13428 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13429 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13430 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13431 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13432 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13433 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 13434 | struct ieee80211_channel *chan, |
| 13435 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13436 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13437 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13438 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13439 | |
| 13440 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13441 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13442 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13443 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13444 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13445 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13446 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 13447 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13448 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13449 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13450 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13451 | struct sk_buff *msg; |
| 13452 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13453 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 13454 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13455 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13456 | if (!msg) |
| 13457 | return; |
| 13458 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13459 | 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] | 13460 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13461 | nlmsg_free(msg); |
| 13462 | return; |
| 13463 | } |
| 13464 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13465 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13466 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13467 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13468 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13469 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13470 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 13471 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13472 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13473 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13474 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13475 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13476 | struct station_info empty_sinfo = {}; |
| 13477 | |
| 13478 | if (!sinfo) |
| 13479 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13480 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13481 | trace_cfg80211_del_sta(dev, mac_addr); |
| 13482 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13484 | if (!msg) |
| 13485 | return; |
| 13486 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13487 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 13488 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13489 | nlmsg_free(msg); |
| 13490 | return; |
| 13491 | } |
| 13492 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13493 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13494 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13495 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13496 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13497 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13498 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 13499 | enum nl80211_connect_failed_reason reason, |
| 13500 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13501 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13502 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13503 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13504 | struct sk_buff *msg; |
| 13505 | void *hdr; |
| 13506 | |
| 13507 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 13508 | if (!msg) |
| 13509 | return; |
| 13510 | |
| 13511 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 13512 | if (!hdr) { |
| 13513 | nlmsg_free(msg); |
| 13514 | return; |
| 13515 | } |
| 13516 | |
| 13517 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13518 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 13519 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 13520 | goto nla_put_failure; |
| 13521 | |
| 13522 | genlmsg_end(msg, hdr); |
| 13523 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13524 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13525 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13526 | return; |
| 13527 | |
| 13528 | nla_put_failure: |
| 13529 | genlmsg_cancel(msg, hdr); |
| 13530 | nlmsg_free(msg); |
| 13531 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13532 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13533 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13534 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 13535 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13536 | { |
| 13537 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13538 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13539 | struct sk_buff *msg; |
| 13540 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13541 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13542 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13543 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13544 | return false; |
| 13545 | |
| 13546 | msg = nlmsg_new(100, gfp); |
| 13547 | if (!msg) |
| 13548 | return true; |
| 13549 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13550 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13551 | if (!hdr) { |
| 13552 | nlmsg_free(msg); |
| 13553 | return true; |
| 13554 | } |
| 13555 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13556 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13557 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13558 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13559 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13560 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13561 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13562 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13563 | return true; |
| 13564 | |
| 13565 | nla_put_failure: |
| 13566 | genlmsg_cancel(msg, hdr); |
| 13567 | nlmsg_free(msg); |
| 13568 | return true; |
| 13569 | } |
| 13570 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13571 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 13572 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13573 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13574 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13575 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13576 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13577 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 13578 | |
| 13579 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13580 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 13581 | trace_cfg80211_return_bool(false); |
| 13582 | return false; |
| 13583 | } |
| 13584 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 13585 | addr, gfp); |
| 13586 | trace_cfg80211_return_bool(ret); |
| 13587 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13588 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13589 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 13590 | |
| 13591 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 13592 | const u8 *addr, gfp_t gfp) |
| 13593 | { |
| 13594 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13595 | bool ret; |
| 13596 | |
| 13597 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 13598 | |
| 13599 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13600 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 13601 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 13602 | trace_cfg80211_return_bool(false); |
| 13603 | return false; |
| 13604 | } |
| 13605 | ret = __nl80211_unexpected_frame(dev, |
| 13606 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 13607 | addr, gfp); |
| 13608 | trace_cfg80211_return_bool(ret); |
| 13609 | return ret; |
| 13610 | } |
| 13611 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13612 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13613 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13614 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 13615 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 13616 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13617 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13618 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13619 | struct sk_buff *msg; |
| 13620 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13621 | |
| 13622 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13623 | if (!msg) |
| 13624 | return -ENOMEM; |
| 13625 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13626 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13627 | if (!hdr) { |
| 13628 | nlmsg_free(msg); |
| 13629 | return -ENOMEM; |
| 13630 | } |
| 13631 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13632 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13633 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13634 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13635 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13636 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13637 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 13638 | (sig_dbm && |
| 13639 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 13640 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 13641 | (flags && |
| 13642 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13643 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13644 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13645 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13646 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13647 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13648 | |
| 13649 | nla_put_failure: |
| 13650 | genlmsg_cancel(msg, hdr); |
| 13651 | nlmsg_free(msg); |
| 13652 | return -ENOBUFS; |
| 13653 | } |
| 13654 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13655 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 13656 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13657 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13658 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13659 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13660 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13661 | struct sk_buff *msg; |
| 13662 | void *hdr; |
| 13663 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13664 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 13665 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13667 | if (!msg) |
| 13668 | return; |
| 13669 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13670 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13671 | if (!hdr) { |
| 13672 | nlmsg_free(msg); |
| 13673 | return; |
| 13674 | } |
| 13675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13676 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13677 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13678 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13679 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13680 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13681 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13682 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13683 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13684 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 13685 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13686 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13687 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13688 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13689 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13690 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13691 | return; |
| 13692 | |
| 13693 | nla_put_failure: |
| 13694 | genlmsg_cancel(msg, hdr); |
| 13695 | nlmsg_free(msg); |
| 13696 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13697 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13698 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13699 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 13700 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13701 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13702 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13703 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 13704 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13705 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13706 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13707 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13708 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13709 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13710 | cb = (void **)msg->cb; |
| 13711 | |
| 13712 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 13713 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13714 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13715 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13716 | } |
| 13717 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13718 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13719 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13720 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13721 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13722 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13723 | goto nla_put_failure; |
| 13724 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13725 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 13726 | if (!cb[1]) |
| 13727 | goto nla_put_failure; |
| 13728 | |
| 13729 | cb[2] = rdev; |
| 13730 | |
| 13731 | return msg; |
| 13732 | nla_put_failure: |
| 13733 | nlmsg_free(msg); |
| 13734 | return NULL; |
| 13735 | } |
| 13736 | |
| 13737 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 13738 | { |
| 13739 | void **cb = (void **)msg->cb; |
| 13740 | struct cfg80211_registered_device *rdev = cb[2]; |
| 13741 | |
| 13742 | nla_nest_end(msg, cb[1]); |
| 13743 | genlmsg_end(msg, cb[0]); |
| 13744 | |
| 13745 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 13746 | |
| 13747 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13748 | NL80211_MCGRP_MLME, gfp); |
| 13749 | } |
| 13750 | |
| 13751 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 13752 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 13753 | gfp_t gfp) |
| 13754 | { |
| 13755 | struct sk_buff *msg; |
| 13756 | |
| 13757 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 13758 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13759 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 13760 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 13761 | return; |
| 13762 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13763 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13764 | if (!msg) |
| 13765 | return; |
| 13766 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13767 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 13768 | rssi_event)) |
| 13769 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13770 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13771 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13772 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13773 | return; |
| 13774 | |
| 13775 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13776 | nlmsg_free(msg); |
| 13777 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13778 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13779 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13780 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 13781 | const u8 *peer, u32 num_packets, |
| 13782 | u32 rate, u32 intvl, gfp_t gfp) |
| 13783 | { |
| 13784 | struct sk_buff *msg; |
| 13785 | |
| 13786 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13787 | if (!msg) |
| 13788 | return; |
| 13789 | |
| 13790 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 13791 | goto nla_put_failure; |
| 13792 | |
| 13793 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 13794 | goto nla_put_failure; |
| 13795 | |
| 13796 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 13797 | goto nla_put_failure; |
| 13798 | |
| 13799 | cfg80211_send_cqm(msg, gfp); |
| 13800 | return; |
| 13801 | |
| 13802 | nla_put_failure: |
| 13803 | nlmsg_free(msg); |
| 13804 | } |
| 13805 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 13806 | |
| 13807 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 13808 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 13809 | { |
| 13810 | struct sk_buff *msg; |
| 13811 | |
| 13812 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 13813 | |
| 13814 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13815 | if (!msg) |
| 13816 | return; |
| 13817 | |
| 13818 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 13819 | goto nla_put_failure; |
| 13820 | |
| 13821 | cfg80211_send_cqm(msg, gfp); |
| 13822 | return; |
| 13823 | |
| 13824 | nla_put_failure: |
| 13825 | nlmsg_free(msg); |
| 13826 | } |
| 13827 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 13828 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13829 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 13830 | { |
| 13831 | struct sk_buff *msg; |
| 13832 | |
| 13833 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13834 | if (!msg) |
| 13835 | return; |
| 13836 | |
| 13837 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 13838 | goto nla_put_failure; |
| 13839 | |
| 13840 | cfg80211_send_cqm(msg, gfp); |
| 13841 | return; |
| 13842 | |
| 13843 | nla_put_failure: |
| 13844 | nlmsg_free(msg); |
| 13845 | } |
| 13846 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 13847 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13848 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 13849 | struct net_device *netdev, const u8 *bssid, |
| 13850 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13851 | { |
| 13852 | struct sk_buff *msg; |
| 13853 | struct nlattr *rekey_attr; |
| 13854 | void *hdr; |
| 13855 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13857 | if (!msg) |
| 13858 | return; |
| 13859 | |
| 13860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 13861 | if (!hdr) { |
| 13862 | nlmsg_free(msg); |
| 13863 | return; |
| 13864 | } |
| 13865 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13867 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13868 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13869 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13870 | |
| 13871 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 13872 | if (!rekey_attr) |
| 13873 | goto nla_put_failure; |
| 13874 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13875 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 13876 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 13877 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13878 | |
| 13879 | nla_nest_end(msg, rekey_attr); |
| 13880 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13881 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13882 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13883 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13884 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13885 | return; |
| 13886 | |
| 13887 | nla_put_failure: |
| 13888 | genlmsg_cancel(msg, hdr); |
| 13889 | nlmsg_free(msg); |
| 13890 | } |
| 13891 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13892 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 13893 | const u8 *replay_ctr, gfp_t gfp) |
| 13894 | { |
| 13895 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13896 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13897 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13898 | |
| 13899 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 13900 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 13901 | } |
| 13902 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 13903 | |
| 13904 | static void |
| 13905 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 13906 | struct net_device *netdev, int index, |
| 13907 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13908 | { |
| 13909 | struct sk_buff *msg; |
| 13910 | struct nlattr *attr; |
| 13911 | void *hdr; |
| 13912 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13913 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13914 | if (!msg) |
| 13915 | return; |
| 13916 | |
| 13917 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 13918 | if (!hdr) { |
| 13919 | nlmsg_free(msg); |
| 13920 | return; |
| 13921 | } |
| 13922 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13923 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13924 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13925 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13926 | |
| 13927 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 13928 | if (!attr) |
| 13929 | goto nla_put_failure; |
| 13930 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13931 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 13932 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 13933 | (preauth && |
| 13934 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 13935 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13936 | |
| 13937 | nla_nest_end(msg, attr); |
| 13938 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13939 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13940 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13941 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13942 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 13943 | return; |
| 13944 | |
| 13945 | nla_put_failure: |
| 13946 | genlmsg_cancel(msg, hdr); |
| 13947 | nlmsg_free(msg); |
| 13948 | } |
| 13949 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13950 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 13951 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 13952 | { |
| 13953 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13954 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13955 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13956 | |
| 13957 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 13958 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 13959 | } |
| 13960 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 13961 | |
| 13962 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 13963 | struct net_device *netdev, |
| 13964 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13965 | gfp_t gfp, |
| 13966 | enum nl80211_commands notif, |
| 13967 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13968 | { |
| 13969 | struct sk_buff *msg; |
| 13970 | void *hdr; |
| 13971 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13973 | if (!msg) |
| 13974 | return; |
| 13975 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13976 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13977 | if (!hdr) { |
| 13978 | nlmsg_free(msg); |
| 13979 | return; |
| 13980 | } |
| 13981 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 13982 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 13983 | goto nla_put_failure; |
| 13984 | |
| 13985 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 13986 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13987 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 13988 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 13989 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 13990 | goto nla_put_failure; |
| 13991 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13992 | genlmsg_end(msg, hdr); |
| 13993 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13994 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13995 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 13996 | return; |
| 13997 | |
| 13998 | nla_put_failure: |
| 13999 | genlmsg_cancel(msg, hdr); |
| 14000 | nlmsg_free(msg); |
| 14001 | } |
| 14002 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14003 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14004 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14005 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14006 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14007 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14008 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14009 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14010 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14011 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14012 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14013 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14014 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14015 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14016 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14017 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14018 | } |
| 14019 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14020 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14021 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14022 | struct cfg80211_chan_def *chandef, |
| 14023 | u8 count) |
| 14024 | { |
| 14025 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14026 | struct wiphy *wiphy = wdev->wiphy; |
| 14027 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14028 | |
| 14029 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14030 | |
| 14031 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14032 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14033 | } |
| 14034 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14035 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14036 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14037 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14038 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14039 | enum nl80211_radar_event event, |
| 14040 | struct net_device *netdev, gfp_t gfp) |
| 14041 | { |
| 14042 | struct sk_buff *msg; |
| 14043 | void *hdr; |
| 14044 | |
| 14045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14046 | if (!msg) |
| 14047 | return; |
| 14048 | |
| 14049 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14050 | if (!hdr) { |
| 14051 | nlmsg_free(msg); |
| 14052 | return; |
| 14053 | } |
| 14054 | |
| 14055 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14056 | goto nla_put_failure; |
| 14057 | |
| 14058 | /* NOP and radar events don't need a netdev parameter */ |
| 14059 | if (netdev) { |
| 14060 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14061 | |
| 14062 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14063 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14064 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14065 | goto nla_put_failure; |
| 14066 | } |
| 14067 | |
| 14068 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14069 | goto nla_put_failure; |
| 14070 | |
| 14071 | if (nl80211_send_chandef(msg, chandef)) |
| 14072 | goto nla_put_failure; |
| 14073 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14074 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14075 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14076 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14077 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14078 | return; |
| 14079 | |
| 14080 | nla_put_failure: |
| 14081 | genlmsg_cancel(msg, hdr); |
| 14082 | nlmsg_free(msg); |
| 14083 | } |
| 14084 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14085 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14086 | u64 cookie, bool acked, gfp_t gfp) |
| 14087 | { |
| 14088 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14089 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14090 | struct sk_buff *msg; |
| 14091 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14092 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14093 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14094 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14095 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14096 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14097 | if (!msg) |
| 14098 | return; |
| 14099 | |
| 14100 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14101 | if (!hdr) { |
| 14102 | nlmsg_free(msg); |
| 14103 | return; |
| 14104 | } |
| 14105 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14106 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14107 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14108 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14109 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14110 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14111 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14112 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14113 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14114 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14115 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14116 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14117 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14118 | return; |
| 14119 | |
| 14120 | nla_put_failure: |
| 14121 | genlmsg_cancel(msg, hdr); |
| 14122 | nlmsg_free(msg); |
| 14123 | } |
| 14124 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14125 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14126 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14127 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14128 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14129 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14130 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14131 | struct sk_buff *msg; |
| 14132 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14133 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14134 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14135 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14136 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14137 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14138 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14139 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14140 | if (!msg) { |
| 14141 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14142 | return; |
| 14143 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14144 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14145 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14146 | if (!hdr) |
| 14147 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14148 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14149 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14150 | (freq && |
| 14151 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14152 | (sig_dbm && |
| 14153 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14154 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14155 | goto nla_put_failure; |
| 14156 | |
| 14157 | genlmsg_end(msg, hdr); |
| 14158 | |
| 14159 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14160 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14161 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14162 | return; |
| 14163 | |
| 14164 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14165 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14166 | if (hdr) |
| 14167 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14168 | nlmsg_free(msg); |
| 14169 | } |
| 14170 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14171 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14172 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14173 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14174 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14175 | { |
| 14176 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14177 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14178 | int i, j; |
| 14179 | |
| 14180 | nl_results = nla_nest_start( |
| 14181 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14182 | if (!nl_results) |
| 14183 | return -EMSGSIZE; |
| 14184 | |
| 14185 | for (i = 0; i < nd->n_matches; i++) { |
| 14186 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14187 | |
| 14188 | nl_match = nla_nest_start(msg, i); |
| 14189 | if (!nl_match) |
| 14190 | break; |
| 14191 | |
| 14192 | /* The SSID attribute is optional in nl80211, but for |
| 14193 | * simplicity reasons it's always present in the |
| 14194 | * cfg80211 structure. If a driver can't pass the |
| 14195 | * SSID, that needs to be changed. A zero length SSID |
| 14196 | * is still a valid SSID (wildcard), so it cannot be |
| 14197 | * used for this purpose. |
| 14198 | */ |
| 14199 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14200 | match->ssid.ssid)) { |
| 14201 | nla_nest_cancel(msg, nl_match); |
| 14202 | goto out; |
| 14203 | } |
| 14204 | |
| 14205 | if (match->n_channels) { |
| 14206 | nl_freqs = nla_nest_start( |
| 14207 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14208 | if (!nl_freqs) { |
| 14209 | nla_nest_cancel(msg, nl_match); |
| 14210 | goto out; |
| 14211 | } |
| 14212 | |
| 14213 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14214 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14215 | nla_nest_cancel(msg, nl_freqs); |
| 14216 | nla_nest_cancel(msg, nl_match); |
| 14217 | goto out; |
| 14218 | } |
| 14219 | } |
| 14220 | |
| 14221 | nla_nest_end(msg, nl_freqs); |
| 14222 | } |
| 14223 | |
| 14224 | nla_nest_end(msg, nl_match); |
| 14225 | } |
| 14226 | |
| 14227 | out: |
| 14228 | nla_nest_end(msg, nl_results); |
| 14229 | return 0; |
| 14230 | } |
| 14231 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14232 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14233 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14234 | gfp_t gfp) |
| 14235 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14236 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14237 | struct sk_buff *msg; |
| 14238 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14239 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14240 | |
| 14241 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14242 | |
| 14243 | if (wakeup) |
| 14244 | size += wakeup->packet_present_len; |
| 14245 | |
| 14246 | msg = nlmsg_new(size, gfp); |
| 14247 | if (!msg) |
| 14248 | return; |
| 14249 | |
| 14250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14251 | if (!hdr) |
| 14252 | goto free_msg; |
| 14253 | |
| 14254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14255 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14256 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14257 | goto free_msg; |
| 14258 | |
| 14259 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14260 | wdev->netdev->ifindex)) |
| 14261 | goto free_msg; |
| 14262 | |
| 14263 | if (wakeup) { |
| 14264 | struct nlattr *reasons; |
| 14265 | |
| 14266 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14267 | if (!reasons) |
| 14268 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14269 | |
| 14270 | if (wakeup->disconnect && |
| 14271 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14272 | goto free_msg; |
| 14273 | if (wakeup->magic_pkt && |
| 14274 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14275 | goto free_msg; |
| 14276 | if (wakeup->gtk_rekey_failure && |
| 14277 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 14278 | goto free_msg; |
| 14279 | if (wakeup->eap_identity_req && |
| 14280 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 14281 | goto free_msg; |
| 14282 | if (wakeup->four_way_handshake && |
| 14283 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 14284 | goto free_msg; |
| 14285 | if (wakeup->rfkill_release && |
| 14286 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 14287 | goto free_msg; |
| 14288 | |
| 14289 | if (wakeup->pattern_idx >= 0 && |
| 14290 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 14291 | wakeup->pattern_idx)) |
| 14292 | goto free_msg; |
| 14293 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14294 | if (wakeup->tcp_match && |
| 14295 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 14296 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14297 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14298 | if (wakeup->tcp_connlost && |
| 14299 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 14300 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14301 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14302 | if (wakeup->tcp_nomoretokens && |
| 14303 | nla_put_flag(msg, |
| 14304 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 14305 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14306 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14307 | if (wakeup->packet) { |
| 14308 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 14309 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 14310 | |
| 14311 | if (!wakeup->packet_80211) { |
| 14312 | pkt_attr = |
| 14313 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 14314 | len_attr = |
| 14315 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 14316 | } |
| 14317 | |
| 14318 | if (wakeup->packet_len && |
| 14319 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 14320 | goto free_msg; |
| 14321 | |
| 14322 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 14323 | wakeup->packet)) |
| 14324 | goto free_msg; |
| 14325 | } |
| 14326 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14327 | if (wakeup->net_detect && |
| 14328 | cfg80211_net_detect_results(msg, wakeup)) |
| 14329 | goto free_msg; |
| 14330 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14331 | nla_nest_end(msg, reasons); |
| 14332 | } |
| 14333 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14334 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14335 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14336 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14337 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14338 | return; |
| 14339 | |
| 14340 | free_msg: |
| 14341 | nlmsg_free(msg); |
| 14342 | } |
| 14343 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 14344 | #endif |
| 14345 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14346 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 14347 | enum nl80211_tdls_operation oper, |
| 14348 | u16 reason_code, gfp_t gfp) |
| 14349 | { |
| 14350 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14351 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14352 | struct sk_buff *msg; |
| 14353 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14354 | |
| 14355 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 14356 | reason_code); |
| 14357 | |
| 14358 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14359 | if (!msg) |
| 14360 | return; |
| 14361 | |
| 14362 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 14363 | if (!hdr) { |
| 14364 | nlmsg_free(msg); |
| 14365 | return; |
| 14366 | } |
| 14367 | |
| 14368 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14369 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14370 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 14371 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 14372 | (reason_code > 0 && |
| 14373 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 14374 | goto nla_put_failure; |
| 14375 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14376 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14377 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14378 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14379 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14380 | return; |
| 14381 | |
| 14382 | nla_put_failure: |
| 14383 | genlmsg_cancel(msg, hdr); |
| 14384 | nlmsg_free(msg); |
| 14385 | } |
| 14386 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 14387 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14388 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 14389 | unsigned long state, |
| 14390 | void *_notify) |
| 14391 | { |
| 14392 | struct netlink_notify *notify = _notify; |
| 14393 | struct cfg80211_registered_device *rdev; |
| 14394 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14395 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14396 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 14397 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14398 | return NOTIFY_DONE; |
| 14399 | |
| 14400 | rcu_read_lock(); |
| 14401 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14402 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14403 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 14404 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 14405 | rcu_dereference(rdev->sched_scan_req); |
| 14406 | |
| 14407 | if (sched_scan_req && notify->portid && |
Johannes Berg | 0a28f53 | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 14408 | sched_scan_req->owner_nlportid == notify->portid) { |
| 14409 | sched_scan_req->owner_nlportid = 0; |
| 14410 | |
| 14411 | if (rdev->ops->sched_scan_stop && |
| 14412 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 14413 | schedule_work(&rdev->sched_scan_stop_wk); |
| 14414 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14415 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 14416 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14417 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14418 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14419 | if (wdev->owner_nlportid == notify->portid) |
| 14420 | schedule_destroy_work = true; |
| 14421 | } |
| 14422 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14423 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14424 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 14425 | list) { |
| 14426 | if (reg->nlportid == notify->portid) { |
| 14427 | list_del(®->list); |
| 14428 | kfree(reg); |
| 14429 | break; |
| 14430 | } |
| 14431 | } |
| 14432 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14433 | |
| 14434 | if (schedule_destroy_work) { |
| 14435 | struct cfg80211_iface_destroy *destroy; |
| 14436 | |
| 14437 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 14438 | if (destroy) { |
| 14439 | destroy->nlportid = notify->portid; |
| 14440 | spin_lock(&rdev->destroy_list_lock); |
| 14441 | list_add(&destroy->list, &rdev->destroy_list); |
| 14442 | spin_unlock(&rdev->destroy_list_lock); |
| 14443 | schedule_work(&rdev->destroy_work); |
| 14444 | } |
| 14445 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14446 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14447 | |
| 14448 | rcu_read_unlock(); |
| 14449 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 14450 | /* |
| 14451 | * It is possible that the user space process that is controlling the |
| 14452 | * indoor setting disappeared, so notify the regulatory core. |
| 14453 | */ |
| 14454 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 14455 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14456 | } |
| 14457 | |
| 14458 | static struct notifier_block nl80211_netlink_notifier = { |
| 14459 | .notifier_call = nl80211_netlink_notify, |
| 14460 | }; |
| 14461 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14462 | void cfg80211_ft_event(struct net_device *netdev, |
| 14463 | struct cfg80211_ft_event_params *ft_event) |
| 14464 | { |
| 14465 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14467 | struct sk_buff *msg; |
| 14468 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14469 | |
| 14470 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 14471 | |
| 14472 | if (!ft_event->target_ap) |
| 14473 | return; |
| 14474 | |
| 14475 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14476 | if (!msg) |
| 14477 | return; |
| 14478 | |
| 14479 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14480 | if (!hdr) |
| 14481 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14482 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14483 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14484 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14485 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 14486 | goto out; |
| 14487 | |
| 14488 | if (ft_event->ies && |
| 14489 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 14490 | goto out; |
| 14491 | if (ft_event->ric_ies && |
| 14492 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 14493 | ft_event->ric_ies)) |
| 14494 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14495 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14496 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14497 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14498 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14499 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14500 | return; |
| 14501 | out: |
| 14502 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14503 | } |
| 14504 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 14505 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14506 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 14507 | { |
| 14508 | struct cfg80211_registered_device *rdev; |
| 14509 | struct sk_buff *msg; |
| 14510 | void *hdr; |
| 14511 | u32 nlportid; |
| 14512 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14513 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14514 | if (!rdev->crit_proto_nlportid) |
| 14515 | return; |
| 14516 | |
| 14517 | nlportid = rdev->crit_proto_nlportid; |
| 14518 | rdev->crit_proto_nlportid = 0; |
| 14519 | |
| 14520 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14521 | if (!msg) |
| 14522 | return; |
| 14523 | |
| 14524 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 14525 | if (!hdr) |
| 14526 | goto nla_put_failure; |
| 14527 | |
| 14528 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14529 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14530 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14531 | goto nla_put_failure; |
| 14532 | |
| 14533 | genlmsg_end(msg, hdr); |
| 14534 | |
| 14535 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 14536 | return; |
| 14537 | |
| 14538 | nla_put_failure: |
| 14539 | if (hdr) |
| 14540 | genlmsg_cancel(msg, hdr); |
| 14541 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14542 | } |
| 14543 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 14544 | |
Sameer Thalappil | faa4c4a | 2013-07-05 14:58:32 -0700 | [diff] [blame] | 14545 | void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp) |
| 14546 | { |
| 14547 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14548 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14549 | |
| 14550 | nl80211_send_mlme_event(rdev, netdev, NULL, 0, |
| 14551 | NL80211_CMD_STOP_AP, gfp, -1); |
| 14552 | } |
| 14553 | EXPORT_SYMBOL(cfg80211_ap_stopped); |
| 14554 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14555 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 14556 | { |
| 14557 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14558 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14559 | struct sk_buff *msg; |
| 14560 | void *hdr; |
| 14561 | |
| 14562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14563 | if (!msg) |
| 14564 | return; |
| 14565 | |
| 14566 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 14567 | if (!hdr) |
| 14568 | goto out; |
| 14569 | |
| 14570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14571 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14572 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14573 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14574 | goto out; |
| 14575 | |
| 14576 | genlmsg_end(msg, hdr); |
| 14577 | |
| 14578 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 14579 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 14580 | return; |
| 14581 | out: |
| 14582 | nlmsg_free(msg); |
| 14583 | } |
| 14584 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14585 | /* initialisation/exit functions */ |
| 14586 | |
| 14587 | int nl80211_init(void) |
| 14588 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 14589 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14590 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14591 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 14592 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14593 | if (err) |
| 14594 | return err; |
| 14595 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14596 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 14597 | if (err) |
| 14598 | goto err_out; |
| 14599 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14600 | return 0; |
| 14601 | err_out: |
| 14602 | genl_unregister_family(&nl80211_fam); |
| 14603 | return err; |
| 14604 | } |
| 14605 | |
| 14606 | void nl80211_exit(void) |
| 14607 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14608 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14609 | genl_unregister_family(&nl80211_fam); |
| 14610 | } |